Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16591 anikendra 1
<?php
2
/**
3
 * AppTest file.
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.Test.Case.Core
15
 * @since         CakePHP(tm) v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
/**
20
 * AppTest class
21
 *
22
 * @package       Cake.Test.Case.Core
23
 */
24
class AppTest extends CakeTestCase {
25
 
26
/**
27
 * tearDown method
28
 *
29
 * @return void
30
 */
31
	public function tearDown() {
32
		parent::tearDown();
33
		CakePlugin::unload();
34
	}
35
 
36
/**
37
 * testBuild method
38
 *
39
 * @return void
40
 */
41
	public function testBuild() {
42
		$old = App::path('Model');
43
		$expected = array(
44
			APP . 'Model' . DS
45
		);
46
		$this->assertEquals($expected, $old);
47
 
48
		App::build(array('Model' => array('/path/to/models/')));
49
		$new = App::path('Model');
50
		$expected = array(
51
			'/path/to/models/',
52
			APP . 'Model' . DS
53
		);
54
		$this->assertEquals($expected, $new);
55
 
56
		App::build();
57
		App::build(array('Model' => array('/path/to/models/')), App::PREPEND);
58
		$new = App::path('Model');
59
		$expected = array(
60
			'/path/to/models/',
61
			APP . 'Model' . DS
62
		);
63
		$this->assertEquals($expected, $new);
64
 
65
		App::build();
66
		App::build(array('Model' => array('/path/to/models/')), App::APPEND);
67
		$new = App::path('Model');
68
		$expected = array(
69
			APP . 'Model' . DS,
70
			'/path/to/models/'
71
		);
72
		$this->assertEquals($expected, $new);
73
 
74
		App::build();
75
		App::build(array(
76
			'Model' => array('/path/to/models/'),
77
			'Controller' => array('/path/to/controllers/'),
78
		), App::APPEND);
79
		$new = App::path('Model');
80
		$expected = array(
81
			APP . 'Model' . DS,
82
			'/path/to/models/'
83
		);
84
		$this->assertEquals($expected, $new);
85
		$new = App::path('Controller');
86
		$expected = array(
87
			APP . 'Controller' . DS,
88
			'/path/to/controllers/'
89
		);
90
		$this->assertEquals($expected, $new);
91
 
92
		App::build(); //reset defaults
93
		$defaults = App::path('Model');
94
		$this->assertEquals($old, $defaults);
95
	}
96
 
97
/**
98
 * tests that it is possible to set up paths using the CakePHP 1.3 notation for them (models, behaviors, controllers...)
99
 *
100
 * @return void
101
 */
102
	public function testCompatibleBuild() {
103
		$old = App::path('models');
104
		$expected = array(
105
			APP . 'Model' . DS
106
		);
107
		$this->assertEquals($expected, $old);
108
 
109
		App::build(array('models' => array('/path/to/models/')));
110
 
111
		$new = App::path('models');
112
 
113
		$expected = array(
114
			'/path/to/models/',
115
			APP . 'Model' . DS
116
		);
117
		$this->assertEquals($expected, $new);
118
		$this->assertEquals($expected, App::path('Model'));
119
 
120
		App::build(array('datasources' => array('/path/to/datasources/')));
121
		$expected = array(
122
			'/path/to/datasources/',
123
			APP . 'Model' . DS . 'Datasource' . DS
124
		);
125
		$result = App::path('datasources');
126
		$this->assertEquals($expected, $result);
127
		$this->assertEquals($expected, App::path('Model/Datasource'));
128
 
129
		App::build(array('behaviors' => array('/path/to/behaviors/')));
130
		$expected = array(
131
			'/path/to/behaviors/',
132
			APP . 'Model' . DS . 'Behavior' . DS
133
		);
134
		$result = App::path('behaviors');
135
		$this->assertEquals($expected, $result);
136
		$this->assertEquals($expected, App::path('Model/Behavior'));
137
 
138
		App::build(array('controllers' => array('/path/to/controllers/')));
139
		$expected = array(
140
			'/path/to/controllers/',
141
			APP . 'Controller' . DS
142
		);
143
		$result = App::path('controllers');
144
		$this->assertEquals($expected, $result);
145
		$this->assertEquals($expected, App::path('Controller'));
146
 
147
		App::build(array('components' => array('/path/to/components/')));
148
		$expected = array(
149
			'/path/to/components/',
150
			APP . 'Controller' . DS . 'Component' . DS
151
		);
152
		$result = App::path('components');
153
		$this->assertEquals($expected, $result);
154
		$this->assertEquals($expected, App::path('Controller/Component'));
155
 
156
		App::build(array('views' => array('/path/to/views/')));
157
		$expected = array(
158
			'/path/to/views/',
159
			APP . 'View' . DS
160
		);
161
		$result = App::path('views');
162
		$this->assertEquals($expected, $result);
163
		$this->assertEquals($expected, App::path('View'));
164
 
165
		App::build(array('helpers' => array('/path/to/helpers/')));
166
		$expected = array(
167
			'/path/to/helpers/',
168
			APP . 'View' . DS . 'Helper' . DS
169
		);
170
		$result = App::path('helpers');
171
		$this->assertEquals($expected, $result);
172
		$this->assertEquals($expected, App::path('View/Helper'));
173
 
174
		App::build(array('shells' => array('/path/to/shells/')));
175
		$expected = array(
176
			'/path/to/shells/',
177
			APP . 'Console' . DS . 'Command' . DS
178
		);
179
		$result = App::path('shells');
180
		$this->assertEquals($expected, $result);
181
		$this->assertEquals($expected, App::path('Console/Command'));
182
 
183
		App::build(); //reset defaults
184
		$defaults = App::path('Model');
185
		$this->assertEquals($old, $defaults);
186
	}
187
 
188
/**
189
 * test package build() with App::REGISTER.
190
 *
191
 * @return void
192
 */
193
	public function testBuildPackage() {
194
		$pluginPaths = array(
195
			'/foo/bar',
196
			APP . 'Plugin' . DS,
197
			dirname(dirname(CAKE)) . DS . 'plugins' . DS
198
		);
199
		App::build(array(
200
			'Plugin' => array(
201
				'/foo/bar'
202
			)
203
		));
204
		$result = App::path('Plugin');
205
		$this->assertEquals($pluginPaths, $result);
206
 
207
		$paths = App::path('Service');
208
		$this->assertEquals(array(), $paths);
209
 
210
		App::build(array(
211
			'Service' => array(
212
				'%s' . 'Service' . DS,
213
			),
214
		), App::REGISTER);
215
 
216
		$expected = array(
217
			APP . 'Service' . DS,
218
		);
219
		$result = App::path('Service');
220
		$this->assertEquals($expected, $result);
221
 
222
		//Ensure new paths registered for other packages are not affected
223
		$result = App::path('Plugin');
224
		$this->assertEquals($pluginPaths, $result);
225
 
226
		App::build();
227
		$paths = App::path('Service');
228
		$this->assertEquals(array(), $paths);
229
	}
230
 
231
/**
232
 * test path() with a plugin.
233
 *
234
 * @return void
235
 */
236
	public function testPathWithPlugins() {
237
		$basepath = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
238
		App::build(array(
239
			'Plugin' => array($basepath),
240
		));
241
		CakePlugin::load('TestPlugin');
242
 
243
		$result = App::path('Vendor', 'TestPlugin');
244
		$this->assertEquals($basepath . 'TestPlugin' . DS . 'Vendor' . DS, $result[0]);
245
	}
246
 
247
/**
248
 * testBuildWithReset method
249
 *
250
 * @return void
251
 */
252
	public function testBuildWithReset() {
253
		$old = App::path('Model');
254
		$expected = array(
255
			APP . 'Model' . DS
256
		);
257
		$this->assertEquals($expected, $old);
258
 
259
		App::build(array('Model' => array('/path/to/models/')), App::RESET);
260
 
261
		$new = App::path('Model');
262
 
263
		$expected = array(
264
			'/path/to/models/'
265
		);
266
		$this->assertEquals($expected, $new);
267
 
268
		App::build(); //reset defaults
269
		$defaults = App::path('Model');
270
		$this->assertEquals($old, $defaults);
271
	}
272
 
273
/**
274
 * testCore method
275
 *
276
 * @return void
277
 */
278
	public function testCore() {
279
		$model = App::core('Model');
280
		$this->assertEquals(array(CAKE . 'Model' . DS), $model);
281
 
282
		$view = App::core('View');
283
		$this->assertEquals(array(CAKE . 'View' . DS), $view);
284
 
285
		$controller = App::core('Controller');
286
		$this->assertEquals(array(CAKE . 'Controller' . DS), $controller);
287
 
288
		$component = App::core('Controller/Component');
289
		$this->assertEquals(array(CAKE . 'Controller' . DS . 'Component' . DS), str_replace('/', DS, $component));
290
 
291
		$auth = App::core('Controller/Component/Auth');
292
		$this->assertEquals(array(CAKE . 'Controller' . DS . 'Component' . DS . 'Auth' . DS), str_replace('/', DS, $auth));
293
 
294
		$datasource = App::core('Model/Datasource');
295
		$this->assertEquals(array(CAKE . 'Model' . DS . 'Datasource' . DS), str_replace('/', DS, $datasource));
296
	}
297
 
298
/**
299
 * testListObjects method
300
 *
301
 * @return void
302
 */
303
	public function testListObjects() {
304
		$result = App::objects('class', CAKE . 'Routing', false);
305
		$this->assertTrue(in_array('Dispatcher', $result));
306
		$this->assertTrue(in_array('Router', $result));
307
 
308
		App::build(array(
309
			'Model/Behavior' => App::core('Model/Behavior'),
310
			'Controller' => App::core('Controller'),
311
			'Controller/Component' => App::core('Controller/Component'),
312
			'View' => App::core('View'),
313
			'Model' => App::core('Model'),
314
			'View/Helper' => App::core('View/Helper'),
315
		), App::RESET);
316
		$result = App::objects('behavior', null, false);
317
		$this->assertTrue(in_array('TreeBehavior', $result));
318
		$result = App::objects('Model/Behavior', null, false);
319
		$this->assertTrue(in_array('TreeBehavior', $result));
320
 
321
		$result = App::objects('component', null, false);
322
		$this->assertTrue(in_array('AuthComponent', $result));
323
		$result = App::objects('Controller/Component', null, false);
324
		$this->assertTrue(in_array('AuthComponent', $result));
325
 
326
		$result = App::objects('view', null, false);
327
		$this->assertTrue(in_array('MediaView', $result));
328
		$result = App::objects('View', null, false);
329
		$this->assertTrue(in_array('MediaView', $result));
330
 
331
		$result = App::objects('helper', null, false);
332
		$this->assertTrue(in_array('HtmlHelper', $result));
333
		$result = App::objects('View/Helper', null, false);
334
		$this->assertTrue(in_array('HtmlHelper', $result));
335
 
336
		$result = App::objects('model', null, false);
337
		$this->assertTrue(in_array('AcoAction', $result));
338
		$result = App::objects('Model', null, false);
339
		$this->assertTrue(in_array('AcoAction', $result));
340
 
341
		$result = App::objects('file');
342
		$this->assertFalse($result);
343
 
344
		$result = App::objects('file', 'non_existing_configure');
345
		$expected = array();
346
		$this->assertEquals($expected, $result);
347
 
348
		$result = App::objects('NonExistingType');
349
		$this->assertSame(array(), $result);
350
 
351
		App::build(array(
352
			'plugins' => array(
353
				CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS
354
			)
355
		));
356
		$result = App::objects('plugin', null, false);
357
		$this->assertTrue(in_array('Cache', $result));
358
		$this->assertTrue(in_array('Log', $result));
359
 
360
		App::build();
361
	}
362
 
363
/**
364
 * Make sure that .svn and friends are excluded from App::objects('plugin')
365
 *
366
 * @return void
367
 */
368
	public function testListObjectsIgnoreDotDirectories() {
369
		$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
370
 
371
		$this->skipIf(!is_writable($path), $path . ' is not writable.');
372
 
373
		App::build(array(
374
			'plugins' => array($path)
375
		), App::RESET);
376
		mkdir($path . '.svn');
377
		$result = App::objects('plugin', null, false);
378
		rmdir($path . '.svn');
379
 
380
		$this->assertNotContains('.svn', $result);
381
	}
382
 
383
/**
384
 * Tests listing objects within a plugin
385
 *
386
 * @return void
387
 */
388
	public function testListObjectsInPlugin() {
389
		App::build(array(
390
			'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
391
			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
392
		), App::RESET);
393
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
394
 
395
		$result = App::objects('TestPlugin.model');
396
		$this->assertTrue(in_array('TestPluginPost', $result));
397
		$result = App::objects('TestPlugin.Model');
398
		$this->assertTrue(in_array('TestPluginPost', $result));
399
 
400
		$result = App::objects('TestPlugin.behavior');
401
		$this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));
