comparison cake/tests/cases/libs/configure.test.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * ConfigureTest file
4 *
5 * Holds several tests
6 *
7 * PHP versions 4 and 5
8 *
9 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
10 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
11 *
12 * Licensed under The Open Group Test Suite License
13 * Redistributions of files must retain the above copyright notice.
14 *
15 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
16 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
17 * @package cake
18 * @subpackage cake.tests.cases.libs
19 * @since CakePHP(tm) v 1.2.0.5432
20 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
21 */
22 App::import('Core', 'Configure');
23
24 /**
25 * ConfigureTest
26 *
27 * @package cake
28 * @subpackage cake.tests.cases.libs
29 */
30 class ConfigureTest extends CakeTestCase {
31
32 /**
33 * setUp method
34 *
35 * @access public
36 * @return void
37 */
38 function setUp() {
39 $this->_cacheDisable = Configure::read('Cache.disable');
40 $this->_debug = Configure::read('debug');
41
42 Configure::write('Cache.disable', true);
43 }
44
45 /**
46 * endTest
47 *
48 * @access public
49 * @return void
50 */
51 function endTest() {
52 App::build();
53 }
54
55 /**
56 * tearDown method
57 *
58 * @access public
59 * @return void
60 */
61 function tearDown() {
62 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths')) {
63 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths');
64 }
65 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map')) {
66 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map');
67 }
68 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map')) {
69 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map');
70 }
71 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map')) {
72 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map');
73 }
74 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'test.config.php')) {
75 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'test.config.php');
76 }
77 if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'test.php')) {
78 unlink(TMP . 'cache' . DS . 'persistent' . DS . 'test.php');
79 }
80 Configure::write('debug', $this->_debug);
81 Configure::write('Cache.disable', $this->_cacheDisable);
82 }
83
84 /**
85 * testRead method
86 *
87 * @access public
88 * @return void
89 */
90 function testRead() {
91 $expected = 'ok';
92 Configure::write('level1.level2.level3_1', $expected);
93 Configure::write('level1.level2.level3_2', 'something_else');
94 $result = Configure::read('level1.level2.level3_1');
95 $this->assertEqual($expected, $result);
96
97 $result = Configure::read('level1.level2.level3_2');
98 $this->assertEqual($result, 'something_else');
99
100 $result = Configure::read('debug');
101 $this->assertTrue($result >= 0);
102 }
103
104 /**
105 * testWrite method
106 *
107 * @access public
108 * @return void
109 */
110 function testWrite() {
111 $writeResult = Configure::write('SomeName.someKey', 'myvalue');
112 $this->assertTrue($writeResult);
113 $result = Configure::read('SomeName.someKey');
114 $this->assertEqual($result, 'myvalue');
115
116 $writeResult = Configure::write('SomeName.someKey', null);
117 $this->assertTrue($writeResult);
118 $result = Configure::read('SomeName.someKey');
119 $this->assertEqual($result, null);
120
121 $expected = array('One' => array('Two' => array('Three' => array('Four' => array('Five' => 'cool')))));
122 $writeResult = Configure::write('Key', $expected);
123 $this->assertTrue($writeResult);
124
125 $result = Configure::read('Key');
126 $this->assertEqual($expected, $result);
127
128 $result = Configure::read('Key.One');
129 $this->assertEqual($expected['One'], $result);
130
131 $result = Configure::read('Key.One.Two');
132 $this->assertEqual($expected['One']['Two'], $result);
133
134 $result = Configure::read('Key.One.Two.Three.Four.Five');
135 $this->assertEqual('cool', $result);
136 }
137
138 /**
139 * testSetErrorReporting Level
140 *
141 * @return void
142 */
143 function testSetErrorReportingLevel() {
144 Configure::write('log', false);
145
146 Configure::write('debug', 0);
147 $result = ini_get('error_reporting');
148 $this->assertEqual($result, 0);
149
150 Configure::write('debug', 2);
151 $result = ini_get('error_reporting');
152 $this->assertEqual($result, E_ALL & ~E_DEPRECATED);
153
154 $result = ini_get('display_errors');
155 $this->assertEqual($result, 1);
156
157 Configure::write('debug', 0);
158 $result = ini_get('error_reporting');
159 $this->assertEqual($result, 0);
160 }
161
162 /**
163 * test that log and debug configure values interact well.
164 *
165 * @return void
166 */
167 function testInteractionOfDebugAndLog() {
168 Configure::write('log', false);
169
170 Configure::write('debug', 0);
171 $this->assertEqual(ini_get('error_reporting'), 0);
172 $this->assertEqual(ini_get('display_errors'), 0);
173
174 Configure::write('log', E_WARNING);
175 Configure::write('debug', 0);
176 $this->assertEqual(ini_get('error_reporting'), E_WARNING);
177 $this->assertEqual(ini_get('display_errors'), 0);
178
179 Configure::write('debug', 2);
180 $this->assertEqual(ini_get('error_reporting'), E_ALL & ~E_DEPRECATED);
181 $this->assertEqual(ini_get('display_errors'), 1);
182
183 Configure::write('debug', 0);
184 Configure::write('log', false);
185 $this->assertEqual(ini_get('error_reporting'), 0);
186 $this->assertEqual(ini_get('display_errors'), 0);
187 }
188
189 /**
190 * testDelete method
191 *
192 * @access public
193 * @return void
194 */
195 function testDelete() {
196 Configure::write('SomeName.someKey', 'myvalue');
197 $result = Configure::read('SomeName.someKey');
198 $this->assertEqual($result, 'myvalue');
199
200 Configure::delete('SomeName.someKey');
201 $result = Configure::read('SomeName.someKey');
202 $this->assertTrue($result === null);
203
204 Configure::write('SomeName', array('someKey' => 'myvalue', 'otherKey' => 'otherValue'));
205
206 $result = Configure::read('SomeName.someKey');
207 $this->assertEqual($result, 'myvalue');
208
209 $result = Configure::read('SomeName.otherKey');
210 $this->assertEqual($result, 'otherValue');
211
212 Configure::delete('SomeName');
213
214 $result = Configure::read('SomeName.someKey');
215 $this->assertTrue($result === null);
216
217 $result = Configure::read('SomeName.otherKey');
218 $this->assertTrue($result === null);
219 }
220
221 /**
222 * testLoad method
223 *
224 * @access public
225 * @return void
226 */
227 function testLoad() {
228 $result = Configure::load('non_existing_configuration_file');
229 $this->assertFalse($result);
230
231 $result = Configure::load('config');
232 $this->assertTrue($result);
233
234 $result = Configure::load('../../index');
235 $this->assertFalse($result);
236 }
237
238 /**
239 * testLoad method
240 *
241 * @access public
242 * @return void
243 */
244 function testLoadPlugin() {
245 App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true);
246 $result = Configure::load('test_plugin.load');
247 $this->assertTrue($result);
248 $expected = '/test_app/plugins/test_plugin/config/load.php';
249 $config = Configure::read('plugin_load');
250 $this->assertEqual($config, $expected);
251
252 $result = Configure::load('test_plugin.more.load');
253 $this->assertTrue($result);
254 $expected = '/test_app/plugins/test_plugin/config/more.load.php';
255 $config = Configure::read('plugin_more_load');
256 $this->assertEqual($config, $expected);
257 }
258
259 /**
260 * testStore method
261 *
262 * @access public
263 * @return void
264 */
265 function testStoreAndLoad() {
266 Configure::write('Cache.disable', false);
267
268 $expected = array('data' => 'value with backslash \, \'singlequote\' and "doublequotes"');
269 Configure::store('SomeExample', 'test', $expected);
270
271 Configure::load('test');
272 $config = Configure::read('SomeExample');
273 $this->assertEqual($config, $expected);
274
275 $expected = array(
276 'data' => array('first' => 'value with backslash \, \'singlequote\' and "doublequotes"', 'second' => 'value2'),
277 'data2' => 'value'
278 );
279 Configure::store('AnotherExample', 'test_config', $expected);
280
281 Configure::load('test_config');
282 $config = Configure::read('AnotherExample');
283 $this->assertEqual($config, $expected);
284 }
285
286 /**
287 * testVersion method
288 *
289 * @access public
290 * @return void
291 */
292 function testVersion() {
293 $result = Configure::version();
294 $this->assertTrue(version_compare($result, '1.2', '>='));
295 }
296 }
297
298 /**
299 * AppImportTest class
300 *
301 * @package cake
302 * @subpackage cake.tests.cases.libs
303 */
304 class AppImportTest extends CakeTestCase {
305
306 /**
307 * testBuild method
308 *
309 * @access public
310 * @return void
311 */
312 function testBuild() {
313 $old = App::path('models');
314 $expected = array(
315 APP . 'models' . DS,
316 APP,
317 ROOT . DS . LIBS . 'model' . DS
318 );
319 $this->assertEqual($expected, $old);
320
321 App::build(array('models' => array('/path/to/models/')));
322
323 $new = App::path('models');
324
325 $expected = array(
326 '/path/to/models/',
327 APP . 'models' . DS,
328 APP,
329 ROOT . DS . LIBS . 'model' . DS
330 );
331 $this->assertEqual($expected, $new);
332
333 App::build(); //reset defaults
334 $defaults = App::path('models');
335 $this->assertEqual($old, $defaults);
336 }
337
338 /**
339 * testBuildWithReset method
340 *
341 * @access public
342 * @return void
343 */
344 function testBuildWithReset() {
345 $old = App::path('models');
346 $expected = array(
347 APP . 'models' . DS,
348 APP,
349 ROOT . DS . LIBS . 'model' . DS
350 );
351 $this->assertEqual($expected, $old);
352
353 App::build(array('models' => array('/path/to/models/')), true);
354
355 $new = App::path('models');
356
357 $expected = array(
358 '/path/to/models/'
359 );
360 $this->assertEqual($expected, $new);
361
362 App::build(); //reset defaults
363 $defaults = App::path('models');
364 $this->assertEqual($old, $defaults);
365 }
366
367 /**
368 * testCore method
369 *
370 * @access public
371 * @return void
372 */
373 function testCore() {
374 $model = App::core('models');
375 $this->assertEqual(array(ROOT . DS . LIBS . 'model' . DS), $model);
376
377 $view = App::core('views');
378 $this->assertEqual(array(ROOT . DS . LIBS . 'view' . DS), $view);
379
380 $controller = App::core('controllers');
381 $this->assertEqual(array(ROOT . DS . LIBS . 'controller' . DS), $controller);
382
383 }
384
385 /**
386 * testListObjects method
387 *
388 * @access public
389 * @return void
390 */
391 function testListObjects() {
392 $result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs');
393 $this->assertTrue(in_array('Xml', $result));
394 $this->assertTrue(in_array('Cache', $result));
395 $this->assertTrue(in_array('HttpSocket', $result));
396
397 $result = App::objects('behavior');
398 $this->assertTrue(in_array('Tree', $result));
399
400 $result = App::objects('controller');
401 $this->assertTrue(in_array('Pages', $result));
402
403 $result = App::objects('component');
404 $this->assertTrue(in_array('Auth', $result));
405
406 $result = App::objects('view');
407 $this->assertTrue(in_array('Media', $result));
408
409 $result = App::objects('helper');
410 $this->assertTrue(in_array('Html', $result));
411
412 $result = App::objects('model');
413 $notExpected = array('AppModel', 'ModelBehavior', 'ConnectionManager', 'DbAcl', 'Model', 'CakeSchema');
414 foreach ($notExpected as $class) {
415 $this->assertFalse(in_array($class, $result));
416 }
417
418 $result = App::objects('file');
419 $this->assertFalse($result);
420
421 $result = App::objects('file', 'non_existing_configure');
422 $expected = array();
423 $this->assertEqual($result, $expected);
424
425 $result = App::objects('NonExistingType');
426 $this->assertFalse($result);
427
428 App::build(array(
429 'plugins' => array(
430 TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS
431 )
432 ));
433 $result = App::objects('plugin', null, false);
434 $this->assertTrue(in_array('Cache', $result));
435 $this->assertTrue(in_array('Log', $result));
436
437 App::build();
438 }
439
440 /**
441 * test that pluginPath can find paths for plugins.
442 *
443 * @return void
444 */
445 function testPluginPath() {
446 App::build(array(
447 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
448 ));
449 $path = App::pluginPath('test_plugin');
450 $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
451 $this->assertEqual($path, $expected);
452
453 $path = App::pluginPath('TestPlugin');
454 $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
455 $this->assertEqual($path, $expected);
456
457 $path = App::pluginPath('TestPluginTwo');
458 $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS;
459 $this->assertEqual($path, $expected);
460 App::build();
461 }
462
463 /**
464 * test that pluginPath can find paths for plugins.
465 *
466 * @return void
467 */
468 function testThemePath() {
469 App::build(array(
470 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
471 ));
472 $path = App::themePath('test_theme');
473 $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
474 $this->assertEqual($path, $expected);
475
476 $path = App::themePath('TestTheme');
477 $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
478 $this->assertEqual($path, $expected);
479
480 App::build();
481 }
482
483 /**
484 * testClassLoading method
485 *
486 * @access public
487 * @return void
488 */
489 function testClassLoading() {
490 $file = App::import();
491 $this->assertTrue($file);
492
493 $file = App::import('Model', 'Model', false);
494 $this->assertTrue($file);
495 $this->assertTrue(class_exists('Model'));
496
497 $file = App::import('Controller', 'Controller', false);
498 $this->assertTrue($file);
499 $this->assertTrue(class_exists('Controller'));
500
501 $file = App::import('Component', 'Component', false);
502 $this->assertTrue($file);
503 $this->assertTrue(class_exists('Component'));
504
505 $file = App::import('Shell', 'Shell', false);
506 $this->assertTrue($file);
507 $this->assertTrue(class_exists('Shell'));
508
509 $file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
510 $this->assertFalse($file);
511
512 $file = App::import('Model', 'AppModel', false);
513 $this->assertTrue($file);
514 $this->assertTrue(class_exists('AppModel'));
515
516 $file = App::import('WrongType', null, true, array(), '');
517 $this->assertTrue($file);
518
519 $file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
520 $this->assertFalse($file);
521
522 $file = App::import('Core', 'NonExistingPlugin.NonExistingModel', false);
523 $this->assertFalse($file);
524
525 $file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
526 $this->assertFalse($file);
527
528 $file = App::import('Core', array('NonExistingPlugin.NonExistingModel'), false);
529 $this->assertFalse($file);
530
531 $file = App::import('Core', array('NonExistingPlugin.NonExistingModel.AnotherChild'), false);
532 $this->assertFalse($file);
533
534 if (!class_exists('AppController')) {
535 $classes = array_flip(get_declared_classes());
536
537 if (PHP5) {
538 $this->assertFalse(isset($classes['PagesController']));
539 $this->assertFalse(isset($classes['AppController']));
540 } else {
541 $this->assertFalse(isset($classes['pagescontroller']));
542 $this->assertFalse(isset($classes['appcontroller']));
543 }
544
545 $file = App::import('Controller', 'Pages');
546 $this->assertTrue($file);
547 $this->assertTrue(class_exists('PagesController'));
548
549 $classes = array_flip(get_declared_classes());
550
551 if (PHP5) {
552 $this->assertTrue(isset($classes['PagesController']));
553 $this->assertTrue(isset($classes['AppController']));
554 } else {
555 $this->assertTrue(isset($classes['pagescontroller']));
556 $this->assertTrue(isset($classes['appcontroller']));
557 }
558
559 $file = App::import('Behavior', 'Containable');
560 $this->assertTrue($file);
561 $this->assertTrue(class_exists('ContainableBehavior'));
562
563 $file = App::import('Component', 'RequestHandler');
564 $this->assertTrue($file);
565 $this->assertTrue(class_exists('RequestHandlerComponent'));
566
567 $file = App::import('Helper', 'Form');
568 $this->assertTrue($file);
569 $this->assertTrue(class_exists('FormHelper'));
570
571 $file = App::import('Model', 'NonExistingModel');
572 $this->assertFalse($file);
573
574 $file = App::import('Datasource', 'DboSource');
575 $this->assertTrue($file);
576 $this->assertTrue(class_exists('DboSource'));
577 }
578 App::build();
579 }
580
581 /**
582 * test import() with plugins
583 *
584 * @return void
585 */
586 function testPluginImporting() {
587 App::build(array(
588 'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
589 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
590 ));
591
592 $result = App::import('Controller', 'TestPlugin.Tests');
593 $this->assertTrue($result);
594 $this->assertTrue(class_exists('TestPluginAppController'));
595 $this->assertTrue(class_exists('TestsController'));
596
597 $result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
598 $this->assertTrue($result);
599 $this->assertTrue(class_exists('TestPluginLibrary'));
600
601 $result = App::import('Lib', 'Library');
602 $this->assertTrue($result);
603 $this->assertTrue(class_exists('Library'));
604
605 $result = App::import('Helper', 'TestPlugin.OtherHelper');
606 $this->assertTrue($result);
607 $this->assertTrue(class_exists('OtherHelperHelper'));
608
609 $result = App::import('Helper', 'TestPlugin.TestPluginApp');
610 $this->assertTrue($result);
611 $this->assertTrue(class_exists('TestPluginAppHelper'));
612
613 $result = App::import('Datasource', 'TestPlugin.TestSource');
614 $this->assertTrue($result);
615 $this->assertTrue(class_exists('TestSource'));
616
617 App::build();
618 }
619
620 /**
621 * test that building helper paths actually works.
622 *
623 * @return void
624 * @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
625 */
626 function testImportingHelpersFromAlternatePaths() {
627 App::build();
628 $this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
629 App::import('Helper', 'Banana');
630 $this->assertFalse(class_exists('BananaHelper'), 'BananaHelper was not found because the path does not exist.');
631
632 App::build(array(
633 'helpers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'helpers' . DS)
634 ));
635 App::build(array('vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH)));
636 $this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
637 App::import('Helper', 'Banana');
638 $this->assertTrue(class_exists('BananaHelper'), 'BananaHelper was not loaded.');
639
640 App::build();
641 }
642
643 /**
644 * testFileLoading method
645 *
646 * @access public
647 * @return void
648 */
649 function testFileLoading () {
650 $file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
651 $this->assertTrue($file);
652
653 $file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
654 $this->assertFalse($file);
655 }
656 // import($type = null, $name = null, $parent = true, $file = null, $search = array(), $return = false) {
657
658 /**
659 * testFileLoadingWithArray method
660 *
661 * @access public
662 * @return void
663 */
664 function testFileLoadingWithArray() {
665 $type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
666 'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
667 $file = App::import($type);
668 $this->assertTrue($file);
669
670 $type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
671 'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
672 $file = App::import($type);
673 $this->assertFalse($file);
674 }
675
676 /**
677 * testFileLoadingReturnValue method
678 *
679 * @access public
680 * @return void
681 */
682 function testFileLoadingReturnValue () {
683 $file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
684 $this->assertTrue($file);
685
686 $this->assertTrue(isset($file['Cake.version']));
687
688 $type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
689 'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
690 $file = App::import($type);
691 $this->assertTrue($file);
692
693 $this->assertTrue(isset($file['Cake.version']));
694 }
695
696 /**
697 * testLoadingWithSearch method
698 *
699 * @access public
700 * @return void
701 */
702 function testLoadingWithSearch () {
703 $file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
704 $this->assertTrue($file);
705
706 $file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
707 $this->assertFalse($file);
708 }
709
710 /**
711 * testLoadingWithSearchArray method
712 *
713 * @access public
714 * @return void
715 */
716 function testLoadingWithSearchArray () {
717 $type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
718 $file = App::import($type);
719 $this->assertTrue($file);
720
721 $type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
722 $file = App::import($type);
723 $this->assertFalse($file);
724 }
725
726 /**
727 * testMultipleLoading method
728 *
729 * @access public
730 * @return void
731 */
732 function testMultipleLoading() {
733 $toLoad = array('I18n', 'CakeSocket');
734
735 $classes = array_flip(get_declared_classes());
736 $this->assertFalse(isset($classes['i18n']));
737 $this->assertFalse(isset($classes['CakeSocket']));
738
739 $load = App::import($toLoad);
740 $this->assertTrue($load);
741
742 $classes = array_flip(get_declared_classes());
743
744 if (PHP5) {
745 $this->assertTrue(isset($classes['I18n']));
746 } else {
747 $this->assertTrue(isset($classes['i18n']));
748 }
749
750 $load = App::import(array('I18n', 'SomeNotFoundClass', 'CakeSocket'));
751 $this->assertFalse($load);
752
753 $load = App::import($toLoad);
754 $this->assertTrue($load);
755 }
756
757 /**
758 * This test only works if you have plugins/my_plugin set up.
759 * plugins/my_plugin/models/my_plugin.php and other_model.php
760 */
761
762 /*
763 function testMultipleLoadingByType() {
764 $classes = array_flip(get_declared_classes());
765 $this->assertFalse(isset($classes['OtherPlugin']));
766 $this->assertFalse(isset($classes['MyPlugin']));
767
768
769 $load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
770 $this->assertTrue($load);
771
772 $classes = array_flip(get_declared_classes());
773 $this->assertTrue(isset($classes['OtherPlugin']));
774 $this->assertTrue(isset($classes['MyPlugin']));
775 }
776 */
777 function testLoadingVendor() {
778 App::build(array(
779 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
780 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
781 ), true);
782
783 ob_start();
784 $result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
785 $text = ob_get_clean();
786 $this->assertTrue($result);
787 $this->assertEqual($text, 'this is the test plugin asset css file');
788
789 ob_start();
790 $result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
791 $text = ob_get_clean();
792 $this->assertTrue($result);
793 $this->assertEqual($text, 'this is the test asset css file');
794
795 $result = App::import('Vendor', 'TestPlugin.SamplePlugin');
796 $this->assertTrue($result);
797 $this->assertTrue(class_exists('SamplePluginClassTestName'));
798
799 $result = App::import('Vendor', 'ConfigureTestVendorSample');
800 $this->assertTrue($result);
801 $this->assertTrue(class_exists('ConfigureTestVendorSample'));
802
803 ob_start();
804 $result = App::import('Vendor', 'SomeName', array('file' => 'some.name.php'));
805 $text = ob_get_clean();
806 $this->assertTrue($result);
807 $this->assertEqual($text, 'This is a file with dot in file name');
808
809 ob_start();
810 $result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
811 $text = ob_get_clean();
812 $this->assertTrue($result);
813 $this->assertEqual($text, 'This is the hello.php file in Test directory');
814
815 ob_start();
816 $result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
817 $text = ob_get_clean();
818 $this->assertTrue($result);
819 $this->assertEqual($text, 'This is the MyTest.php file');
820
821 ob_start();
822 $result = App::import('Vendor', 'Welcome');
823 $text = ob_get_clean();
824 $this->assertTrue($result);
825 $this->assertEqual($text, 'This is the welcome.php file in vendors directory');
826
827 ob_start();
828 $result = App::import('Vendor', 'TestPlugin.Welcome');
829 $text = ob_get_clean();
830 $this->assertTrue($result);
831 $this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
832 }
833 }