PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/trunk/tests/Zend/Application/Module/BootstrapTest.php

http://firephp.googlecode.com/
PHP | 237 lines | 168 code | 20 blank | 49 comment | 6 complexity | 594bdef4ab57298ebd5c8372b655a287 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Application
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: BootstrapTest.php 23772 2011-02-28 21:35:29Z ralph $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Module_BootstrapTest::main');
  24. }
  25. /**
  26. * Zend_Loader_Autoloader
  27. */
  28. require_once 'Zend/Loader/Autoloader.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Application
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Application
  36. */
  37. class Zend_Application_Module_BootstrapTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. public function setUp()
  45. {
  46. // Store original autoloaders
  47. $this->loaders = spl_autoload_functions();
  48. if (!is_array($this->loaders)) {
  49. // spl_autoload_functions does not return empty array when no
  50. // autoloaders registered...
  51. $this->loaders = array();
  52. }
  53. Zend_Loader_Autoloader::resetInstance();
  54. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  55. $this->application = new Zend_Application('testing');
  56. Zend_Controller_Front::getInstance()->resetInstance();
  57. }
  58. public function tearDown()
  59. {
  60. // Restore original autoloaders
  61. $loaders = spl_autoload_functions();
  62. foreach ($loaders as $loader) {
  63. spl_autoload_unregister($loader);
  64. }
  65. foreach ($this->loaders as $loader) {
  66. spl_autoload_register($loader);
  67. }
  68. // Reset autoloader instance so it doesn't affect other tests
  69. Zend_Loader_Autoloader::resetInstance();
  70. }
  71. public function testConstructorShouldInitializeModuleResourceLoaderWithModulePrefix()
  72. {
  73. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  74. $bootstrap = new ZfModule_Bootstrap($this->application);
  75. $module = $bootstrap->getModuleName();
  76. $loader = $bootstrap->getResourceLoader();
  77. $this->assertNotNull($loader, "resource loader is unexpectedly NULL");
  78. $this->assertEquals($module, $loader->getNamespace());
  79. }
  80. public function testConstructorShouldAcceptResourceLoaderInOptions()
  81. {
  82. $loader = new Zend_Loader_Autoloader_Resource(array(
  83. 'namespace' => 'Foo',
  84. 'basePath' => dirname(__FILE__),
  85. ));
  86. $this->application->setOptions(array('resourceLoader' => $loader));
  87. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  88. $bootstrap = new ZfModule_Bootstrap($this->application);
  89. $this->assertSame($loader, $bootstrap->getResourceLoader(), var_export($bootstrap->getOptions(), 1));
  90. }
  91. public function testModuleNameShouldBeFirstSegmentOfClassName()
  92. {
  93. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  94. $bootstrap = new ZfModule_Bootstrap($this->application);
  95. $this->assertEquals('ZfModule', $bootstrap->getModuleName());
  96. }
  97. public function testShouldPullModuleNamespacedOptionsWhenPresent()
  98. {
  99. $options = array(
  100. 'foo' => 'bar',
  101. 'ZfModule' => array(
  102. 'foo' => 'baz',
  103. )
  104. );
  105. $this->application->setOptions($options);
  106. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  107. $bootstrap = new ZfModule_Bootstrap($this->application);
  108. $this->assertEquals('baz', $bootstrap->foo);
  109. }
  110. /**
  111. * @group ZF-6545
  112. */
  113. public function testFrontControllerPluginResourceShouldBeRegistered()
  114. {
  115. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  116. $bootstrap = new ZfModule_Bootstrap($this->application);
  117. $this->assertTrue($bootstrap->hasPluginResource('FrontController'));
  118. }
  119. /**
  120. * @group ZF-6545
  121. */
  122. public function testFrontControllerStateRemainsSameIfNoOptionsPassedToModuleBootstrap()
  123. {
  124. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  125. $this->application->setOptions(array(
  126. 'resources' => array(
  127. 'frontController' => array(
  128. 'baseUrl' => '/foo',
  129. 'controllerDirectory' => dirname(__FILE__),
  130. ),
  131. ),
  132. 'bootstrap' => array(
  133. 'path' => dirname(__FILE__) . '/../_files/ZfAppBootstrap.php',
  134. 'class' => 'ZfAppBootstrap',
  135. ),
  136. 'ZfModule' => array(
  137. 'resources' => array(
  138. 'FrontController' => array(),
  139. ),
  140. ),
  141. ));
  142. $appBootstrap = $this->application->getBootstrap();
  143. $appBootstrap->bootstrap('FrontController');
  144. $front = $appBootstrap->getResource('FrontController');
  145. $bootstrap = new ZfModule_Bootstrap($appBootstrap);
  146. $bootstrap->bootstrap('FrontController');
  147. $test = $bootstrap->getResource('FrontController');
  148. $this->assertSame($front, $test);
  149. $this->assertEquals('/foo', $test->getBaseUrl());
  150. $this->assertEquals(dirname(__FILE__), $test->getControllerDirectory('default'));
  151. }
  152. /**
  153. * @group ZF-6545
  154. */
  155. public function testModuleBootstrapsShouldNotAcceptModuleResourceInOrderToPreventRecursion()
  156. {
  157. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  158. $this->application->setOptions(array(
  159. 'resources' => array(
  160. 'modules' => array(),
  161. 'frontController' => array(
  162. 'baseUrl' => '/foo',
  163. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  164. ),
  165. ),
  166. 'bootstrap' => array(
  167. 'path' => dirname(__FILE__) . '/../_files/ZfAppBootstrap.php',
  168. 'class' => 'ZfAppBootstrap',
  169. )
  170. ));
  171. $appBootstrap = $this->application->getBootstrap();
  172. $appBootstrap->bootstrap('Modules');
  173. $modules = $appBootstrap->getResource('Modules');
  174. foreach ($modules as $module => $bootstrap) {
  175. if ($module == 'default') {
  176. // "default" module gets lumped in, and is not a Module_Bootstrap
  177. continue;
  178. }
  179. $resources = $bootstrap->getPluginResourceNames();
  180. $this->assertFalse($bootstrap->hasPluginResource('Modules'));
  181. }
  182. }
  183. /**
  184. * @group ZF-6567
  185. */
  186. public function testModuleBootstrapShouldInheritApplicationBootstrapPluginPaths()
  187. {
  188. require_once dirname(__FILE__) . '/../_files/ZfModuleBootstrap.php';
  189. $this->application->setOptions(array(
  190. 'resources' => array(
  191. 'modules' => array(),
  192. 'frontController' => array(
  193. 'baseUrl' => '/foo',
  194. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  195. ),
  196. ),
  197. 'pluginPaths' => array(
  198. 'ZfModuleBootstrap_Resource' => dirname(__FILE__),
  199. ),
  200. 'bootstrap' => array(
  201. 'path' => dirname(__FILE__) . '/../_files/ZfAppBootstrap.php',
  202. 'class' => 'ZfAppBootstrap',
  203. )
  204. ));
  205. $appBootstrap = $this->application->getBootstrap();
  206. $appBootstrap->bootstrap('Modules');
  207. $modules = $appBootstrap->getResource('Modules');
  208. foreach ($modules as $bootstrap) {
  209. $loader = $bootstrap->getPluginLoader();
  210. $paths = $loader->getPaths();
  211. $this->assertTrue(array_key_exists('ZfModuleBootstrap_Resource_', $paths));
  212. }
  213. }
  214. }
  215. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Module_BootstrapTest::main') {
  216. Zend_Application_Module_BootstrapTest::main();
  217. }