PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://skygames.googlecode.com/
PHP | 191 lines | 113 code | 31 blank | 47 comment | 7 complexity | b6951776831fe83a8bb807dbf7593a45 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, CC-BY-SA-3.0
  1. <?php
  2. /* SVN FILE: $Id: loader.test.php 6311 2008-01-02 06:33:52Z phpnut $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc.
  12. * 1785 E. Sahara Avenue, Suite 490-204
  13. * Las Vegas, Nevada 89104
  14. *
  15. * Licensed under The Open Group Test Suite License
  16. * Redistributions of files must retain the above copyright notice.
  17. *
  18. * @filesource
  19. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
  20. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  21. * @package cake.tests
  22. * @subpackage cake.tests.cases.libs
  23. * @since CakePHP(tm) v 1.2.0.5432
  24. * @version $Revision: 6311 $
  25. * @modifiedby $LastChangedBy: phpnut $
  26. * @lastmodified $Date: 2008-01-02 00:33:52 -0600 (Wed, 02 Jan 2008) $
  27. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  28. */
  29. uses('configure');
  30. class AppImportTest extends UnitTestCase {
  31. function testClassLoading() {
  32. $file = App::import();
  33. $this->assertTrue($file);
  34. $file = App::import('Core', 'Model', false);
  35. $this->assertTrue($file);
  36. $file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
  37. $this->assertFalse($file);
  38. $file = App::import('Model', 'AppModel', false);
  39. $this->assertTrue($file);
  40. if (!class_exists('AppController')) {
  41. $classes = array_flip(get_declared_classes());
  42. if (PHP5) {
  43. $this->assertFalse(isset($classes['PagesController']));
  44. $this->assertFalse(isset($classes['AppController']));
  45. } else {
  46. $this->assertFalse(isset($classes['pagescontroller']));
  47. $this->assertFalse(isset($classes['appcontroller']));
  48. }
  49. $file = App::import('Controller', 'Pages');
  50. $this->assertTrue($file);
  51. $classes = array_flip(get_declared_classes());
  52. if (PHP5) {
  53. $this->assertTrue(isset($classes['PagesController']));
  54. $this->assertTrue(isset($classes['AppController']));
  55. } else {
  56. $this->assertTrue(isset($classes['pagescontroller']));
  57. $this->assertTrue(isset($classes['appcontroller']));
  58. }
  59. }
  60. }
  61. function testFileLoading () {
  62. $file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
  63. $this->assertTrue($file);
  64. $file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
  65. $this->assertFalse($file);
  66. }
  67. // import($type = null, $name = null, $parent = true, $file = null, $search = array(), $return = false) {
  68. function testFileLoadingWithArray() {
  69. $type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
  70. 'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
  71. $file = App::import($type);
  72. $this->assertTrue($file);
  73. $type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
  74. 'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
  75. $file = App::import($type);
  76. $this->assertFalse($file);
  77. }
  78. function testFileLoadingReturnValue () {
  79. $file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
  80. $this->assertTrue($file);
  81. $this->assertTrue(isset($file['Cake.version']));
  82. $type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
  83. 'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
  84. $file = App::import($type);
  85. $this->assertTrue($file);
  86. $this->assertTrue(isset($file['Cake.version']));
  87. }
  88. function testLoadingWithSearch () {
  89. $file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
  90. $this->assertTrue($file);
  91. $file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
  92. $this->assertFalse($file);
  93. }
  94. function testLoadingWithSearchArray () {
  95. $type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
  96. $file = App::import($type);
  97. $this->assertTrue($file);
  98. $type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
  99. $file = App::import($type);
  100. $this->assertFalse($file);
  101. }
  102. function testMultipleLoading() {
  103. $toLoad = array('I18n', 'Socket');
  104. $classes = array_flip(get_declared_classes());
  105. $this->assertFalse(isset($classes['i18n']));
  106. $this->assertFalse(isset($classes['Socket']));
  107. $load = App::import($toLoad);
  108. $this->assertTrue($load);
  109. $classes = array_flip(get_declared_classes());
  110. if (PHP5) {
  111. $this->assertTrue(isset($classes['I18n']));
  112. } else {
  113. $this->assertTrue(isset($classes['i18n']));
  114. }
  115. $load = App::import(array('I18n', 'SomeNotFoundClass', 'Socket'));
  116. $this->assertFalse($load);
  117. $load = App::import($toLoad);
  118. $this->assertTrue($load);
  119. }
  120. /**
  121. * This test only works if you have plugins/my_plugin set up.
  122. * plugins/my_plugin/models/my_plugin.php and other_model.php
  123. */
  124. /*
  125. function testMultipleLoadingByType() {
  126. $classes = array_flip(get_declared_classes());
  127. $this->assertFalse(isset($classes['OtherPlugin']));
  128. $this->assertFalse(isset($classes['MyPlugin']));
  129. $load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
  130. $this->assertTrue($load);
  131. $classes = array_flip(get_declared_classes());
  132. $this->assertTrue(isset($classes['OtherPlugin']));
  133. $this->assertTrue(isset($classes['MyPlugin']));
  134. }
  135. */
  136. function testLoadingVendor() {
  137. Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
  138. Configure::write('vendorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS));
  139. ob_start();
  140. $result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
  141. $text = ob_get_clean();
  142. $this->assertTrue($result);
  143. $this->assertEqual($text, 'this is the test plugin asset css file');
  144. ob_start();
  145. $result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
  146. $text = ob_get_clean();
  147. $this->assertTrue($result);
  148. $this->assertEqual($text, 'this is the test asset css file');
  149. $result = App::import('Vendor', 'TestPlugin.SamplePlugin');
  150. $this->assertTrue($result);
  151. $this->assertTrue(class_exists('SamplePluginClassTestName'));
  152. $result = App::import('Vendor', 'Sample');
  153. $this->assertTrue($result);
  154. $this->assertTrue(class_exists('SampleClassTestName'));
  155. }
  156. }
  157. ?>