Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / web / public_php / webtt / cake / tests / cases / basics.test.php
blob6ba22e6b87cf127474444e29fc148e95ec011218
1 <?php
2 /**
3 * BasicsTest file
5 * PHP versions 4 and 5
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10 * Licensed under The Open Group Test Suite License
11 * Redistributions of files must retain the above copyright notice.
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
20 require_once CAKE . 'basics.php';
21 App::import('Core', 'Folder');
23 /**
24 * BasicsTest class
26 * @package cake
27 * @subpackage cake.tests.cases
29 class BasicsTest extends CakeTestCase {
31 /**
32 * setUp method
34 * @return void
35 * @access public
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');
44 /**
45 * tearDown method
47 * @return void
48 * @access public
50 function tearDown() {
51 App::build();
52 Configure::write('Config.language', $this->_language);
55 /**
56 * test the array_diff_key compatibility function.
58 * @return void
59 * @access public
61 function testArrayDiffKey() {
62 $one = array('one' => 1, 'two' => 2, 'three' => 3);
63 $two = array('one' => 'one', 'two' => 'two');
64 $result = array_diff_key($one, $two);
65 $expected = array('three' => 3);
66 $this->assertEqual($result, $expected);
68 $one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3);
69 $two = array('two' => 'two');
70 $result = array_diff_key($one, $two);
71 $expected = array('one' => array('value', 'value-two'), 'three' => 3);
72 $this->assertEqual($result, $expected);
74 $one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0);
75 $two = array('two' => 'two');
76 $result = array_diff_key($one, $two);
77 $expected = array('one' => null, 'three' => '', 'four' => 0);
78 $this->assertEqual($result, $expected);
80 $one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
81 $two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
82 $result = array_diff_key($one, $two);
83 $this->assertEqual($result, array());
86 /**
87 * testHttpBase method
89 * @return void
90 * @access public
92 function testEnv() {
93 $this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
95 $__SERVER = $_SERVER;
96 $__ENV = $_ENV;
98 $_SERVER['HTTP_HOST'] = 'localhost';
99 $this->assertEqual(env('HTTP_BASE'), '.localhost');
101 $_SERVER['HTTP_HOST'] = 'com.ar';
102 $this->assertEqual(env('HTTP_BASE'), '.com.ar');
104 $_SERVER['HTTP_HOST'] = 'example.ar';
105 $this->assertEqual(env('HTTP_BASE'), '.example.ar');
107 $_SERVER['HTTP_HOST'] = 'example.com';
108 $this->assertEqual(env('HTTP_BASE'), '.example.com');
110 $_SERVER['HTTP_HOST'] = 'www.example.com';
111 $this->assertEqual(env('HTTP_BASE'), '.example.com');
113 $_SERVER['HTTP_HOST'] = 'subdomain.example.com';
114 $this->assertEqual(env('HTTP_BASE'), '.example.com');
116 $_SERVER['HTTP_HOST'] = 'example.com.ar';
117 $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
119 $_SERVER['HTTP_HOST'] = 'www.example.com.ar';
120 $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
122 $_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
123 $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
125 $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
126 $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
128 $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
129 $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
131 $_SERVER = $_ENV = array();
133 $_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
134 $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
136 $_SERVER = $_ENV = array();
138 $_ENV['CGI_MODE'] = 'BINARY';
139 $_ENV['SCRIPT_URL'] = '/a/test/test.php';
140 $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
142 $_SERVER = $_ENV = array();
144 $this->assertFalse(env('HTTPS'));
146 $_SERVER['HTTPS'] = 'on';
147 $this->assertTrue(env('HTTPS'));
149 $_SERVER['HTTPS'] = '1';
150 $this->assertTrue(env('HTTPS'));
152 $_SERVER['HTTPS'] = 'I am not empty';
153 $this->assertTrue(env('HTTPS'));
155 $_SERVER['HTTPS'] = 1;
156 $this->assertTrue(env('HTTPS'));
158 $_SERVER['HTTPS'] = 'off';
159 $this->assertFalse(env('HTTPS'));
161 $_SERVER['HTTPS'] = false;
162 $this->assertFalse(env('HTTPS'));
164 $_SERVER['HTTPS'] = '';
165 $this->assertFalse(env('HTTPS'));
167 $_SERVER = array();
169 $_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';
170 $this->assertTrue(env('HTTPS'));
172 $_ENV['SCRIPT_URI'] = 'http://domain.test/a/test.php';
173 $this->assertFalse(env('HTTPS'));
175 $_SERVER = $_ENV = array();
177 $this->assertFalse(env('TEST_ME'));
179 $_ENV['TEST_ME'] = 'a';
180 $this->assertEqual(env('TEST_ME'), 'a');
182 $_SERVER['TEST_ME'] = 'b';
183 $this->assertEqual(env('TEST_ME'), 'b');
185 unset($_ENV['TEST_ME']);
186 $this->assertEqual(env('TEST_ME'), 'b');
188 $_SERVER = $__SERVER;
189 $_ENV = $__ENV;
193 * test uses()
195 * @return void
196 * @access public
197 * @deprecated
199 function testUses() {
200 $this->skipIf(class_exists('Security') || class_exists('Sanitize'), '%s Security and/or Sanitize class already loaded');
202 $this->assertFalse(class_exists('Security'));
203 $this->assertFalse(class_exists('Sanitize'));
205 uses('Security', 'Sanitize');
207 $this->assertTrue(class_exists('Security'));
208 $this->assertTrue(class_exists('Sanitize'));
212 * Test h()
214 * @return void
215 * @access public
217 function testH() {
218 $string = '<foo>';
219 $result = h($string);
220 $this->assertEqual('&lt;foo&gt;', $result);
222 $in = array('this & that', '<p>Which one</p>');
223 $result = h($in);
224 $expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;');
225 $this->assertEqual($expected, $result);
229 * Test a()
231 * @return void
232 * @access public
234 function testA() {
235 $result = a('this', 'that', 'bar');
236 $this->assertEqual(array('this', 'that', 'bar'), $result);
240 * Test aa()
242 * @return void
243 * @access public
245 function testAa() {
246 $result = aa('a', 'b', 'c', 'd');
247 $expected = array('a' => 'b', 'c' => 'd');
248 $this->assertEqual($expected, $result);
250 $result = aa('a', 'b', 'c', 'd', 'e');
251 $expected = array('a' => 'b', 'c' => 'd', 'e' => null);
252 $this->assertEqual($result, $expected);
256 * Test am()
258 * @return void
259 * @access public
261 function testAm() {
262 $result = am(array('one', 'two'), 2, 3, 4);
263 $expected = array('one', 'two', 2, 3, 4);
264 $this->assertEqual($result, $expected);
266 $result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
267 $expected = array('one' => array(4, 5),'two' => array('foo'));
268 $this->assertEqual($result, $expected);
272 * test cache()
274 * @return void
275 * @access public
277 function testCache() {
278 $_cacheDisable = Configure::read('Cache.disable');
279 if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
280 return;
283 Configure::write('Cache.disable', true);
284 $result = cache('basics_test', 'simple cache write');
285 $this->assertNull($result);
287 $result = cache('basics_test');
288 $this->assertNull($result);
290 Configure::write('Cache.disable', false);
291 $result = cache('basics_test', 'simple cache write');
292 $this->assertTrue($result);
293 $this->assertTrue(file_exists(CACHE . 'basics_test'));
295 $result = cache('basics_test');
296 $this->assertEqual($result, 'simple cache write');
297 @unlink(CACHE . 'basics_test');
299 cache('basics_test', 'expired', '+1 second');
300 sleep(2);
301 $result = cache('basics_test', null, '+1 second');
302 $this->assertNull($result);
304 Configure::write('Cache.disable', $_cacheDisable);
308 * test clearCache()
310 * @return void
311 * @access public
313 function testClearCache() {
314 $cacheOff = Configure::read('Cache.disable');
315 if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
316 return;
319 cache('views' . DS . 'basics_test.cache', 'simple cache write');
320 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
322 cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
323 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
325 cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
326 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
328 $result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
329 $this->assertTrue($result);
330 $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
331 $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
332 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
334 $result = clearCache(null, 'views', '.cache');
335 $this->assertTrue($result);
336 $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
338 // Different path from views and with prefix
339 cache('models' . DS . 'basics_test.cache', 'simple cache write');
340 $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
342 cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
343 $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
345 cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
346 $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
348 $result = clearCache('basics', 'models', '.cache');
349 $this->assertTrue($result);
350 $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
351 $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
352 $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
354 // checking if empty files were not removed
355 $emptyExists = file_exists(CACHE . 'views' . DS . 'empty');
356 if (!$emptyExists) {
357 cache('views' . DS . 'empty', '');
359 cache('views' . DS . 'basics_test.php', 'simple cache write');
360 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
361 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
363 $result = clearCache();
364 $this->assertTrue($result);
365 $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
366 $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
367 if (!$emptyExists) {
368 unlink(CACHE . 'views' . DS . 'empty');
373 * test __()
375 * @return void
376 * @access public
378 function test__() {
379 Configure::write('Config.language', 'rule_1_po');
381 $result = __('Plural Rule 1', true);
382 $expected = 'Plural Rule 1 (translated)';
383 $this->assertEqual($result, $expected);
385 $result = __('Plural Rule 1 (from core)', true);
386 $expected = 'Plural Rule 1 (from core translated)';
387 $this->assertEqual($result, $expected);
389 ob_start();
390 __('Plural Rule 1 (from core)');
391 $result = ob_get_clean();
392 $expected = 'Plural Rule 1 (from core translated)';
393 $this->assertEqual($result, $expected);
397 * test __n()
399 * @return void
400 * @access public
402 function test__n() {
403 Configure::write('Config.language', 'rule_1_po');
405 $result = __n('%d = 1', '%d = 0 or > 1', 0, true);
406 $expected = '%d = 0 or > 1 (translated)';
407 $this->assertEqual($result, $expected);
409 $result = __n('%d = 1', '%d = 0 or > 1', 1, true);
410 $expected = '%d = 1 (translated)';
411 $this->assertEqual($result, $expected);
413 $result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2, true);
414 $expected = '%d = 0 or > 1 (from core translated)';
415 $this->assertEqual($result, $expected);
417 ob_start();
418 __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
419 $result = ob_get_clean();
420 $expected = '%d = 0 or > 1 (from core translated)';
421 $this->assertEqual($result, $expected);
425 * test __d()
427 * @return void
428 * @access public
430 function test__d() {
431 Configure::write('Config.language', 'rule_1_po');
433 $result = __d('default', 'Plural Rule 1', true);
434 $expected = 'Plural Rule 1 (translated)';
435 $this->assertEqual($result, $expected);
437 $result = __d('core', 'Plural Rule 1', true);
438 $expected = 'Plural Rule 1';
439 $this->assertEqual($result, $expected);
441 $result = __d('core', 'Plural Rule 1 (from core)', true);
442 $expected = 'Plural Rule 1 (from core translated)';
443 $this->assertEqual($result, $expected);
445 ob_start();
446 __d('core', 'Plural Rule 1 (from core)');
447 $result = ob_get_clean();
448 $expected = 'Plural Rule 1 (from core translated)';
449 $this->assertEqual($result, $expected);
453 * test __dn()
455 * @return void
456 * @access public
458 function test__dn() {
459 Configure::write('Config.language', 'rule_1_po');
461 $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0, true);
462 $expected = '%d = 0 or > 1 (translated)';
463 $this->assertEqual($result, $expected);
465 $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0, true);
466 $expected = '%d = 0 or > 1';
467 $this->assertEqual($result, $expected);
469 $result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0, true);
470 $expected = '%d = 0 or > 1 (from core translated)';
471 $this->assertEqual($result, $expected);
473 $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1, true);
474 $expected = '%d = 1 (translated)';
475 $this->assertEqual($result, $expected);
477 ob_start();
478 __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
479 $result = ob_get_clean();
480 $expected = '%d = 0 or > 1 (from core translated)';
481 $this->assertEqual($result, $expected);
485 * test __c()
487 * @return void
488 * @access public
490 function test__c() {
491 Configure::write('Config.language', 'rule_1_po');
493 $result = __c('Plural Rule 1', 6, true);
494 $expected = 'Plural Rule 1 (translated)';
495 $this->assertEqual($result, $expected);
497 $result = __c('Plural Rule 1 (from core)', 6, true);
498 $expected = 'Plural Rule 1 (from core translated)';
499 $this->assertEqual($result, $expected);
501 ob_start();
502 __c('Plural Rule 1 (from core)', 6);
503 $result = ob_get_clean();
504 $expected = 'Plural Rule 1 (from core translated)';
505 $this->assertEqual($result, $expected);
509 * test __dc()
511 * @return void
512 * @access public
514 function test__dc() {
515 Configure::write('Config.language', 'rule_1_po');
517 $result = __dc('default', 'Plural Rule 1', 6, true);
518 $expected = 'Plural Rule 1 (translated)';
519 $this->assertEqual($result, $expected);
521 $result = __dc('default', 'Plural Rule 1 (from core)', 6, true);
522 $expected = 'Plural Rule 1 (from core translated)';
523 $this->assertEqual($result, $expected);
525 $result = __dc('core', 'Plural Rule 1', 6, true);
526 $expected = 'Plural Rule 1';
527 $this->assertEqual($result, $expected);
529 $result = __dc('core', 'Plural Rule 1 (from core)', 6, true);
530 $expected = 'Plural Rule 1 (from core translated)';
531 $this->assertEqual($result, $expected);
533 ob_start();
534 __dc('default', 'Plural Rule 1 (from core)', 6);
535 $result = ob_get_clean();
536 $expected = 'Plural Rule 1 (from core translated)';
537 $this->assertEqual($result, $expected);
541 * test __dcn()
543 * @return void
544 * @access public
546 function test__dcn() {
547 Configure::write('Config.language', 'rule_1_po');
549 $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6, true);
550 $expected = '%d = 0 or > 1 (translated)';
551 $this->assertEqual($result, $expected);
553 $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6, true);
554 $expected = '%d = 1 (from core translated)';
555 $this->assertEqual($result, $expected);
557 $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6, true);
558 $expected = '%d = 0 or > 1';
559 $this->assertEqual($result, $expected);
561 ob_start();
562 __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
563 $result = ob_get_clean();
564 $expected = '%d = 1 (from core translated)';
565 $this->assertEqual($result, $expected);
569 * test LogError()
571 * @return void
572 * @access public
574 function testLogError() {
575 @unlink(LOGS . 'error.log');
577 LogError('Testing LogError() basic function');
578 LogError("Testing with\nmulti-line\nstring");
580 $result = file_get_contents(LOGS . 'error.log');
581 $this->assertPattern('/Error: Testing LogError\(\) basic function/', $result);
582 $this->assertNoPattern("/Error: Testing with\nmulti-line\nstring/", $result);
583 $this->assertPattern('/Error: Testing with multi-line string/', $result);
587 * test fileExistsInPath()
589 * @return void
590 * @access public
592 function testFileExistsInPath() {
593 $this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
595 $_includePath = ini_get('include_path');
597 $path = TMP . 'basics_test';
598 $folder1 = $path . DS . 'folder1';
599 $folder2 = $path . DS . 'folder2';
600 $file1 = $path . DS . 'file1.php';
601 $file2 = $folder1 . DS . 'file2.php';
602 $file3 = $folder1 . DS . 'file3.php';
603 $file4 = $folder2 . DS . 'file4.php';
605 new Folder($path, true);
606 new Folder($folder1, true);
607 new Folder($folder2, true);
608 touch($file1);
609 touch($file2);
610 touch($file3);
611 touch($file4);
613 ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
615 $this->assertEqual(fileExistsInPath('file1.php'), $file1);
616 $this->assertEqual(fileExistsInPath('file2.php'), $file2);
617 $this->assertEqual(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
618 $this->assertEqual(fileExistsInPath($file2), $file2);
619 $this->assertEqual(fileExistsInPath('file3.php'), $file3);
620 $this->assertEqual(fileExistsInPath($file4), $file4);
622 $this->assertFalse(fileExistsInPath('file1'));
623 $this->assertFalse(fileExistsInPath('file4.php'));
625 $Folder = new Folder($path);
626 $Folder->delete();
628 ini_set('include_path', $_includePath);
632 * test convertSlash()
634 * @return void
635 * @access public
637 function testConvertSlash() {
638 $result = convertSlash('\path\to\location\\');
639 $expected = '\path\to\location\\';
640 $this->assertEqual($result, $expected);
642 $result = convertSlash('/path/to/location/');
643 $expected = 'path_to_location';
644 $this->assertEqual($result, $expected);
648 * test debug()
650 * @return void
651 * @access public
653 function testDebug() {
654 ob_start();
655 debug('this-is-a-test');
656 $result = ob_get_clean();
657 $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
658 $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
659 $pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
660 $this->assertPattern($pattern, $result);
662 ob_start();
663 debug('<div>this-is-a-test</div>', true);
664 $result = ob_get_clean();
665 $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
666 $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
667 $pattern .= '.*line.*' . (__LINE__ - 4) . '.*&lt;div&gt;this-is-a-test&lt;\/div&gt;.*/s';
668 $this->assertPattern($pattern, $result);
672 * test pr()
674 * @return void
675 * @access public
677 function testPr() {
678 ob_start();
679 pr('this is a test');
680 $result = ob_get_clean();
681 $expected = "<pre>this is a test</pre>";
682 $this->assertEqual($result, $expected);
684 ob_start();
685 pr(array('this' => 'is', 'a' => 'test'));
686 $result = ob_get_clean();
687 $expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
688 $this->assertEqual($result, $expected);
692 * test params()
694 * @return void
695 * @access public
697 function testParams() {
698 $this->assertNull(params('weekend'));
699 $this->assertNull(params(array()));
700 $this->assertEqual(params(array('weekend')), array('weekend'));
702 $nested = array(array('weekend'));
703 $this->assertEqual(params($nested), array('weekend'));
705 $multiple = array(array('weekend'), 'jean-luc', 'godard');
706 $this->assertEqual(params($multiple), $multiple);
710 * test stripslashes_deep()
712 * @return void
713 * @access public
715 function testStripslashesDeep() {
716 $this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
718 $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
719 $this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
720 $this->assertEqual(stripslashes_deep('tes\"t'), 'tes"t');
721 $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
722 $this->assertEqual(stripslashes_deep('te\\st'), 'test');
724 $nested = array(
725 'a' => "tes\'t",
726 'b' => 'tes\\' . chr(0) .'t',
727 'c' => array(
728 'd' => 'tes\"t',
729 'e' => "te\'s\'t",
730 array('f' => "tes\'t")
732 'g' => 'te\\st'
734 $expected = array(
735 'a' => "tes't",
736 'b' => 'tes' . chr(0) .'t',
737 'c' => array(
738 'd' => 'tes"t',
739 'e' => "te's't",
740 array('f' => "tes't")
742 'g' => 'test'
744 $this->assertEqual(stripslashes_deep($nested), $expected);
748 * test stripslashes_deep() with magic_quotes_sybase on
750 * @return void
751 * @access public
753 function testStripslashesDeepSybase() {
754 $this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
756 $this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
758 $nested = array(
759 'a' => "tes't",
760 'b' => "tes''t",
761 'c' => array(
762 'd' => "tes'''t",
763 'e' => "tes''''t",
764 array('f' => "tes''t")
766 'g' => "te'''''st"
768 $expected = array(
769 'a' => "tes't",
770 'b' => "tes't",
771 'c' => array(
772 'd' => "tes''t",
773 'e' => "tes''t",
774 array('f' => "tes't")
776 'g' => "te'''st"
778 $this->assertEqual(stripslashes_deep($nested), $expected);
782 * test ife()
784 * @return void
785 * @access public
787 function testIfe() {
788 $this->assertEqual(ife(true, 'a', 'b'), 'a');
789 $this->assertEqual(ife(' ', 'a', 'b'), 'a');
790 $this->assertEqual(ife('test', 'a', 'b'), 'a');
791 $this->assertEqual(ife(23, 'a', 'b'), 'a');
792 $this->assertEqual(ife(array('t' => 'est'), 'a', 'b'), 'a');
794 $this->assertEqual(ife(false, 'a', 'b'), 'b');
795 $this->assertEqual(ife(null, 'a', 'b'), 'b');
796 $this->assertEqual(ife('', 'a', 'b'), 'b');
797 $this->assertEqual(ife(0, 'a', 'b'), 'b');
798 $this->assertEqual(ife(array(), 'a', 'b'), 'b');
802 * test pluginSplit
804 * @return void
806 function testPluginSplit() {
807 $result = pluginSplit('Something.else');
808 $this->assertEqual($result, array('Something', 'else'));
810 $result = pluginSplit('Something.else.more.dots');
811 $this->assertEqual($result, array('Something', 'else.more.dots'));
813 $result = pluginSplit('Somethingelse');
814 $this->assertEqual($result, array(null, 'Somethingelse'));
816 $result = pluginSplit('Something.else', true);
817 $this->assertEqual($result, array('Something.', 'else'));
819 $result = pluginSplit('Something.else.more.dots', true);
820 $this->assertEqual($result, array('Something.', 'else.more.dots'));
822 $result = pluginSplit('Post', false, 'Blog');
823 $this->assertEqual($result, array('Blog', 'Post'));
825 $result = pluginSplit('Blog.Post', false, 'Ultimate');
826 $this->assertEqual($result, array('Blog', 'Post'));