PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

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