source: Dev/branches/cakephp/cake/tests/cases/basics.test.php @ 126

Last change on this file since 126 was 126, checked in by fpvanagthoven, 14 years ago

Cakephp branch.

File size: 22.5 KB
Line 
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-2011, 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-2011, 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 */
20require_once CAKE . 'basics.php';
21App::import('Core', 'Folder');
22
23/**
24 * BasicsTest class
25 *
26 * @package       cake
27 * @subpackage    cake.tests.cases
28 */
29class BasicsTest extends CakeTestCase {
30
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/**
45 * tearDown method
46 *
47 * @return void
48 * @access public
49 */
50        function tearDown() {
51                App::build();
52                Configure::write('Config.language', $this->_language);
53        }
54
55/**
56 * test the array_diff_key compatibility function.
57 *
58 * @return void
59 * @access public
60 */
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);
67
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);
73
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);
79
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());
84
85        }
86/**
87 * testHttpBase method
88 *
89 * @return void
90 * @access public
91 */
92        function testEnv() {
93                $this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
94
95                $__SERVER = $_SERVER;
96                $__ENV = $_ENV;
97
98                $_SERVER['HTTP_HOST'] = 'localhost';
99                $this->assertEqual(env('HTTP_BASE'), '.localhost');
100
101                $_SERVER['HTTP_HOST'] = 'com.ar';
102                $this->assertEqual(env('HTTP_BASE'), '.com.ar');
103
104                $_SERVER['HTTP_HOST'] = 'example.ar';
105                $this->assertEqual(env('HTTP_BASE'), '.example.ar');
106
107                $_SERVER['HTTP_HOST'] = 'example.com';
108                $this->assertEqual(env('HTTP_BASE'), '.example.com');
109
110                $_SERVER['HTTP_HOST'] = 'www.example.com';
111                $this->assertEqual(env('HTTP_BASE'), '.example.com');
112
113                $_SERVER['HTTP_HOST'] = 'subdomain.example.com';
114                $this->assertEqual(env('HTTP_BASE'), '.example.com');
115
116                $_SERVER['HTTP_HOST'] = 'example.com.ar';
117                $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
118
119                $_SERVER['HTTP_HOST'] = 'www.example.com.ar';
120                $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
121
122                $_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
123                $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
124
125                $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
126                $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
127
128                $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
129                $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
130
131                $_SERVER = $_ENV = array();
132
133                $_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
134                $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
135
136                $_SERVER = $_ENV = array();
137
138                $_ENV['CGI_MODE'] = 'BINARY';
139                $_ENV['SCRIPT_URL'] = '/a/test/test.php';
140                $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
141
142                $_SERVER = $_ENV = array();
143
144                $this->assertFalse(env('HTTPS'));
145
146                $_SERVER['HTTPS'] = 'on';
147                $this->assertTrue(env('HTTPS'));
148
149                $_SERVER['HTTPS'] = '1';
150                $this->assertTrue(env('HTTPS'));
151
152                $_SERVER['HTTPS'] = 'I am not empty';
153                $this->assertTrue(env('HTTPS'));
154
155                $_SERVER['HTTPS'] = 1;
156                $this->assertTrue(env('HTTPS'));
157
158                $_SERVER['HTTPS'] = 'off';
159                $this->assertFalse(env('HTTPS'));
160
161                $_SERVER['HTTPS'] = false;
162                $this->assertFalse(env('HTTPS'));
163
164                $_SERVER['HTTPS'] = '';
165                $this->assertFalse(env('HTTPS'));
166
167                $_SERVER = array();
168
169                $_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';
170                $this->assertTrue(env('HTTPS'));
171
172                $_ENV['SCRIPT_URI'] = 'http://domain.test/a/test.php';
173                $this->assertFalse(env('HTTPS'));
174
175                $_SERVER = $_ENV = array();
176
177                $this->assertFalse(env('TEST_ME'));
178
179                $_ENV['TEST_ME'] = 'a';
180                $this->assertEqual(env('TEST_ME'), 'a');
181
182                $_SERVER['TEST_ME'] = 'b';
183                $this->assertEqual(env('TEST_ME'), 'b');
184
185                unset($_ENV['TEST_ME']);
186                $this->assertEqual(env('TEST_ME'), 'b');
187
188                $_SERVER = $__SERVER;
189                $_ENV = $__ENV;
190        }
191
192/**
193 * test uses()
194 *
195 * @return void
196 * @access public
197 * @deprecated
198 */
199        function testUses() {
200                $this->skipIf(class_exists('Security') || class_exists('Sanitize'), '%s Security and/or Sanitize class already loaded');
201
202                $this->assertFalse(class_exists('Security'));
203                $this->assertFalse(class_exists('Sanitize'));
204
205                uses('Security', 'Sanitize');
206
207                $this->assertTrue(class_exists('Security'));
208                $this->assertTrue(class_exists('Sanitize'));
209        }
210
211/**
212 * Test h()
213 *
214 * @return void
215 * @access public
216 */
217        function testH() {
218                $string = '<foo>';
219                $result = h($string);
220                $this->assertEqual('&lt;foo&gt;', $result);
221
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);
226        }
227
228/**
229 * Test a()
230 *
231 * @return void
232 * @access public
233 */
234        function testA() {
235                $result = a('this', 'that', 'bar');
236                $this->assertEqual(array('this', 'that', 'bar'), $result);
237        }
238
239/**
240 * Test aa()
241 *
242 * @return void
243 * @access public
244 */
245        function testAa() {
246                $result = aa('a', 'b', 'c', 'd');
247                $expected = array('a' => 'b', 'c' => 'd');
248                $this->assertEqual($expected, $result);
249
250                $result = aa('a', 'b', 'c', 'd', 'e');
251                $expected = array('a' => 'b', 'c' => 'd', 'e' => null);
252                $this->assertEqual($result, $expected);
253        }
254
255/**
256 * Test am()
257 *
258 * @return void
259 * @access public
260 */
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);
265
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);
269        }
270
271/**
272 * test cache()
273 *
274 * @return void
275 * @access public
276 */
277        function testCache() {
278                $_cacheDisable = Configure::read('Cache.disable');
279                if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
280                        return;
281                }
282
283                Configure::write('Cache.disable', true);
284                $result = cache('basics_test', 'simple cache write');
285                $this->assertNull($result);
286
287                $result = cache('basics_test');
288                $this->assertNull($result);
289
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'));
294
295                $result = cache('basics_test');
296                $this->assertEqual($result, 'simple cache write');
297                @unlink(CACHE . 'basics_test');
298
299                cache('basics_test', 'expired', '+1 second');
300                sleep(2);
301                $result = cache('basics_test', null, '+1 second');
302                $this->assertNull($result);
303
304                Configure::write('Cache.disable', $_cacheDisable);
305        }
306
307/**
308 * test clearCache()
309 *
310 * @return void
311 * @access public
312 */
313        function testClearCache() {
314                $cacheOff = Configure::read('Cache.disable');
315                if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
316                        return;
317                }
318
319                cache('views' . DS . 'basics_test.cache', 'simple cache write');
320                $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
321
322                cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
323                $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
324
325                cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
326                $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
327
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'));
333
334                $result = clearCache(null, 'views', '.cache');
335                $this->assertTrue($result);
336                $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
337
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'));
341
342                cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
343                $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
344
345                cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
346                $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
347
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'));
353
354                // checking if empty files were not removed
355                $emptyExists = file_exists(CACHE . 'views' . DS . 'empty');
356                if (!$emptyExists) {
357                        cache('views' . DS . 'empty', '');
358                }
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'));
362
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');
369                }
370        }
371
372/**
373 * test __()
374 *
375 * @return void
376 * @access public
377 */
378        function test__() {
379                Configure::write('Config.language', 'rule_1_po');
380
381                $result = __('Plural Rule 1', true);
382                $expected = 'Plural Rule 1 (translated)';
383                $this->assertEqual($result, $expected);
384
385                $result = __('Plural Rule 1 (from core)', true);
386                $expected = 'Plural Rule 1 (from core translated)';
387                $this->assertEqual($result, $expected);
388
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);
394        }
395
396/**
397 * test __n()
398 *
399 * @return void
400 * @access public
401 */
402        function test__n() {
403                Configure::write('Config.language', 'rule_1_po');
404
405                $result = __n('%d = 1', '%d = 0 or > 1', 0, true);
406                $expected = '%d = 0 or > 1 (translated)';
407                $this->assertEqual($result, $expected);
408
409                $result = __n('%d = 1', '%d = 0 or > 1', 1, true);
410                $expected = '%d = 1 (translated)';
411                $this->assertEqual($result, $expected);
412
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);
416
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);
422        }
423
424/**
425 * test __d()
426 *
427 * @return void
428 * @access public
429 */
430        function test__d() {
431                Configure::write('Config.language', 'rule_1_po');
432
433                $result = __d('default', 'Plural Rule 1', true);
434                $expected = 'Plural Rule 1 (translated)';
435                $this->assertEqual($result, $expected);
436
437                $result = __d('core', 'Plural Rule 1', true);
438                $expected = 'Plural Rule 1';
439                $this->assertEqual($result, $expected);
440
441                $result = __d('core', 'Plural Rule 1 (from core)', true);
442                $expected = 'Plural Rule 1 (from core translated)';
443                $this->assertEqual($result, $expected);
444
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);
450        }
451
452/**
453 * test __dn()
454 *
455 * @return void
456 * @access public
457 */
458        function test__dn() {
459                Configure::write('Config.language', 'rule_1_po');
460
461                $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0, true);
462                $expected = '%d = 0 or > 1 (translated)';
463                $this->assertEqual($result, $expected);
464
465                $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0, true);
466                $expected = '%d = 0 or > 1';
467                $this->assertEqual($result, $expected);
468
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);
472
473                $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1, true);
474                $expected = '%d = 1 (translated)';
475                $this->assertEqual($result, $expected);
476
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);
482        }
483
484/**
485 * test __c()
486 *
487 * @return void
488 * @access public
489 */
490        function test__c() {
491                Configure::write('Config.language', 'rule_1_po');
492
493                $result = __c('Plural Rule 1', 6, true);
494                $expected = 'Plural Rule 1 (translated)';
495                $this->assertEqual($result, $expected);
496
497                $result = __c('Plural Rule 1 (from core)', 6, true);
498                $expected = 'Plural Rule 1 (from core translated)';
499                $this->assertEqual($result, $expected);
500
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);
506        }
507
508/**
509 * test __dc()
510 *
511 * @return void
512 * @access public
513 */
514        function test__dc() {
515                Configure::write('Config.language', 'rule_1_po');
516
517                $result = __dc('default', 'Plural Rule 1', 6, true);
518                $expected = 'Plural Rule 1 (translated)';
519                $this->assertEqual($result, $expected);
520
521                $result = __dc('default', 'Plural Rule 1 (from core)', 6, true);
522                $expected = 'Plural Rule 1 (from core translated)';
523                $this->assertEqual($result, $expected);
524
525                $result = __dc('core', 'Plural Rule 1', 6, true);
526                $expected = 'Plural Rule 1';
527                $this->assertEqual($result, $expected);
528
529                $result = __dc('core', 'Plural Rule 1 (from core)', 6, true);
530                $expected = 'Plural Rule 1 (from core translated)';
531                $this->assertEqual($result, $expected);
532
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);
538        }
539
540/**
541 * test __dcn()
542 *
543 * @return void
544 * @access public
545 */
546        function test__dcn() {
547                Configure::write('Config.language', 'rule_1_po');
548
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);
552
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);
556
557                $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6, true);
558                $expected = '%d = 0 or > 1';
559                $this->assertEqual($result, $expected);
560
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);
566        }
567
568/**
569 * test LogError()
570 *
571 * @return void
572 * @access public
573 */
574        function testLogError() {
575                @unlink(LOGS . 'error.log');
576
577                LogError('Testing LogError() basic function');
578                LogError("Testing with\nmulti-line\nstring");
579
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);
584        }
585
586/**
587 * test fileExistsInPath()
588 *
589 * @return void
590 * @access public
591 */
592        function testFileExistsInPath() {
593                $this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
594
595                $_includePath = ini_get('include_path');
596
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';
604
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);
612
613                ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
614
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);
621
622                $this->assertFalse(fileExistsInPath('file1'));
623                $this->assertFalse(fileExistsInPath('file4.php'));
624
625                $Folder = new Folder($path);
626                $Folder->delete();
627
628                ini_set('include_path', $_includePath);
629        }
630
631/**
632 * test convertSlash()
633 *
634 * @return void
635 * @access public
636 */
637        function testConvertSlash() {
638                $result = convertSlash('\path\to\location\\');
639                $expected = '\path\to\location\\';
640                $this->assertEqual($result, $expected);
641
642                $result = convertSlash('/path/to/location/');
643                $expected = 'path_to_location';
644                $this->assertEqual($result, $expected);
645        }
646
647/**
648 * test debug()
649 *
650 * @return void
651 * @access public
652 */
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);
661
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);
669        }
670
671/**
672 * test pr()
673 *
674 * @return void
675 * @access public
676 */
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);
683
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);
689        }
690
691/**
692 * test params()
693 *
694 * @return void
695 * @access public
696 */
697        function testParams() {
698                $this->assertNull(params('weekend'));
699                $this->assertNull(params(array()));
700                $this->assertEqual(params(array('weekend')), array('weekend'));
701
702                $nested = array(array('weekend'));
703                $this->assertEqual(params($nested), array('weekend'));
704
705                $multiple = array(array('weekend'), 'jean-luc', 'godard');
706                $this->assertEqual(params($multiple), $multiple);
707        }
708
709/**
710 * test stripslashes_deep()
711 *
712 * @return void
713 * @access public
714 */
715        function testStripslashesDeep() {
716                $this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
717
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');
723
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")
731                                ),
732                        'g' => 'te\\st'
733                        );
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")
741                                ),
742                        'g' => 'test'
743                        );
744                $this->assertEqual(stripslashes_deep($nested), $expected);
745        }
746
747/**
748 * test stripslashes_deep() with magic_quotes_sybase on
749 *
750 * @return void
751 * @access public
752 */
753        function testStripslashesDeepSybase() {
754                $this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
755
756                $this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
757
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")
765                                ),
766                        'g' => "te'''''st"
767                        );
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")
775                                ),
776                        'g' => "te'''st"
777                        );
778                $this->assertEqual(stripslashes_deep($nested), $expected);
779        }
780
781/**
782 * test ife()
783 *
784 * @return void
785 * @access public
786 */
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');
793
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');
799        }
800
801/**
802 * test pluginSplit
803 *
804 * @return void
805 */
806        function testPluginSplit() {
807                $result = pluginSplit('Something.else');
808                $this->assertEqual($result, array('Something', 'else'));
809
810                $result = pluginSplit('Something.else.more.dots');
811                $this->assertEqual($result, array('Something', 'else.more.dots'));
812
813                $result = pluginSplit('Somethingelse');
814                $this->assertEqual($result, array(null, 'Somethingelse'));
815
816                $result = pluginSplit('Something.else', true);
817                $this->assertEqual($result, array('Something.', 'else'));
818
819                $result = pluginSplit('Something.else.more.dots', true);
820                $this->assertEqual($result, array('Something.', 'else.more.dots'));
821
822                $result = pluginSplit('Post', false, 'Blog');
823                $this->assertEqual($result, array('Blog', 'Post'));
824
825                $result = pluginSplit('Blog.Post', false, 'Ultimate');
826                $this->assertEqual($result, array('Blog', 'Post'));
827        }
828}
Note: See TracBrowser for help on using the repository browser.