402
		$result = App::objects('TestPlugin.Model/Behavior');
403
		$this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));
404
 
405
		$result = App::objects('TestPlugin.helper');
406
		$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
407
		$this->assertEquals($expected, $result);
408
		$result = App::objects('TestPlugin.View/Helper');
409
		$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
410
		$this->assertEquals($expected, $result);
411
 
412
		$result = App::objects('TestPlugin.component');
413
		$this->assertTrue(in_array('OtherComponent', $result));
414
		$result = App::objects('TestPlugin.Controller/Component');
415
		$this->assertTrue(in_array('OtherComponent', $result));
416
 
417
		$result = App::objects('TestPluginTwo.behavior');
418
		$this->assertSame(array(), $result);
419
		$result = App::objects('TestPluginTwo.Model/Behavior');
420
		$this->assertSame(array(), $result);
421
 
422
		$result = App::objects('model', null, false);
423
		$this->assertTrue(in_array('Comment', $result));
424
		$this->assertTrue(in_array('Post', $result));
425
 
426
		$result = App::objects('Model', null, false);
427
		$this->assertTrue(in_array('Comment', $result));
428
		$this->assertTrue(in_array('Post', $result));
429
 
430
		App::build();
431
	}
432
 
433
/**
434
 * test that themePath can find paths for themes.
435
 *
436
 * @return void
437
 */
