PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/code/ryzom/tools/server/www/webtt/cake/tests/cases/basics.test.php

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