/lib/Cake/Test/Case/Core/AppTest.php

https://github.com/gustavor/lore · PHP · 780 lines · 536 code · 125 blank · 119 comment · 3 complexity · 7fdf979824a998e38839d9807fdc3d72 MD5 · raw file

  1. <?php
  2. /**
  3. * AppTest class
  4. *
  5. * @package Cake.Test.Case.Core
  6. */
  7. class AppTest extends CakeTestCase {
  8. /**
  9. * tearDown method
  10. *
  11. * @return void
  12. */
  13. public function tearDown() {
  14. CakePlugin::unload();
  15. }
  16. /**
  17. * testBuild method
  18. *
  19. * @return void
  20. */
  21. public function testBuild() {
  22. $old = App::path('Model');
  23. $expected = array(
  24. APP . 'Model' . DS,
  25. APP . 'models' . DS
  26. );
  27. $this->assertEqual($expected, $old);
  28. App::build(array('Model' => array('/path/to/models/')));
  29. $new = App::path('Model');
  30. $expected = array(
  31. '/path/to/models/',
  32. APP . 'Model' . DS,
  33. APP . 'models' . DS
  34. );
  35. $this->assertEqual($expected, $new);
  36. App::build();
  37. App::build(array('Model' => array('/path/to/models/')), App::PREPEND);
  38. $new = App::path('Model');
  39. $expected = array(
  40. '/path/to/models/',
  41. APP . 'Model' . DS,
  42. APP . 'models' . DS
  43. );
  44. $this->assertEqual($expected, $new);
  45. App::build();
  46. App::build(array('Model' => array('/path/to/models/')), App::APPEND);
  47. $new = App::path('Model');
  48. $expected = array(
  49. APP . 'Model' . DS,
  50. APP . 'models' . DS,
  51. '/path/to/models/'
  52. );
  53. $this->assertEqual($expected, $new);
  54. App::build();
  55. App::build(array(
  56. 'Model' => array('/path/to/models/'),
  57. 'Controller' => array('/path/to/controllers/'),
  58. ), App::APPEND);
  59. $new = App::path('Model');
  60. $expected = array(
  61. APP . 'Model' . DS,
  62. APP . 'models' . DS,
  63. '/path/to/models/'
  64. );
  65. $this->assertEqual($expected, $new);
  66. $new = App::path('Controller');
  67. $expected = array(
  68. APP . 'Controller' . DS,
  69. APP . 'controllers' . DS,
  70. '/path/to/controllers/'
  71. );
  72. $this->assertEqual($expected, $new);
  73. App::build(); //reset defaults
  74. $defaults = App::path('Model');
  75. $this->assertEqual($old, $defaults);
  76. }
  77. /**
  78. * tests that it is possible to set up paths using the cake 1.3 notation for them (models, behaviors, controllers...)
  79. *
  80. * @return void
  81. */
  82. public function testCompatibleBuild() {
  83. $old = App::path('models');
  84. $expected = array(
  85. APP . 'Model' . DS,
  86. APP . 'models' . DS
  87. );
  88. $this->assertEqual($expected, $old);
  89. App::build(array('models' => array('/path/to/models/')));
  90. $new = App::path('models');
  91. $expected = array(
  92. '/path/to/models/',
  93. APP . 'Model' . DS,
  94. APP . 'models' . DS
  95. );
  96. $this->assertEqual($expected, $new);
  97. $this->assertEqual($expected, App::path('Model'));
  98. App::build(array('datasources' => array('/path/to/datasources/')));
  99. $expected = array(
  100. '/path/to/datasources/',
  101. APP . 'Model' . DS . 'Datasource' . DS,
  102. APP . 'models' . DS . 'datasources' . DS
  103. );
  104. $result = App::path('datasources');
  105. $this->assertEqual($expected, $result);
  106. $this->assertEqual($expected, App::path('Model/Datasource'));
  107. App::build(array('behaviors' => array('/path/to/behaviors/')));
  108. $expected = array(
  109. '/path/to/behaviors/',
  110. APP . 'Model' . DS . 'Behavior' . DS,
  111. APP . 'models' . DS . 'behaviors' . DS
  112. );
  113. $result = App::path('behaviors');
  114. $this->assertEqual($expected, $result);
  115. $this->assertEqual($expected, App::path('Model/Behavior'));
  116. App::build(array('controllers' => array('/path/to/controllers/')));
  117. $expected = array(
  118. '/path/to/controllers/',
  119. APP . 'Controller' . DS,
  120. APP . 'controllers' . DS
  121. );
  122. $result = App::path('controllers');
  123. $this->assertEqual($expected, $result);
  124. $this->assertEqual($expected, App::path('Controller'));
  125. App::build(array('components' => array('/path/to/components/')));
  126. $expected = array(
  127. '/path/to/components/',
  128. APP . 'Controller' . DS . 'Component' . DS,
  129. APP . 'controllers' . DS . 'components' . DS
  130. );
  131. $result = App::path('components');
  132. $this->assertEqual($expected, $result);
  133. $this->assertEqual($expected, App::path('Controller/Component'));
  134. App::build(array('views' => array('/path/to/views/')));
  135. $expected = array(
  136. '/path/to/views/',
  137. APP . 'View' . DS,
  138. APP . 'views' . DS
  139. );
  140. $result = App::path('views');
  141. $this->assertEqual($expected, $result);
  142. $this->assertEqual($expected, App::path('View'));
  143. App::build(array('helpers' => array('/path/to/helpers/')));
  144. $expected = array(
  145. '/path/to/helpers/',
  146. APP . 'View' . DS . 'Helper' .DS,
  147. APP . 'views' . DS . 'helpers' . DS
  148. );
  149. $result = App::path('helpers');
  150. $this->assertEqual($expected, $result);
  151. $this->assertEqual($expected, App::path('View/Helper'));
  152. App::build(array('shells' => array('/path/to/shells/')));
  153. $expected = array(
  154. '/path/to/shells/',
  155. APP . 'Console' . DS . 'Command' . DS,
  156. APP . 'console' . DS . 'shells' . DS,
  157. );
  158. $result = App::path('shells');
  159. $this->assertEqual($expected, $result);
  160. $this->assertEqual($expected, App::path('Console/Command'));
  161. App::build(); //reset defaults
  162. $defaults = App::path('Model');
  163. $this->assertEqual($old, $defaults);
  164. }
  165. /**
  166. * test path() with a plugin.
  167. *
  168. * @return void
  169. */
  170. public function testPathWithPlugins() {
  171. $basepath = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
  172. App::build(array(
  173. 'Plugin' => array($basepath),
  174. ));
  175. CakePlugin::load('TestPlugin');
  176. $result = App::path('Vendor', 'TestPlugin');
  177. $this->assertEquals($basepath . 'TestPlugin' . DS . 'Vendor' . DS, $result[0]);
  178. }
  179. /**
  180. * testBuildWithReset method
  181. *
  182. * @return void
  183. */
  184. public function testBuildWithReset() {
  185. $old = App::path('Model');
  186. $expected = array(
  187. APP . 'Model' . DS,
  188. APP . 'models' . DS
  189. );
  190. $this->assertEqual($expected, $old);
  191. App::build(array('Model' => array('/path/to/models/')), App::RESET);
  192. $new = App::path('Model');
  193. $expected = array(
  194. '/path/to/models/'
  195. );
  196. $this->assertEqual($expected, $new);
  197. App::build(); //reset defaults
  198. $defaults = App::path('Model');
  199. $this->assertEqual($old, $defaults);
  200. }
  201. /**
  202. * testCore method
  203. *
  204. * @return void
  205. */
  206. public function testCore() {
  207. $model = App::core('Model');
  208. $this->assertEqual(array(CAKE . 'Model' . DS), $model);
  209. $view = App::core('View');
  210. $this->assertEqual(array(CAKE . 'View' . DS), $view);
  211. $controller = App::core('Controller');
  212. $this->assertEqual(array(CAKE . 'Controller' . DS), $controller);
  213. $component = App::core('Controller/Component');
  214. $this->assertEqual(array(CAKE . 'Controller' . DS . 'Component' . DS), str_replace('/', DS, $component));
  215. $auth = App::core('Controller/Component/Auth');
  216. $this->assertEqual(array(CAKE . 'Controller' . DS . 'Component' . DS . 'Auth' . DS), str_replace('/', DS, $auth));
  217. $datasource = App::core('Model/Datasource');
  218. $this->assertEqual(array(CAKE . 'Model' . DS . 'Datasource' . DS), str_replace('/', DS, $datasource));
  219. }
  220. /**
  221. * testListObjects method
  222. *
  223. * @return void
  224. */
  225. public function testListObjects() {
  226. $result = App::objects('class', CAKE . 'Routing', false);
  227. $this->assertTrue(in_array('Dispatcher', $result));
  228. $this->assertTrue(in_array('Router', $result));
  229. App::build(array(
  230. 'Model/Behavior' => App::core('Model/Behavior'),
  231. 'Controller' => App::core('Controller'),
  232. 'Controller/Component' => App::core('Controller/Component'),
  233. 'View' => App::core('View'),
  234. 'Model' => App::core('Model'),
  235. 'View/Helper' => App::core('View/Helper'),
  236. ), App::RESET);
  237. $result = App::objects('behavior', null, false);
  238. $this->assertTrue(in_array('TreeBehavior', $result));
  239. $result = App::objects('Model/Behavior', null, false);
  240. $this->assertTrue(in_array('TreeBehavior', $result));
  241. $result = App::objects('controller', null, false);
  242. $this->assertTrue(in_array('PagesController', $result));
  243. $result = App::objects('Controller', null, false);
  244. $this->assertTrue(in_array('PagesController', $result));
  245. $result = App::objects('component', null, false);
  246. $this->assertTrue(in_array('AuthComponent', $result));
  247. $result = App::objects('Controller/Component', null, false);
  248. $this->assertTrue(in_array('AuthComponent', $result));
  249. $result = App::objects('view', null, false);
  250. $this->assertTrue(in_array('MediaView', $result));
  251. $result = App::objects('View', null, false);
  252. $this->assertTrue(in_array('MediaView', $result));
  253. $result = App::objects('helper', null, false);
  254. $this->assertTrue(in_array('HtmlHelper', $result));
  255. $result = App::objects('View/Helper', null, false);
  256. $this->assertTrue(in_array('HtmlHelper', $result));
  257. $result = App::objects('model', null, false);
  258. $this->assertTrue(in_array('AcoAction', $result));
  259. $result = App::objects('Model', null, false);
  260. $this->assertTrue(in_array('AcoAction', $result));
  261. $result = App::objects('file');
  262. $this->assertFalse($result);
  263. $result = App::objects('file', 'non_existing_configure');
  264. $expected = array();
  265. $this->assertEqual($expected, $result);
  266. $result = App::objects('NonExistingType');
  267. $this->assertEqual($result, array());
  268. App::build(array(
  269. 'plugins' => array(
  270. CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS
  271. )
  272. ));
  273. $result = App::objects('plugin', null, false);
  274. $this->assertTrue(in_array('Cache', $result));
  275. $this->assertTrue(in_array('Log', $result));
  276. App::build();
  277. }
  278. /**
  279. * Make sure that .svn and friends are excluded from App::objects('plugin')
  280. */
  281. public function testListObjectsIgnoreDotDirectories() {
  282. $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
  283. App::build(array(
  284. 'plugins' => array($path)
  285. ), true);
  286. mkdir($path . '.svn');
  287. $result = App::objects('plugin', null, false);
  288. rmdir($path . '.svn');
  289. $this->assertNotContains('.svn', $result);
  290. }
  291. /**
  292. * Tests listing objects within a plugin
  293. *
  294. * @return void
  295. */
  296. public function testListObjectsInPlugin() {
  297. App::build(array(
  298. 'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
  299. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  300. ), true);
  301. CakePlugin::loadAll();
  302. $result = App::objects('TestPlugin.model');
  303. $this->assertTrue(in_array('TestPluginPost', $result));
  304. $result = App::objects('TestPlugin.Model');
  305. $this->assertTrue(in_array('TestPluginPost', $result));
  306. $result = App::objects('TestPlugin.behavior');
  307. $this->assertTrue(in_array('TestPluginPersisterOne', $result));
  308. $result = App::objects('TestPlugin.Model/Behavior');
  309. $this->assertTrue(in_array('TestPluginPersisterOne', $result));
  310. $result = App::objects('TestPlugin.helper');
  311. $expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
  312. $this->assertEquals($expected, $result);
  313. $result = App::objects('TestPlugin.View/Helper');
  314. $expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
  315. $this->assertEquals($expected, $result);
  316. $result = App::objects('TestPlugin.component');
  317. $this->assertTrue(in_array('OtherComponent', $result));
  318. $result = App::objects('TestPlugin.Controller/Component');
  319. $this->assertTrue(in_array('OtherComponent', $result));
  320. $result = App::objects('TestPluginTwo.behavior');
  321. $this->assertEquals($result, array());
  322. $result = App::objects('TestPluginTwo.Model/Behavior');
  323. $this->assertEquals($result, array());
  324. $result = App::objects('model', null, false);
  325. $this->assertTrue(in_array('Comment', $result));
  326. $this->assertTrue(in_array('Post', $result));
  327. $result = App::objects('Model', null, false);
  328. $this->assertTrue(in_array('Comment', $result));
  329. $this->assertTrue(in_array('Post', $result));
  330. App::build();
  331. }
  332. /**
  333. * test that pluginPath can find paths for plugins.
  334. *
  335. * @return void
  336. */
  337. public function testPluginPath() {
  338. App::build(array(
  339. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  340. ));
  341. CakePlugin::loadAll();
  342. $path = App::pluginPath('TestPlugin');
  343. $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS;
  344. $this->assertEqual($path, $expected);
  345. $path = App::pluginPath('TestPluginTwo');
  346. $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPluginTwo' . DS;
  347. $this->assertEqual($path, $expected);
  348. App::build();
  349. }
  350. /**
  351. * test that pluginPath can find paths for plugins.
  352. *
  353. * @return void
  354. */
  355. public function testThemePath() {
  356. App::build(array(
  357. 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
  358. ));
  359. $path = App::themePath('test_theme');
  360. $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
  361. $this->assertEqual($path, $expected);
  362. $path = App::themePath('TestTheme');
  363. $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
  364. $this->assertEqual($path, $expected);
  365. App::build();
  366. }
  367. /**
  368. * testClassLoading method
  369. *
  370. * @return void
  371. */
  372. public function testClassLoading() {
  373. $file = App::import('Model', 'Model', false);
  374. $this->assertTrue($file);
  375. $this->assertTrue(class_exists('Model'));
  376. $file = App::import('Controller', 'Controller', false);
  377. $this->assertTrue($file);
  378. $this->assertTrue(class_exists('Controller'));
  379. $file = App::import('Component', 'Auth', false);
  380. $this->assertTrue($file);
  381. $this->assertTrue(class_exists('AuthComponent'));
  382. $file = App::import('Shell', 'Shell', false);
  383. $this->assertTrue($file);
  384. $this->assertTrue(class_exists('Shell'));
  385. $file = App::import('Configure', 'PhpReader');
  386. $this->assertTrue($file);
  387. $this->assertTrue(class_exists('PhpReader'));
  388. $file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
  389. $this->assertFalse($file);
  390. $file = App::import('Model', 'AppModel', false);
  391. $this->assertTrue($file);
  392. $this->assertTrue(class_exists('AppModel'));
  393. $file = App::import('WrongType', null, true, array(), '');
  394. $this->assertFalse($file);
  395. $file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
  396. $this->assertFalse($file);
  397. $file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
  398. $this->assertFalse($file);
  399. if (!class_exists('AppController', false)) {
  400. $classes = array_flip(get_declared_classes());
  401. $this->assertFalse(isset($classes['PagesController']));
  402. $this->assertFalse(isset($classes['AppController']));
  403. $file = App::import('Controller', 'Pages');
  404. $this->assertTrue($file);
  405. $this->assertTrue(class_exists('PagesController'));
  406. $classes = array_flip(get_declared_classes());
  407. $this->assertTrue(isset($classes['PagesController']));
  408. $this->assertTrue(isset($classes['AppController']));
  409. $file = App::import('Behavior', 'Containable');
  410. $this->assertTrue($file);
  411. $this->assertTrue(class_exists('ContainableBehavior'));
  412. $file = App::import('Component', 'RequestHandler');
  413. $this->assertTrue($file);
  414. $this->assertTrue(class_exists('RequestHandlerComponent'));
  415. $file = App::import('Helper', 'Form');
  416. $this->assertTrue($file);
  417. $this->assertTrue(class_exists('FormHelper'));
  418. $file = App::import('Model', 'NonExistingModel');
  419. $this->assertFalse($file);
  420. $file = App::import('Datasource', 'DboSource');
  421. $this->assertTrue($file);
  422. $this->assertTrue(class_exists('DboSource'));
  423. }
  424. App::build();
  425. }
  426. /**
  427. * test import() with plugins
  428. *
  429. * @return void
  430. */
  431. public function testPluginImporting() {
  432. App::build(array(
  433. 'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
  434. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  435. ));
  436. CakePlugin::loadAll();
  437. $result = App::import('Controller', 'TestPlugin.Tests');
  438. $this->assertTrue($result);
  439. $this->assertTrue(class_exists('TestPluginAppController'));
  440. $this->assertTrue(class_exists('TestsController'));
  441. $result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
  442. $this->assertTrue($result);
  443. $this->assertTrue(class_exists('TestPluginLibrary'));
  444. $result = App::import('Lib', 'Library');
  445. $this->assertTrue($result);
  446. $this->assertTrue(class_exists('Library'));
  447. $result = App::import('Helper', 'TestPlugin.OtherHelper');
  448. $this->assertTrue($result);
  449. $this->assertTrue(class_exists('OtherHelperHelper'));
  450. $result = App::import('Helper', 'TestPlugin.TestPluginApp');
  451. $this->assertTrue($result);
  452. $this->assertTrue(class_exists('TestPluginAppHelper'));
  453. $result = App::import('Datasource', 'TestPlugin.TestSource');
  454. $this->assertTrue($result);
  455. $this->assertTrue(class_exists('TestSource'));
  456. App::build();
  457. }
  458. /**
  459. * test that building helper paths actually works.
  460. *
  461. * @return void
  462. * @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
  463. */
  464. public function testImportingHelpersFromAlternatePaths() {
  465. $this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
  466. App::build(array(
  467. 'View/Helper' => array(
  468. CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Helper' . DS
  469. )
  470. ));
  471. $this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
  472. App::import('Helper', 'Banana');
  473. $this->assertTrue(class_exists('BananaHelper', false), 'BananaHelper was not loaded.');
  474. App::build();
  475. }
  476. /**
  477. * testFileLoading method
  478. *
  479. * @return void
  480. */
  481. public function testFileLoading () {
  482. $file = App::import('File', 'RealFile', false, array(), CAKE . 'Config' . DS . 'config.php');
  483. $this->assertTrue($file);
  484. $file = App::import('File', 'NoFile', false, array(), CAKE . 'Config' . DS . 'cake' . DS . 'config.php');
  485. $this->assertFalse($file);
  486. }
  487. /**
  488. * testFileLoadingWithArray method
  489. *
  490. * @return void
  491. */
  492. public function testFileLoadingWithArray() {
  493. $type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
  494. 'file' => CAKE . DS . 'Config' . DS . 'config.php');
  495. $file = App::import($type);
  496. $this->assertTrue($file);
  497. $type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
  498. 'file' => CAKE . 'Config' . DS . 'cake' . DS . 'config.php');
  499. $file = App::import($type);
  500. $this->assertFalse($file);
  501. }
  502. /**
  503. * testFileLoadingReturnValue method
  504. *
  505. * @return void
  506. */
  507. public function testFileLoadingReturnValue () {
  508. $file = App::import('File', 'Name', false, array(), CAKE . 'Config' . DS . 'config.php', true);
  509. $this->assertTrue(!empty($file));
  510. $this->assertTrue(isset($file['Cake.version']));
  511. $type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
  512. 'file' => CAKE . 'Config' . DS . 'config.php', 'return' => true);
  513. $file = App::import($type);
  514. $this->assertTrue(!empty($file));
  515. $this->assertTrue(isset($file['Cake.version']));
  516. }
  517. /**
  518. * testLoadingWithSearch method
  519. *
  520. * @return void
  521. */
  522. public function testLoadingWithSearch () {
  523. $file = App::import('File', 'NewName', false, array(CAKE . 'Config' . DS), 'config.php');
  524. $this->assertTrue($file);
  525. $file = App::import('File', 'AnotherNewName', false, array(CAKE), 'config.php');
  526. $this->assertFalse($file);
  527. }
  528. /**
  529. * testLoadingWithSearchArray method
  530. *
  531. * @return void
  532. */
  533. public function testLoadingWithSearchArray() {
  534. $type = array(
  535. 'type' => 'File',
  536. 'name' => 'RandomName',
  537. 'parent' => false,
  538. 'file' => 'config.php',
  539. 'search' => array(CAKE . 'Config' . DS)
  540. );
  541. $file = App::import($type);
  542. $this->assertTrue($file);
  543. $type = array(
  544. 'type' => 'File',
  545. 'name' => 'AnotherRandomName',
  546. 'parent' => false,
  547. 'file' => 'config.php',
  548. 'search' => array(CAKE)
  549. );
  550. $file = App::import($type);
  551. $this->assertFalse($file);
  552. }
  553. /**
  554. * testMultipleLoading method
  555. *
  556. * @return void
  557. */
  558. public function testMultipleLoading() {
  559. if (class_exists('PersisterOne', false) || class_exists('PersisterTwo', false)) {
  560. $this->markTestSkipped('Cannot test loading of classes that exist.');
  561. }
  562. App::build(array(
  563. 'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
  564. ));
  565. $toLoad = array('PersisterOne', 'PersisterTwo');
  566. $load = App::import('Model', $toLoad);
  567. $this->assertTrue($load);
  568. $classes = array_flip(get_declared_classes());
  569. $this->assertTrue(isset($classes['PersisterOne']));
  570. $this->assertTrue(isset($classes['PersisterTwo']));
  571. $load = App::import('Model', array('PersisterOne', 'SomeNotFoundClass', 'PersisterTwo'));
  572. $this->assertFalse($load);
  573. }
  574. public function testLoadingVendor() {
  575. App::build(array(
  576. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
  577. 'vendors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor'. DS),
  578. ), App::RESET);
  579. CakePlugin::loadAll();
  580. ob_start();
  581. $result = App::import('Vendor', 'css/TestAsset', array('ext' => 'css'));
  582. $text = ob_get_clean();
  583. $this->assertTrue($result);
  584. $this->assertEqual($text, 'this is the test asset css file');
  585. $result = App::import('Vendor', 'TestPlugin.sample/SamplePlugin');
  586. $this->assertTrue($result);
  587. $this->assertTrue(class_exists('SamplePluginClassTestName'));
  588. $result = App::import('Vendor', 'sample/ConfigureTestVendorSample');
  589. $this->assertTrue($result);
  590. $this->assertTrue(class_exists('ConfigureTestVendorSample'));
  591. ob_start();
  592. $result = App::import('Vendor', 'SomeNameInSubfolder', array('file' => 'somename/some.name.php'));
  593. $text = ob_get_clean();
  594. $this->assertTrue($result);
  595. $this->assertEqual($text, 'This is a file with dot in file name');
  596. ob_start();
  597. $result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
  598. $text = ob_get_clean();
  599. $this->assertTrue($result);
  600. $this->assertEqual($text, 'This is the hello.php file in Test directory');
  601. ob_start();
  602. $result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
  603. $text = ob_get_clean();
  604. $this->assertTrue($result);
  605. $this->assertEqual($text, 'This is the MyTest.php file');
  606. ob_start();
  607. $result = App::import('Vendor', 'Welcome');
  608. $text = ob_get_clean();
  609. $this->assertTrue($result);
  610. $this->assertEqual($text, 'This is the welcome.php file in vendors directory');
  611. ob_start();
  612. $result = App::import('Vendor', 'TestPlugin.Welcome');
  613. $text = ob_get_clean();
  614. $this->assertTrue($result);
  615. $this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
  616. }
  617. /**
  618. * Tests that the automatic class loader will also find in "libs" folder for both
  619. * app and plugins if it does not find the class in other configured paths
  620. *
  621. */
  622. public function testLoadClassInLibs() {
  623. App::build(array(
  624. 'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
  625. 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  626. ), App::RESET);
  627. CakePlugin::loadAll();
  628. $this->assertFalse(class_exists('CustomLibClass', false));
  629. App::uses('CustomLibClass', 'TestPlugin.Custom/Package');
  630. $this->assertTrue(class_exists('CustomLibClass'));
  631. $this->assertFalse(class_exists('TestUtilityClass', false));
  632. App::uses('TestUtilityClass', 'Utility');
  633. $this->assertTrue(class_exists('CustomLibClass'));
  634. }
  635. /**
  636. * Tests that App::location() returns the defined path for a class
  637. *
  638. * @return void
  639. */
  640. public function testClassLocation() {
  641. App::uses('MyCustomClass', 'MyPackage/Name');
  642. $this->assertEquals('MyPackage/Name', App::location('MyCustomClass'));
  643. }
  644. /**
  645. * Test that paths() works.
  646. *
  647. * @return void
  648. */
  649. public function testPaths() {
  650. $result = App::paths();
  651. $this->assertArrayHasKey('Plugin', $result);
  652. $this->assertArrayHasKey('Controller', $result);
  653. $this->assertArrayHasKey('Controller/Component', $result);
  654. }
  655. }