438
	public function testThemePath() {
439
		App::build(array(
440
			'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
441
		));
442
		$path = App::themePath('test_theme');
443
		$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
444
		$this->assertEquals($expected, $path);
445
 
446
		$path = App::themePath('TestTheme');
447
		$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
448
		$this->assertEquals($expected, $path);
449
 
450
		App::build();
451
	}
452
 
453
/**
454
 * testClassLoading method
455
 *
456
 * @return void
457
 */
458
	public function testClassLoading() {
459
		$file = App::import('Model', 'Model', false);
460
		$this->assertTrue($file);
461
		$this->assertTrue(class_exists('Model'));
462
 
463
		$file = App::import('Controller', 'Controller', false);
464
		$this->assertTrue($file);
465
		$this->assertTrue(class_exists('Controller'));
466
 
467
		$file = App::import('Component', 'Auth', false);
468
		$this->assertTrue($file);
469
		$this->assertTrue(class_exists('AuthComponent'));
470
 
471
		$file = App::import('Shell', 'Shell', false);
472
		$this->assertTrue($file);
473
		$this->assertTrue(class_exists('Shell'));
474
 
475
		$file = App::import('Configure', 'PhpReader');
476
		$this->assertTrue($file);
477
		$this->assertTrue(class_exists('PhpReader'));
478
 
479
		$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
480
		$this->assertFalse($file);
481
 
482
		$file = App::import('Model', 'AppModel', false);
483
		$this->assertTrue($file);
484
		$this->assertTrue(class_exists('AppModel'));
485
 
486
		$file = App::import('WrongType', null, true, array(), '');
487
		$this->assertFalse($file);
488
 
489
		$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
490
		$this->assertFalse($file);
491
 
492
		$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
493
		$this->assertFalse($file);
494
 
495
		if (!class_exists('AppController', false)) {
496
			$classes = array_flip(get_declared_classes());
497
 
498
			$this->assertFalse(isset($classes['PagesController']));
499
			$this->assertFalse(isset($classes['AppController']));
500
 
501
			$file = App::import('Controller', 'Pages');
502
			$this->assertTrue($file);
503
			$this->assertTrue(class_exists('PagesController'));
504
 
505
			$classes = array_flip(get_declared_classes());
506
 
507
			$this->assertTrue(isset($classes['PagesController']));
508
			$this->assertTrue(isset($classes['AppController']));
509
 
510
			$file = App::import('Behavior', 'Containable');
511
			$this->assertTrue($file);
512
			$this->assertTrue(class_exists('ContainableBehavior'));
513
 
514
			$file = App::import('Component', 'RequestHandler');
515
			$this->assertTrue($file);
516
			$this->assertTrue(class_exists('RequestHandlerComponent'));
517
 
518
			$file = App::import('Helper', 'Form');
519
			$this->assertTrue($file);
520
			$this->assertTrue(class_exists('FormHelper'));
521
 
522
			$file = App::import('Model', 'NonExistingModel');
523
			$this->assertFalse($file);
524
 
525
			$file = App::import('Datasource', 'DboSource');
526
			$this->assertTrue($file);
527
			$this->assertTrue(class_exists('DboSource'));
528
		}
529
		App::build();
530
	}
