PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/libs/configure.test.php

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