PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/basics.test.php

https://github.com/Forbin/cakephp2x
PHP | 775 lines | 479 code | 121 blank | 175 comment | 3 complexity | d912e57d0257fdcae9768f05279ee4dc MD5 | raw file
  1. <?php
  2. /**
  3. * BasicsTest file
  4. *
  5. * PHP Version 5.x
  6. *
  7. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  8. * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  15. * @package cake
  16. * @subpackage cake.tests.cases
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. require_once CAKE . 'basics.php';
  21. App::import('Core', 'Folder');
  22. /**
  23. * BasicsTest class
  24. *
  25. * @package cake
  26. * @subpackage cake.tests.cases
  27. */
  28. class BasicsTest extends CakeTestCase {
  29. /**
  30. * setUp method
  31. *
  32. * @return void
  33. * @access public
  34. */
  35. function setUp() {
  36. App::build(array(
  37. 'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS)
  38. ));
  39. $this->_language = Configure::read('Config.language');
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @return void
  45. * @access public
  46. */
  47. function tearDown() {
  48. App::build();
  49. Configure::write('Config.language', $this->_language);
  50. }
  51. /**
  52. * test the array_diff_key compatibility function.
  53. *
  54. * @return void
  55. * @access public
  56. */
  57. function testArrayDiffKey() {
  58. $one = array('one' => 1, 'two' => 2, 'three' => 3);
  59. $two = array('one' => 'one', 'two' => 'two');
  60. $result = array_diff_key($one, $two);
  61. $expected = array('three' => 3);
  62. $this->assertEqual($result, $expected);
  63. $one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3);
  64. $two = array('two' => 'two');
  65. $result = array_diff_key($one, $two);
  66. $expected = array('one' => array('value', 'value-two'), 'three' => 3);
  67. $this->assertEqual($result, $expected);
  68. $one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0);
  69. $two = array('two' => 'two');
  70. $result = array_diff_key($one, $two);
  71. $expected = array('one' => null, 'three' => '', 'four' => 0);
  72. $this->assertEqual($result, $expected);
  73. $one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
  74. $two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
  75. $result = array_diff_key($one, $two);
  76. $this->assertEqual($result, array());
  77. }
  78. /**
  79. * testHttpBase method
  80. *
  81. * @return void
  82. * @access public
  83. */
  84. function testEnv() {
  85. $this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
  86. $__SERVER = $_SERVER;
  87. $__ENV = $_ENV;
  88. $_SERVER['HTTP_HOST'] = 'localhost';
  89. $this->assertEqual(env('HTTP_BASE'), '');
  90. $_SERVER['HTTP_HOST'] = 'example.com';
  91. $this->assertEqual(env('HTTP_BASE'), '.example.com');
  92. $_SERVER['HTTP_HOST'] = 'www.example.com';
  93. $this->assertEqual(env('HTTP_BASE'), '.example.com');
  94. $_SERVER['HTTP_HOST'] = 'subdomain.example.com';
  95. $this->assertEqual(env('HTTP_BASE'), '.example.com');
  96. $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
  97. $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
  98. $_SERVER = $_ENV = array();
  99. $_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
  100. $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
  101. $_SERVER = $_ENV = array();
  102. $_ENV['CGI_MODE'] = 'BINARY';
  103. $_ENV['SCRIPT_URL'] = '/a/test/test.php';
  104. $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
  105. $_SERVER = $_ENV = array();
  106. $this->assertFalse(env('HTTPS'));
  107. $_SERVER['HTTPS'] = 'on';
  108. $this->assertTrue(env('HTTPS'));
  109. $_SERVER['HTTPS'] = '1';
  110. $this->assertTrue(env('HTTPS'));
  111. $_SERVER['HTTPS'] = 'I am not empty';
  112. $this->assertTrue(env('HTTPS'));
  113. $_SERVER['HTTPS'] = 1;
  114. $this->assertTrue(env('HTTPS'));
  115. $_SERVER['HTTPS'] = 'off';
  116. $this->assertFalse(env('HTTPS'));
  117. $_SERVER['HTTPS'] = false;
  118. $this->assertFalse(env('HTTPS'));
  119. $_SERVER['HTTPS'] = '';
  120. $this->assertFalse(env('HTTPS'));
  121. $_SERVER = array();
  122. $_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';
  123. $this->assertTrue(env('HTTPS'));
  124. $_ENV['SCRIPT_URI'] = 'http://domain.test/a/test.php';
  125. $this->assertFalse(env('HTTPS'));
  126. $_SERVER = $_ENV = array();
  127. $this->assertFalse(env('TEST_ME'));
  128. $_ENV['TEST_ME'] = 'a';
  129. $this->assertEqual(env('TEST_ME'), 'a');
  130. $_SERVER['TEST_ME'] = 'b';
  131. $this->assertEqual(env('TEST_ME'), 'b');
  132. unset($_ENV['TEST_ME']);
  133. $this->assertEqual(env('TEST_ME'), 'b');
  134. $_SERVER = $__SERVER;
  135. $_ENV = $__ENV;
  136. }
  137. /**
  138. * Test h()
  139. *
  140. * @return void
  141. * @access public
  142. */
  143. function testH() {
  144. $string = '<foo>';
  145. $result = h($string);
  146. $this->assertEqual('&lt;foo&gt;', $result);
  147. $in = array('this & that', '<p>Which one</p>');
  148. $result = h($in);
  149. $expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;');
  150. $this->assertEqual($expected, $result);
  151. }
  152. /**
  153. * Test a()
  154. *
  155. * @return void
  156. * @access public
  157. */
  158. function testA() {
  159. $result = a('this', 'that', 'bar');
  160. $this->assertEqual(array('this', 'that', 'bar'), $result);
  161. }
  162. /**
  163. * Test aa()
  164. *
  165. * @return void
  166. * @access public
  167. */
  168. function testAa() {
  169. $result = aa('a', 'b', 'c', 'd');
  170. $expected = array('a' => 'b', 'c' => 'd');
  171. $this->assertEqual($expected, $result);
  172. $result = aa('a', 'b', 'c', 'd', 'e');
  173. $expected = array('a' => 'b', 'c' => 'd', 'e' => null);
  174. $this->assertEqual($result, $expected);
  175. }
  176. /**
  177. * Test am()
  178. *
  179. * @return void
  180. * @access public
  181. */
  182. function testAm() {
  183. $result = am(array('one', 'two'), 2, 3, 4);
  184. $expected = array('one', 'two', 2, 3, 4);
  185. $this->assertEqual($result, $expected);
  186. $result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
  187. $expected = array('one' => array(4, 5),'two' => array('foo'));
  188. $this->assertEqual($result, $expected);
  189. }
  190. /**
  191. * test cache()
  192. *
  193. * @return void
  194. * @access public
  195. */
  196. function testCache() {
  197. $_cacheDisable = Configure::read('Cache.disable');
  198. if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
  199. return;
  200. }
  201. Configure::write('Cache.disable', true);
  202. $result = cache('basics_test', 'simple cache write');
  203. $this->assertNull($result);
  204. $result = cache('basics_test');
  205. $this->assertNull($result);
  206. Configure::write('Cache.disable', false);
  207. $result = cache('basics_test', 'simple cache write');
  208. $this->assertTrue($result);
  209. $this->assertTrue(file_exists(CACHE . 'basics_test'));
  210. $result = cache('basics_test');
  211. $this->assertEqual($result, 'simple cache write');
  212. @unlink(CACHE . 'basics_test');
  213. cache('basics_test', 'expired', '+1 second');
  214. sleep(2);
  215. $result = cache('basics_test', null, '+1 second');
  216. $this->assertNull($result);
  217. Configure::write('Cache.disable', $_cacheDisable);
  218. }
  219. /**
  220. * test clearCache()
  221. *
  222. * @return void
  223. * @access public
  224. */
  225. function testClearCache() {
  226. $cacheOff = Configure::read('Cache.disable');
  227. if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
  228. return;
  229. }
  230. cache('views' . DS . 'basics_test.cache', 'simple cache write');
  231. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  232. cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
  233. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
  234. cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
  235. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  236. $result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
  237. $this->assertTrue($result);
  238. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  239. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  240. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  241. $result = clearCache(null, 'views', '.cache');
  242. $this->assertTrue($result);
  243. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  244. // Different path from views and with prefix
  245. cache('models' . DS . 'basics_test.cache', 'simple cache write');
  246. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
  247. cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
  248. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
  249. cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
  250. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
  251. $result = clearCache('basics', 'models', '.cache');
  252. $this->assertTrue($result);
  253. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
  254. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
  255. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
  256. }
  257. /**
  258. * test __()
  259. *
  260. * @return void
  261. * @access public
  262. */
  263. function test__() {
  264. Configure::write('Config.language', 'rule_1_po');
  265. $result = __('Plural Rule 1');
  266. $expected = 'Plural Rule 1 (translated)';
  267. $this->assertEqual($result, $expected);
  268. $result = __('Plural Rule 1 (from core)');
  269. $expected = 'Plural Rule 1 (from core translated)';
  270. $this->assertEqual($result, $expected);
  271. ob_start();
  272. __('Plural Rule 1 (from core)', false);
  273. $result = ob_get_clean();
  274. $expected = 'Plural Rule 1 (from core translated)';
  275. $this->assertEqual($result, $expected);
  276. }
  277. /**
  278. * test __n()
  279. *
  280. * @return void
  281. * @access public
  282. */
  283. function test__n() {
  284. Configure::write('Config.language', 'rule_1_po');
  285. $result = __n('%d = 1', '%d = 0 or > 1', 0);
  286. $expected = '%d = 0 or > 1 (translated)';
  287. $this->assertEqual($result, $expected);
  288. $result = __n('%d = 1', '%d = 0 or > 1', 1);
  289. $expected = '%d = 1 (translated)';
  290. $this->assertEqual($result, $expected);
  291. $result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
  292. $expected = '%d = 0 or > 1 (from core translated)';
  293. $this->assertEqual($result, $expected);
  294. ob_start();
  295. __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2, false);
  296. $result = ob_get_clean();
  297. $expected = '%d = 0 or > 1 (from core translated)';
  298. $this->assertEqual($result, $expected);
  299. }
  300. /**
  301. * test __d()
  302. *
  303. * @return void
  304. * @access public
  305. */
  306. function test__d() {
  307. Configure::write('Config.language', 'rule_1_po');
  308. $result = __d('default', 'Plural Rule 1');
  309. $expected = 'Plural Rule 1 (translated)';
  310. $this->assertEqual($result, $expected);
  311. $result = __d('core', 'Plural Rule 1');
  312. $expected = 'Plural Rule 1';
  313. $this->assertEqual($result, $expected);
  314. $result = __d('core', 'Plural Rule 1 (from core)');
  315. $expected = 'Plural Rule 1 (from core translated)';
  316. $this->assertEqual($result, $expected);
  317. ob_start();
  318. __d('core', 'Plural Rule 1 (from core)', false);
  319. $result = ob_get_clean();
  320. $expected = 'Plural Rule 1 (from core translated)';
  321. $this->assertEqual($result, $expected);
  322. }
  323. /**
  324. * test __dn()
  325. *
  326. * @return void
  327. * @access public
  328. */
  329. function test__dn() {
  330. Configure::write('Config.language', 'rule_1_po');
  331. $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0);
  332. $expected = '%d = 0 or > 1 (translated)';
  333. $this->assertEqual($result, $expected);
  334. $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0);
  335. $expected = '%d = 0 or > 1';
  336. $this->assertEqual($result, $expected);
  337. $result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0);
  338. $expected = '%d = 0 or > 1 (from core translated)';
  339. $this->assertEqual($result, $expected);
  340. $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1);
  341. $expected = '%d = 1 (translated)';
  342. $this->assertEqual($result, $expected);
  343. ob_start();
  344. __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2, false);
  345. $result = ob_get_clean();
  346. $expected = '%d = 0 or > 1 (from core translated)';
  347. $this->assertEqual($result, $expected);
  348. }
  349. /**
  350. * test __c()
  351. *
  352. * @return void
  353. * @access public
  354. */
  355. function test__c() {
  356. Configure::write('Config.language', 'rule_1_po');
  357. $result = __c('Plural Rule 1', 6);
  358. $expected = 'Plural Rule 1 (translated)';
  359. $this->assertEqual($result, $expected);
  360. $result = __c('Plural Rule 1 (from core)', 6);
  361. $expected = 'Plural Rule 1 (from core translated)';
  362. $this->assertEqual($result, $expected);
  363. ob_start();
  364. __c('Plural Rule 1 (from core)', 6, false);
  365. $result = ob_get_clean();
  366. $expected = 'Plural Rule 1 (from core translated)';
  367. $this->assertEqual($result, $expected);
  368. }
  369. /**
  370. * test __dc()
  371. *
  372. * @return void
  373. * @access public
  374. */
  375. function test__dc() {
  376. Configure::write('Config.language', 'rule_1_po');
  377. $result = __dc('default', 'Plural Rule 1', 6);
  378. $expected = 'Plural Rule 1 (translated)';
  379. $this->assertEqual($result, $expected);
  380. $result = __dc('default', 'Plural Rule 1 (from core)', 6);
  381. $expected = 'Plural Rule 1 (from core translated)';
  382. $this->assertEqual($result, $expected);
  383. $result = __dc('core', 'Plural Rule 1', 6);
  384. $expected = 'Plural Rule 1';
  385. $this->assertEqual($result, $expected);
  386. $result = __dc('core', 'Plural Rule 1 (from core)', 6);
  387. $expected = 'Plural Rule 1 (from core translated)';
  388. $this->assertEqual($result, $expected);
  389. ob_start();
  390. __dc('default', 'Plural Rule 1 (from core)', 6, false);
  391. $result = ob_get_clean();
  392. $expected = 'Plural Rule 1 (from core translated)';
  393. $this->assertEqual($result, $expected);
  394. }
  395. /**
  396. * test __dcn()
  397. *
  398. * @return void
  399. * @access public
  400. */
  401. function test__dcn() {
  402. Configure::write('Config.language', 'rule_1_po');
  403. $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6);
  404. $expected = '%d = 0 or > 1 (translated)';
  405. $this->assertEqual($result, $expected);
  406. $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
  407. $expected = '%d = 1 (from core translated)';
  408. $this->assertEqual($result, $expected);
  409. $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6);
  410. $expected = '%d = 0 or > 1';
  411. $this->assertEqual($result, $expected);
  412. ob_start();
  413. __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6, false);
  414. $result = ob_get_clean();
  415. $expected = '%d = 1 (from core translated)';
  416. $this->assertEqual($result, $expected);
  417. }
  418. /**
  419. * test LogError()
  420. *
  421. * @return void
  422. * @access public
  423. */
  424. function testLogError() {
  425. @unlink(LOGS . 'error.log');
  426. LogError('Testing LogError() basic function');
  427. LogError("Testing with\nmulti-line\nstring");
  428. $result = file_get_contents(LOGS . 'error.log');
  429. $this->assertPattern('/Error: Testing LogError\(\) basic function/', $result);
  430. $this->assertNoPattern("/Error: Testing with\nmulti-line\nstring/", $result);
  431. $this->assertPattern('/Error: Testing with multi-line string/', $result);
  432. }
  433. /**
  434. * test fileExistsInPath()
  435. *
  436. * @return void
  437. * @access public
  438. */
  439. function testFileExistsInPath() {
  440. $this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
  441. $_includePath = ini_get('include_path');
  442. $path = TMP . 'basics_test';
  443. $folder1 = $path . DS . 'folder1';
  444. $folder2 = $path . DS . 'folder2';
  445. $file1 = $path . DS . 'file1.php';
  446. $file2 = $folder1 . DS . 'file2.php';
  447. $file3 = $folder1 . DS . 'file3.php';
  448. $file4 = $folder2 . DS . 'file4.php';
  449. new Folder($path, true);
  450. new Folder($folder1, true);
  451. new Folder($folder2, true);
  452. touch($file1);
  453. touch($file2);
  454. touch($file3);
  455. touch($file4);
  456. ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
  457. $this->assertEqual(fileExistsInPath('file1.php'), $file1);
  458. $this->assertEqual(fileExistsInPath('file2.php'), $file2);
  459. $this->assertEqual(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
  460. $this->assertEqual(fileExistsInPath($file2), $file2);
  461. $this->assertEqual(fileExistsInPath('file3.php'), $file3);
  462. $this->assertEqual(fileExistsInPath($file4), $file4);
  463. $this->assertFalse(fileExistsInPath('file1'));
  464. $this->assertFalse(fileExistsInPath('file4.php'));
  465. $Folder = new Folder($path);
  466. $Folder->delete();
  467. ini_set('include_path', $_includePath);
  468. }
  469. /**
  470. * test convertSlash()
  471. *
  472. * @return void
  473. * @access public
  474. */
  475. function testConvertSlash() {
  476. $result = convertSlash('\path\to\location\\');
  477. $expected = '\path\to\location\\';
  478. $this->assertEqual($result, $expected);
  479. $result = convertSlash('/path/to/location/');
  480. $expected = 'path_to_location';
  481. $this->assertEqual($result, $expected);
  482. }
  483. /**
  484. * test debug()
  485. *
  486. * @return void
  487. * @access public
  488. */
  489. function testDebug() {
  490. ob_start();
  491. debug('this-is-a-test');
  492. $result = ob_get_clean();
  493. $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
  494. $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
  495. $pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
  496. $this->assertPattern($pattern, $result);
  497. ob_start();
  498. debug('<div>this-is-a-test</div>', true);
  499. $result = ob_get_clean();
  500. $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
  501. $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
  502. $pattern .= '.*line.*' . (__LINE__ - 4) . '.*&lt;div&gt;this-is-a-test&lt;\/div&gt;.*/s';
  503. $this->assertPattern($pattern, $result);
  504. }
  505. /**
  506. * test pr()
  507. *
  508. * @return void
  509. * @access public
  510. */
  511. function testPr() {
  512. ob_start();
  513. pr('this is a test');
  514. $result = ob_get_clean();
  515. $expected = "<pre>this is a test</pre>";
  516. $this->assertEqual($result, $expected);
  517. ob_start();
  518. pr(array('this' => 'is', 'a' => 'test'));
  519. $result = ob_get_clean();
  520. $expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
  521. $this->assertEqual($result, $expected);
  522. }
  523. /**
  524. * test params()
  525. *
  526. * @return void
  527. * @access public
  528. */
  529. function testParams() {
  530. $this->assertNull(params('weekend'));
  531. $this->assertNull(params(array()));
  532. $this->assertEqual(params(array('weekend')), array('weekend'));
  533. $nested = array(array('weekend'));
  534. $this->assertEqual(params($nested), array('weekend'));
  535. $multiple = array(array('weekend'), 'jean-luc', 'godard');
  536. $this->assertEqual(params($multiple), $multiple);
  537. }
  538. /**
  539. * test stripslashes_deep()
  540. *
  541. * @return void
  542. * @access public
  543. */
  544. function testStripslashesDeep() {
  545. $this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
  546. $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
  547. $this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
  548. $this->assertEqual(stripslashes_deep('tes\"t'), 'tes"t');
  549. $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
  550. $this->assertEqual(stripslashes_deep('te\\st'), 'test');
  551. $nested = array(
  552. 'a' => "tes\'t",
  553. 'b' => 'tes\\' . chr(0) .'t',
  554. 'c' => array(
  555. 'd' => 'tes\"t',
  556. 'e' => "te\'s\'t",
  557. array('f' => "tes\'t")
  558. ),
  559. 'g' => 'te\\st'
  560. );
  561. $expected = array(
  562. 'a' => "tes't",
  563. 'b' => 'tes' . chr(0) .'t',
  564. 'c' => array(
  565. 'd' => 'tes"t',
  566. 'e' => "te's't",
  567. array('f' => "tes't")
  568. ),
  569. 'g' => 'test'
  570. );
  571. $this->assertEqual(stripslashes_deep($nested), $expected);
  572. }
  573. /**
  574. * test stripslashes_deep() with magic_quotes_sybase on
  575. *
  576. * @return void
  577. * @access public
  578. */
  579. function testStripslashesDeepSybase() {
  580. $this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
  581. $this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
  582. $nested = array(
  583. 'a' => "tes't",
  584. 'b' => "tes''t",
  585. 'c' => array(
  586. 'd' => "tes'''t",
  587. 'e' => "tes''''t",
  588. array('f' => "tes''t")
  589. ),
  590. 'g' => "te'''''st"
  591. );
  592. $expected = array(
  593. 'a' => "tes't",
  594. 'b' => "tes't",
  595. 'c' => array(
  596. 'd' => "tes''t",
  597. 'e' => "tes''t",
  598. array('f' => "tes't")
  599. ),
  600. 'g' => "te'''st"
  601. );
  602. $this->assertEqual(stripslashes_deep($nested), $expected);
  603. }
  604. /**
  605. * test ife()
  606. *
  607. * @return void
  608. * @access public
  609. */
  610. function testIfe() {
  611. $this->assertEqual(ife(true, 'a', 'b'), 'a');
  612. $this->assertEqual(ife(' ', 'a', 'b'), 'a');
  613. $this->assertEqual(ife('test', 'a', 'b'), 'a');
  614. $this->assertEqual(ife(23, 'a', 'b'), 'a');
  615. $this->assertEqual(ife(array('t' => 'est'), 'a', 'b'), 'a');
  616. $this->assertEqual(ife(false, 'a', 'b'), 'b');
  617. $this->assertEqual(ife(null, 'a', 'b'), 'b');
  618. $this->assertEqual(ife('', 'a', 'b'), 'b');
  619. $this->assertEqual(ife(0, 'a', 'b'), 'b');
  620. $this->assertEqual(ife(array(), 'a', 'b'), 'b');
  621. }
  622. /**
  623. * test pluginSplit
  624. *
  625. * @return void
  626. */
  627. function testPluginSplit() {
  628. $result = pluginSplit('Something.else');
  629. $this->assertEqual($result, array('Something', 'else'));
  630. $result = pluginSplit('Something.else.more.dots');
  631. $this->assertEqual($result, array('Something', 'else.more.dots'));
  632. $result = pluginSplit('Somethingelse');
  633. $this->assertEqual($result, array(null, 'Somethingelse'));
  634. $result = pluginSplit('Something.else', true);
  635. $this->assertEqual($result, array('Something.', 'else'));
  636. $result = pluginSplit('Something.else.more.dots', true);
  637. $this->assertEqual($result, array('Something.', 'else.more.dots'));
  638. $result = pluginSplit('Post', false, 'Blog');
  639. $this->assertEqual($result, array('Blog', 'Post'));
  640. $result = pluginSplit('Blog.Post', false, 'Ultimate');
  641. $this->assertEqual($result, array('Blog', 'Post'));
  642. }
  643. }
  644. ?>