531
 
532
/**
533
 * test import() with plugins
534
 *
535
 * @return void
536
 */
537
	public function testPluginImporting() {
538
		App::build(array(
539
			'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
540
			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
541
		));
542
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
543
 
544
		$result = App::import('Controller', 'TestPlugin.Tests');
545
		$this->assertTrue($result);
546
		$this->assertTrue(class_exists('TestPluginAppController'));
547
		$this->assertTrue(class_exists('TestsController'));
548
 
549
		$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
550
		$this->assertTrue($result);
551
		$this->assertTrue(class_exists('TestPluginLibrary'));
552
 
553
		$result = App::import('Lib', 'Library');
554
		$this->assertTrue($result);
555
		$this->assertTrue(class_exists('Library'));
556
 
557
		$result = App::import('Helper', 'TestPlugin.OtherHelper');
558
		$this->assertTrue($result);
559
		$this->assertTrue(class_exists('OtherHelperHelper'));
560
 
561
		$result = App::import('Helper', 'TestPlugin.TestPluginApp');
562
		$this->assertTrue($result);
563
		$this->assertTrue(class_exists('TestPluginAppHelper'));
564
 
565
		$result = App::import('Datasource', 'TestPlugin.TestSource');
566
		$this->assertTrue($result);
567
		$this->assertTrue(class_exists('TestSource'));
568
 
569
		App::uses('ExampleExample', 'TestPlugin.Vendor/Example');
570
		$this->assertTrue(class_exists('ExampleExample'));
571
 
572
		App::build();
573
	}
