PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/cakephp/cakephp1x
PHP | 810 lines | 500 code | 127 blank | 183 comment | 6 complexity | 96c84df06c4f381bed6e8a2db6e44024 MD5 | raw file
  1. <?php
  2. /**
  3. * BasicsTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, 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-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing 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 uses()
  139. *
  140. * @return void
  141. * @access public
  142. * @deprecated
  143. */
  144. function testUses() {
  145. $this->skipIf(class_exists('Security') || class_exists('Sanitize'), '%s Security and/or Sanitize class already loaded');
  146. $this->assertFalse(class_exists('Security'));
  147. $this->assertFalse(class_exists('Sanitize'));
  148. uses('Security', 'Sanitize');
  149. $this->assertTrue(class_exists('Security'));
  150. $this->assertTrue(class_exists('Sanitize'));
  151. }
  152. /**
  153. * Test h()
  154. *
  155. * @return void
  156. * @access public
  157. */
  158. function testH() {
  159. $string = '<foo>';
  160. $result = h($string);
  161. $this->assertEqual('&lt;foo&gt;', $result);
  162. $in = array('this & that', '<p>Which one</p>');
  163. $result = h($in);
  164. $expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;');
  165. $this->assertEqual($expected, $result);
  166. }
  167. /**
  168. * Test a()
  169. *
  170. * @return void
  171. * @access public
  172. */
  173. function testA() {
  174. $result = a('this', 'that', 'bar');
  175. $this->assertEqual(array('this', 'that', 'bar'), $result);
  176. }
  177. /**
  178. * Test aa()
  179. *
  180. * @return void
  181. * @access public
  182. */
  183. function testAa() {
  184. $result = aa('a', 'b', 'c', 'd');
  185. $expected = array('a' => 'b', 'c' => 'd');
  186. $this->assertEqual($expected, $result);
  187. $result = aa('a', 'b', 'c', 'd', 'e');
  188. $expected = array('a' => 'b', 'c' => 'd', 'e' => null);
  189. $this->assertEqual($result, $expected);
  190. }
  191. /**
  192. * Test am()
  193. *
  194. * @return void
  195. * @access public
  196. */
  197. function testAm() {
  198. $result = am(array('one', 'two'), 2, 3, 4);
  199. $expected = array('one', 'two', 2, 3, 4);
  200. $this->assertEqual($result, $expected);
  201. $result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
  202. $expected = array('one' => array(4, 5),'two' => array('foo'));
  203. $this->assertEqual($result, $expected);
  204. }
  205. /**
  206. * test cache()
  207. *
  208. * @return void
  209. * @access public
  210. */
  211. function testCache() {
  212. $_cacheDisable = Configure::read('Cache.disable');
  213. if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
  214. return;
  215. }
  216. Configure::write('Cache.disable', true);
  217. $result = cache('basics_test', 'simple cache write');
  218. $this->assertNull($result);
  219. $result = cache('basics_test');
  220. $this->assertNull($result);
  221. Configure::write('Cache.disable', false);
  222. $result = cache('basics_test', 'simple cache write');
  223. $this->assertTrue($result);
  224. $this->assertTrue(file_exists(CACHE . 'basics_test'));
  225. $result = cache('basics_test');
  226. $this->assertEqual($result, 'simple cache write');
  227. @unlink(CACHE . 'basics_test');
  228. cache('basics_test', 'expired', '+1 second');
  229. sleep(2);
  230. $result = cache('basics_test', null, '+1 second');
  231. $this->assertNull($result);
  232. Configure::write('Cache.disable', $_cacheDisable);
  233. }
  234. /**
  235. * test clearCache()
  236. *
  237. * @return void
  238. * @access public
  239. */
  240. function testClearCache() {
  241. $cacheOff = Configure::read('Cache.disable');
  242. if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
  243. return;
  244. }
  245. cache('views' . DS . 'basics_test.cache', 'simple cache write');
  246. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  247. cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
  248. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
  249. cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
  250. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  251. $result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
  252. $this->assertTrue($result);
  253. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  254. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
  255. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  256. $result = clearCache(null, 'views', '.cache');
  257. $this->assertTrue($result);
  258. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
  259. // Different path from views and with prefix
  260. cache('models' . DS . 'basics_test.cache', 'simple cache write');
  261. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
  262. cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
  263. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
  264. cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
  265. $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
  266. $result = clearCache('basics', 'models', '.cache');
  267. $this->assertTrue($result);
  268. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
  269. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
  270. $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
  271. // checking if empty files were not removed
  272. $emptyExists = file_exists(CACHE . 'views' . DS . 'empty');
  273. if (!$emptyExists) {
  274. cache('views' . DS . 'empty', '');
  275. }
  276. cache('views' . DS . 'basics_test.php', 'simple cache write');
  277. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
  278. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
  279. $result = clearCache();
  280. $this->assertTrue($result);
  281. $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
  282. $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
  283. if (!$emptyExists) {
  284. unlink(CACHE . 'views' . DS . 'empty');
  285. }
  286. }
  287. /**
  288. * test __()
  289. *
  290. * @return void
  291. * @access public
  292. */
  293. function test__() {
  294. Configure::write('Config.language', 'rule_1_po');
  295. $result = __('Plural Rule 1', true);
  296. $expected = 'Plural Rule 1 (translated)';
  297. $this->assertEqual($result, $expected);
  298. $result = __('Plural Rule 1 (from core)', true);
  299. $expected = 'Plural Rule 1 (from core translated)';
  300. $this->assertEqual($result, $expected);
  301. ob_start();
  302. __('Plural Rule 1 (from core)');
  303. $result = ob_get_clean();
  304. $expected = 'Plural Rule 1 (from core translated)';
  305. $this->assertEqual($result, $expected);
  306. }
  307. /**
  308. * test __n()
  309. *
  310. * @return void
  311. * @access public
  312. */
  313. function test__n() {
  314. Configure::write('Config.language', 'rule_1_po');
  315. $result = __n('%d = 1', '%d = 0 or > 1', 0, true);
  316. $expected = '%d = 0 or > 1 (translated)';
  317. $this->assertEqual($result, $expected);
  318. $result = __n('%d = 1', '%d = 0 or > 1', 1, true);
  319. $expected = '%d = 1 (translated)';
  320. $this->assertEqual($result, $expected);
  321. $result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2, true);
  322. $expected = '%d = 0 or > 1 (from core translated)';
  323. $this->assertEqual($result, $expected);
  324. ob_start();
  325. __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
  326. $result = ob_get_clean();
  327. $expected = '%d = 0 or > 1 (from core translated)';
  328. $this->assertEqual($result, $expected);
  329. }
  330. /**
  331. * test __d()
  332. *
  333. * @return void
  334. * @access public
  335. */
  336. function test__d() {
  337. Configure::write('Config.language', 'rule_1_po');
  338. $result = __d('default', 'Plural Rule 1', true);
  339. $expected = 'Plural Rule 1 (translated)';
  340. $this->assertEqual($result, $expected);
  341. $result = __d('core', 'Plural Rule 1', true);
  342. $expected = 'Plural Rule 1';
  343. $this->assertEqual($result, $expected);
  344. $result = __d('core', 'Plural Rule 1 (from core)', true);
  345. $expected = 'Plural Rule 1 (from core translated)';
  346. $this->assertEqual($result, $expected);
  347. ob_start();
  348. __d('core', 'Plural Rule 1 (from core)');
  349. $result = ob_get_clean();
  350. $expected = 'Plural Rule 1 (from core translated)';
  351. $this->assertEqual($result, $expected);
  352. }
  353. /**
  354. * test __dn()
  355. *
  356. * @return void
  357. * @access public
  358. */
  359. function test__dn() {
  360. Configure::write('Config.language', 'rule_1_po');
  361. $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0, true);
  362. $expected = '%d = 0 or > 1 (translated)';
  363. $this->assertEqual($result, $expected);
  364. $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0, true);
  365. $expected = '%d = 0 or > 1';
  366. $this->assertEqual($result, $expected);
  367. $result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0, true);
  368. $expected = '%d = 0 or > 1 (from core translated)';
  369. $this->assertEqual($result, $expected);
  370. $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1, true);
  371. $expected = '%d = 1 (translated)';
  372. $this->assertEqual($result, $expected);
  373. ob_start();
  374. __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
  375. $result = ob_get_clean();
  376. $expected = '%d = 0 or > 1 (from core translated)';
  377. $this->assertEqual($result, $expected);
  378. }
  379. /**
  380. * test __c()
  381. *
  382. * @return void
  383. * @access public
  384. */
  385. function test__c() {
  386. Configure::write('Config.language', 'rule_1_po');
  387. $result = __c('Plural Rule 1', 6, true);
  388. $expected = 'Plural Rule 1 (translated)';
  389. $this->assertEqual($result, $expected);
  390. $result = __c('Plural Rule 1 (from core)', 6, true);
  391. $expected = 'Plural Rule 1 (from core translated)';
  392. $this->assertEqual($result, $expected);
  393. ob_start();
  394. __c('Plural Rule 1 (from core)', 6);
  395. $result = ob_get_clean();
  396. $expected = 'Plural Rule 1 (from core translated)';
  397. $this->assertEqual($result, $expected);
  398. }
  399. /**
  400. * test __dc()
  401. *
  402. * @return void
  403. * @access public
  404. */
  405. function test__dc() {
  406. Configure::write('Config.language', 'rule_1_po');
  407. $result = __dc('default', 'Plural Rule 1', 6, true);
  408. $expected = 'Plural Rule 1 (translated)';
  409. $this->assertEqual($result, $expected);
  410. $result = __dc('default', 'Plural Rule 1 (from core)', 6, true);
  411. $expected = 'Plural Rule 1 (from core translated)';
  412. $this->assertEqual($result, $expected);
  413. $result = __dc('core', 'Plural Rule 1', 6, true);
  414. $expected = 'Plural Rule 1';
  415. $this->assertEqual($result, $expected);
  416. $result = __dc('core', 'Plural Rule 1 (from core)', 6, true);
  417. $expected = 'Plural Rule 1 (from core translated)';
  418. $this->assertEqual($result, $expected);
  419. ob_start();
  420. __dc('default', 'Plural Rule 1 (from core)', 6);
  421. $result = ob_get_clean();
  422. $expected = 'Plural Rule 1 (from core translated)';
  423. $this->assertEqual($result, $expected);
  424. }
  425. /**
  426. * test __dcn()
  427. *
  428. * @return void
  429. * @access public
  430. */
  431. function test__dcn() {
  432. Configure::write('Config.language', 'rule_1_po');
  433. $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6, true);
  434. $expected = '%d = 0 or > 1 (translated)';
  435. $this->assertEqual($result, $expected);
  436. $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6, true);
  437. $expected = '%d = 1 (from core translated)';
  438. $this->assertEqual($result, $expected);
  439. $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6, true);
  440. $expected = '%d = 0 or > 1';
  441. $this->assertEqual($result, $expected);
  442. ob_start();
  443. __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
  444. $result = ob_get_clean();
  445. $expected = '%d = 1 (from core translated)';
  446. $this->assertEqual($result, $expected);
  447. }
  448. /**
  449. * test LogError()
  450. *
  451. * @return void
  452. * @access public
  453. */
  454. function testLogError() {
  455. @unlink(LOGS . 'error.log');
  456. LogError('Testing LogError() basic function');
  457. LogError("Testing with\nmulti-line\nstring");
  458. $result = file_get_contents(LOGS . 'error.log');
  459. $this->assertPattern('/Error: Testing LogError\(\) basic function/', $result);
  460. $this->assertNoPattern("/Error: Testing with\nmulti-line\nstring/", $result);
  461. $this->assertPattern('/Error: Testing with multi-line string/', $result);
  462. }
  463. /**
  464. * test fileExistsInPath()
  465. *
  466. * @return void
  467. * @access public
  468. */
  469. function testFileExistsInPath() {
  470. $this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
  471. $_includePath = ini_get('include_path');
  472. $path = TMP . 'basics_test';
  473. $folder1 = $path . DS . 'folder1';
  474. $folder2 = $path . DS . 'folder2';
  475. $file1 = $path . DS . 'file1.php';
  476. $file2 = $folder1 . DS . 'file2.php';
  477. $file3 = $folder1 . DS . 'file3.php';
  478. $file4 = $folder2 . DS . 'file4.php';
  479. new Folder($path, true);
  480. new Folder($folder1, true);
  481. new Folder($folder2, true);
  482. touch($file1);
  483. touch($file2);
  484. touch($file3);
  485. touch($file4);
  486. ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
  487. $this->assertEqual(fileExistsInPath('file1.php'), $file1);
  488. $this->assertEqual(fileExistsInPath('file2.php'), $file2);
  489. $this->assertEqual(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
  490. $this->assertEqual(fileExistsInPath($file2), $file2);
  491. $this->assertEqual(fileExistsInPath('file3.php'), $file3);
  492. $this->assertEqual(fileExistsInPath($file4), $file4);
  493. $this->assertFalse(fileExistsInPath('file1'));
  494. $this->assertFalse(fileExistsInPath('file4.php'));
  495. $Folder = new Folder($path);
  496. $Folder->delete();
  497. ini_set('include_path', $_includePath);
  498. }
  499. /**
  500. * test convertSlash()
  501. *
  502. * @return void
  503. * @access public
  504. */
  505. function testConvertSlash() {
  506. $result = convertSlash('\path\to\location\\');
  507. $expected = '\path\to\location\\';
  508. $this->assertEqual($result, $expected);
  509. $result = convertSlash('/path/to/location/');
  510. $expected = 'path_to_location';
  511. $this->assertEqual($result, $expected);
  512. }
  513. /**
  514. * test debug()
  515. *
  516. * @return void
  517. * @access public
  518. */
  519. function testDebug() {
  520. ob_start();
  521. debug('this-is-a-test');
  522. $result = ob_get_clean();
  523. $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
  524. $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
  525. $pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
  526. $this->assertPattern($pattern, $result);
  527. ob_start();
  528. debug('<div>this-is-a-test</div>', true);
  529. $result = ob_get_clean();
  530. $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
  531. $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
  532. $pattern .= '.*line.*' . (__LINE__ - 4) . '.*&lt;div&gt;this-is-a-test&lt;\/div&gt;.*/s';
  533. $this->assertPattern($pattern, $result);
  534. }
  535. /**
  536. * test pr()
  537. *
  538. * @return void
  539. * @access public
  540. */
  541. function testPr() {
  542. ob_start();
  543. pr('this is a test');
  544. $result = ob_get_clean();
  545. $expected = "<pre>this is a test</pre>";
  546. $this->assertEqual($result, $expected);
  547. ob_start();
  548. pr(array('this' => 'is', 'a' => 'test'));
  549. $result = ob_get_clean();
  550. $expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
  551. $this->assertEqual($result, $expected);
  552. }
  553. /**
  554. * test params()
  555. *
  556. * @return void
  557. * @access public
  558. */
  559. function testParams() {
  560. $this->assertNull(params('weekend'));
  561. $this->assertNull(params(array()));
  562. $this->assertEqual(params(array('weekend')), array('weekend'));
  563. $nested = array(array('weekend'));
  564. $this->assertEqual(params($nested), array('weekend'));
  565. $multiple = array(array('weekend'), 'jean-luc', 'godard');
  566. $this->assertEqual(params($multiple), $multiple);
  567. }
  568. /**
  569. * test stripslashes_deep()
  570. *
  571. * @return void
  572. * @access public
  573. */
  574. function testStripslashesDeep() {
  575. $this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
  576. $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
  577. $this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
  578. $this->assertEqual(stripslashes_deep('tes\"t'), 'tes"t');
  579. $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
  580. $this->assertEqual(stripslashes_deep('te\\st'), 'test');
  581. $nested = array(
  582. 'a' => "tes\'t",
  583. 'b' => 'tes\\' . chr(0) .'t',
  584. 'c' => array(
  585. 'd' => 'tes\"t',
  586. 'e' => "te\'s\'t",
  587. array('f' => "tes\'t")
  588. ),
  589. 'g' => 'te\\st'
  590. );
  591. $expected = array(
  592. 'a' => "tes't",
  593. 'b' => 'tes' . chr(0) .'t',
  594. 'c' => array(
  595. 'd' => 'tes"t',
  596. 'e' => "te's't",
  597. array('f' => "tes't")
  598. ),
  599. 'g' => 'test'
  600. );
  601. $this->assertEqual(stripslashes_deep($nested), $expected);
  602. }
  603. /**
  604. * test stripslashes_deep() with magic_quotes_sybase on
  605. *
  606. * @return void
  607. * @access public
  608. */
  609. function testStripslashesDeepSybase() {
  610. $this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
  611. $this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
  612. $nested = array(
  613. 'a' => "tes't",
  614. 'b' => "tes''t",
  615. 'c' => array(
  616. 'd' => "tes'''t",
  617. 'e' => "tes''''t",
  618. array('f' => "tes''t")
  619. ),
  620. 'g' => "te'''''st"
  621. );
  622. $expected = array(
  623. 'a' => "tes't",
  624. 'b' => "tes't",
  625. 'c' => array(
  626. 'd' => "tes''t",
  627. 'e' => "tes''t",
  628. array('f' => "tes't")
  629. ),
  630. 'g' => "te'''st"
  631. );
  632. $this->assertEqual(stripslashes_deep($nested), $expected);
  633. }
  634. /**
  635. * test ife()
  636. *
  637. * @return void
  638. * @access public
  639. */
  640. function testIfe() {
  641. $this->assertEqual(ife(true, 'a', 'b'), 'a');
  642. $this->assertEqual(ife(' ', 'a', 'b'), 'a');
  643. $this->assertEqual(ife('test', 'a', 'b'), 'a');
  644. $this->assertEqual(ife(23, 'a', 'b'), 'a');
  645. $this->assertEqual(ife(array('t' => 'est'), 'a', 'b'), 'a');
  646. $this->assertEqual(ife(false, 'a', 'b'), 'b');
  647. $this->assertEqual(ife(null, 'a', 'b'), 'b');
  648. $this->assertEqual(ife('', 'a', 'b'), 'b');
  649. $this->assertEqual(ife(0, 'a', 'b'), 'b');
  650. $this->assertEqual(ife(array(), 'a', 'b'), 'b');
  651. }
  652. /**
  653. * test pluginSplit
  654. *
  655. * @return void
  656. */
  657. function testPluginSplit() {
  658. $result = pluginSplit('Something.else');
  659. $this->assertEqual($result, array('Something', 'else'));
  660. $result = pluginSplit('Something.else.more.dots');
  661. $this->assertEqual($result, array('Something', 'else.more.dots'));
  662. $result = pluginSplit('Somethingelse');
  663. $this->assertEqual($result, array(null, 'Somethingelse'));
  664. $result = pluginSplit('Something.else', true);
  665. $this->assertEqual($result, array('Something.', 'else'));
  666. $result = pluginSplit('Something.else.more.dots', true);
  667. $this->assertEqual($result, array('Something.', 'else.more.dots'));
  668. $result = pluginSplit('Post', false, 'Blog');
  669. $this->assertEqual($result, array('Blog', 'Post'));
  670. $result = pluginSplit('Blog.Post', false, 'Ultimate');
  671. $this->assertEqual($result, array('Blog', 'Post'));
  672. }
  673. }