PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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