574
 
575
/**
576
 * test that building helper paths actually works.
577
 *
578
 * @return void
579
 * @link https://cakephp.lighthouseapp.com/projects/42648/tickets/410
580
 */
581
	public function testImportingHelpersFromAlternatePaths() {
582
		$this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
583
		App::build(array(
584
			'View/Helper' => array(
585
				CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Helper' . DS
586
			)
587
		));
588
		$this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
589
		App::import('Helper', 'Banana');
590
		$this->assertTrue(class_exists('BananaHelper', false), 'BananaHelper was not loaded.');
591
 
592
		App::build();
593
	}
594
 
595
/**
596
 * testFileLoading method
597
 *
598
 * @return void
599
 */
600
	public function testFileLoading() {
601
		$file = App::import('File', 'RealFile', false, array(), CAKE . 'Config' . DS . 'config.php');
602
		$this->assertTrue($file);
603
 
604
		$file = App::import('File', 'NoFile', false, array(), CAKE . 'Config' . DS . 'cake' . DS . 'config.php');
605
		$this->assertFalse($file);
606
	}
607
 
608
/**
609
 * testFileLoadingWithArray method
610
 *
611
 * @return void
612
 */
613
	public function testFileLoadingWithArray() {
614
		$type = array(
615
			'type' => 'File',
616
			'name' => 'SomeName',
617
			'parent' => false,
618
			'file' => CAKE . DS . 'Config' . DS . 'config.php'
619
		);
620
		$file = App::import($type);
621
		$this->assertTrue($file);
622
 
623
		$type = array(
624
			'type' => 'File',
625
			'name' => 'NoFile',
626
			'parent' => false,
627
			'file' => CAKE . 'Config' . DS . 'cake' . DS . 'config.php'
628
		);
629
		$file = App::import($type);
630
		$this->assertFalse($file);
631
	}
632
 
633
/**
634
 * testFileLoadingReturnValue method
635
 *
636
 * @return void
637
 */
638
	public function testFileLoadingReturnValue() {
639
		$file = App::import('File', 'Name', false, array(), CAKE . 'Config' . DS . 'config.php', true);
640
		$this->assertTrue(!empty($file));
641
 
642
		$this->assertTrue(isset($file['Cake.version']));
643
 
644
		$type = array(
645
			'type' => 'File',
646
			'name' => 'OtherName',
647
			'parent' => false,
648
			'file' => CAKE . 'Config' . DS . 'config.php', 'return' => true
649
		);
650
		$file = App::import($type);
651
		$this->assertTrue(!empty($file));
652
 
653
		$this->assertTrue(isset($file['Cake.version']));
654
	}
655
 
656
/**
657
 * testLoadingWithSearch method
658
 *
659
 * @return void
660
 */
661
	public function testLoadingWithSearch() {
662
		$file = App::import('File', 'NewName', false, array(CAKE . 'Config' . DS), 'config.php');
663
		$this->assertTrue($file);
664
 
665
		$file = App::import('File', 'AnotherNewName', false, array(CAKE), 'config.php');
666
		$this->assertFalse($file);
667
	}
668
 
669
/**
670
 * testLoadingWithSearchArray method
671
 *
672
 * @return void
673
 */
674
	public function testLoadingWithSearchArray() {
675
		$type = array(
676
			'type' => 'File',
677
			'name' => 'RandomName',
678
			'parent' => false,
679
			'file' => 'config.php',
680
			'search' => array(CAKE . 'Config' . DS)
681
		);
682
		$file = App::import($type);
683
		$this->assertTrue($file);
684
 
685
		$type = array(
686
			'type' => 'File',
687
			'name' => 'AnotherRandomName',
688
			'parent' => false,
689
			'file' => 'config.php',
690
			'search' => array(CAKE)
691
		);
692
		$file = App::import($type);
693
		$this->assertFalse($file);
694
	}
695
 
696
/**
697
 * testMultipleLoading method
698
 *
699
 * @return void
700
 */
701
	public function testMultipleLoading() {
702
		if (class_exists('PersisterOne', false) || class_exists('PersisterTwo', false)) {
703
			$this->markTestSkipped('Cannot test loading of classes that exist.');
704
		}
705
		App::build(array(
706
			'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
707
		));
708
		$toLoad = array('PersisterOne', 'PersisterTwo');
709
		$load = App::import('Model', $toLoad);
710
		$this->assertTrue($load);
711
 
712
		$classes = array_flip(get_declared_classes());
713
 
714
		$this->assertTrue(isset($classes['PersisterOne']));
715
		$this->assertTrue(isset($classes['PersisterTwo']));
716
 
717
		$load = App::import('Model', array('PersisterOne', 'SomeNotFoundClass', 'PersisterTwo'));
718
		$this->assertFalse($load);
719
	}
720
 
721
	public function testLoadingVendor() {
722
		App::build(array(
723
			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
724
			'vendors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS),
725
		), App::RESET);
726
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
727
 
728
		ob_start();
729
		$result = App::import('Vendor', 'css/TestAsset', array('ext' => 'css'));
730
		$text = ob_get_clean();
731
		$this->assertTrue($result);
732
		$this->assertEquals('/* this is the test asset css file */', trim($text));
733
 
734
		$result = App::import('Vendor', 'TestPlugin.sample/SamplePlugin');
735
		$this->assertTrue($result);
736
		$this->assertTrue(class_exists('SamplePluginClassTestName'));
737
 
738
		$result = App::import('Vendor', 'sample/ConfigureTestVendorSample');
739
		$this->assertTrue($result);
740
		$this->assertTrue(class_exists('ConfigureTestVendorSample'));
741
 
742
		ob_start();
743
		$result = App::import('Vendor', 'SomeNameInSubfolder', array('file' => 'somename/some.name.php'));
744
		$text = ob_get_clean();
745
		$this->assertTrue($result);
746
		$this->assertEquals('This is a file with dot in file name', $text);
747
 
748
		ob_start();
749
		$result = App::import('Vendor', 'TestHello', array('file' => 'Test' . DS . 'hello.php'));
750
		$text = ob_get_clean();
751
		$this->assertTrue($result);
752
		$this->assertEquals('This is the hello.php file in Test directory', $text);
753
 
754
		ob_start();
755
		$result = App::import('Vendor', 'MyTest', array('file' => 'Test' . DS . 'MyTest.php'));
756
		$text = ob_get_clean();
757
		$this->assertTrue($result);
758
		$this->assertEquals('This is the MyTest.php file', $text);
759
 
760
		ob_start();
761
		$result = App::import('Vendor', 'Welcome');
762
		$text = ob_get_clean();
763
		$this->assertTrue($result);
764
		$this->assertEquals('This is the welcome.php file in vendors directory', $text);
765
 
766
		ob_start();
767
		$result = App::import('Vendor', 'TestPlugin.Welcome');
768
		$text = ob_get_clean();
769
		$this->assertTrue($result);
770
		$this->assertEquals('This is the welcome.php file in test_plugin/vendors directory', $text);
771
	}
772
 
773
/**
774
 * Tests that the automatic class loader will also find in "libs" folder for both
775
 * app and plugins if it does not find the class in other configured paths
776
 *
777
 * @return void
778
 */
779
	public function testLoadClassInLibs() {
780
		App::build(array(
781
			'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
782
			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
783
		), App::RESET);
784
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
785
 
786
		$this->assertFalse(class_exists('CustomLibClass', false));
787
		App::uses('CustomLibClass', 'TestPlugin.Custom/Package');
788
		$this->assertTrue(class_exists('CustomLibClass'));
789
 
790
		$this->assertFalse(class_exists('TestUtilityClass', false));
791
		App::uses('TestUtilityClass', 'Utility');
792
		$this->assertTrue(class_exists('TestUtilityClass'));
793
	}
794
 
795
/**
796
 * Tests that App::location() returns the defined path for a class
797
 *
798
 * @return void
799
 */
800
	public function testClassLocation() {
801
		App::uses('MyCustomClass', 'MyPackage/Name');
802
		$this->assertEquals('MyPackage/Name', App::location('MyCustomClass'));
803
	}
804
 
805
/**
806
 * Test that paths() works.
807
 *
808
 * @return void
809
 */
810
	public function testPaths() {
811
		$result = App::paths();
812
		$this->assertArrayHasKey('Plugin', $result);
813
		$this->assertArrayHasKey('Controller', $result);
814
		$this->assertArrayHasKey('Controller/Component', $result);
815
	}
816
 
817
/**
818
 * Proves that it is possible to load plugin libraries in top
819
 * level Lib dir for plugins
820
 *
821
 * @return void
822
 */
823
	public function testPluginLibClasses() {
824
		App::build(array(
825
			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
826
		), App::RESET);
827
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
828
		$this->assertFalse(class_exists('TestPluginOtherLibrary', false));
829
		App::uses('TestPluginOtherLibrary', 'TestPlugin.Lib');
830
		$this->assertTrue(class_exists('TestPluginOtherLibrary'));
831
	}
832
}