PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/Application/Resource/ModulesTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base
PHP | 217 lines | 139 code | 27 blank | 51 comment | 4 complexity | a78195345a4b4dde2cadec3d1ed1e72b MD5 | raw file
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: ModulesTest.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_ModulesTest::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-2012 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_Resource_ModulesTest 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. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  57. $this->bootstrap = new ZfAppBootstrap($this->application);
  58. $this->front = Zend_Controller_Front::getInstance();
  59. $this->front->resetInstance();
  60. }
  61. public function tearDown()
  62. {
  63. // Restore original autoloaders
  64. $loaders = spl_autoload_functions();
  65. foreach ($loaders as $loader) {
  66. spl_autoload_unregister($loader);
  67. }
  68. foreach ($this->loaders as $loader) {
  69. spl_autoload_register($loader);
  70. }
  71. // Reset autoloader instance so it doesn't affect other tests
  72. Zend_Loader_Autoloader::resetInstance();
  73. }
  74. public function testInitializationTriggersNothingIfNoModulesRegistered()
  75. {
  76. require_once 'Zend/Application/Resource/Modules.php';
  77. $this->bootstrap->registerPluginResource('Frontcontroller', array());
  78. $resource = new Zend_Application_Resource_Modules(array());
  79. $resource->setBootstrap($this->bootstrap);
  80. $resource->init();
  81. $this->assertFalse(isset($this->bootstrap->default));
  82. $this->assertFalse(isset($this->bootstrap->foo));
  83. $this->assertFalse(isset($this->bootstrap->bar));
  84. }
  85. /**
  86. * @group ZF-6803
  87. * @group ZF-7158
  88. */
  89. public function testInitializationTriggersDefaultModuleBootstrapWhenDiffersFromApplicationBootstrap()
  90. {
  91. require_once 'Zend/Application/Resource/Modules.php';
  92. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  93. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  94. ));
  95. $resource = new Zend_Application_Resource_Modules(array());
  96. $resource->setBootstrap($this->bootstrap);
  97. $resource->init();
  98. $this->assertTrue(isset($this->bootstrap->default));
  99. }
  100. public function testInitializationShouldTriggerModuleBootstrapsWhenTheyExist()
  101. {
  102. require_once 'Zend/Application/Resource/Modules.php';
  103. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  104. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  105. ));
  106. $resource = new Zend_Application_Resource_Modules(array());
  107. $resource->setBootstrap($this->bootstrap);
  108. $resource->init();
  109. $this->assertTrue($this->bootstrap->foo, 'foo failed');
  110. $this->assertTrue($this->bootstrap->bar, 'bar failed');
  111. }
  112. /**
  113. * @group ZF-6803
  114. * @group ZF-7158
  115. */
  116. public function testInitializationShouldSkipModulesWithoutBootstraps()
  117. {
  118. require_once 'Zend/Application/Resource/Modules.php';
  119. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  120. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  121. ));
  122. $resource = new Zend_Application_Resource_Modules(array());
  123. $resource->setBootstrap($this->bootstrap);
  124. $resource->init();
  125. $bootstraps = $resource->getExecutedBootstraps();
  126. $this->assertEquals(4, count((array)$bootstraps));
  127. $this->assertArrayHasKey('bar', (array)$bootstraps);
  128. $this->assertArrayHasKey('foo-bar', (array)$bootstraps);
  129. $this->assertArrayHasKey('foo', (array)$bootstraps);
  130. $this->assertArrayHasKey('default', (array)$bootstraps);
  131. }
  132. /**
  133. * @group ZF-6803
  134. * @group ZF-7158
  135. */
  136. public function testShouldReturnExecutedBootstrapsWhenComplete()
  137. {
  138. require_once 'Zend/Application/Resource/Modules.php';
  139. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  140. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  141. ));
  142. $resource = new Zend_Application_Resource_Modules(array());
  143. $resource->setBootstrap($this->bootstrap);
  144. $bootstraps = $resource->init();
  145. $this->assertEquals(4, count((array)$bootstraps));
  146. $this->assertArrayHasKey('bar', (array)$bootstraps);
  147. $this->assertArrayHasKey('foo-bar', (array)$bootstraps);
  148. $this->assertArrayHasKey('foo', (array)$bootstraps);
  149. $this->assertArrayHasKey('default', (array)$bootstraps);
  150. }
  151. public function testBootstrapBootstrapsIsOwnMethod()
  152. {
  153. require_once 'Zend/Application/Resource/Modules.php';
  154. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  155. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  156. ));
  157. $resource = new ZendTest_Application_Resource_ModulesHalf(array());
  158. $resource->setBootstrap($this->bootstrap);
  159. $bootstraps = $resource->init();
  160. $this->assertEquals(3, count((array)$bootstraps));
  161. }
  162. /**
  163. * @group ZF-11548
  164. */
  165. public function testGetExecutedBootstrapsShouldReturnArrayObject()
  166. {
  167. require_once 'Zend/Application/Resource/Modules.php';
  168. $this->bootstrap->registerPluginResource('Frontcontroller', array(
  169. 'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
  170. ));
  171. $resource = new Zend_Application_Resource_Modules(array());
  172. $resource->setBootstrap($this->bootstrap);
  173. $resource->init();
  174. $bootstraps = $resource->getExecutedBootstraps();
  175. $this->assertType('ArrayObject', $bootstraps);
  176. }
  177. }
  178. require_once 'Zend/Application/Resource/Modules.php';
  179. class ZendTest_Application_Resource_ModulesHalf
  180. extends Zend_Application_Resource_Modules
  181. {
  182. protected function bootstrapBootstraps($bootstraps)
  183. {
  184. array_pop($bootstraps);
  185. return parent::bootstrapBootstraps($bootstraps);
  186. }
  187. }
  188. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_ModulesTest::main') {
  189. Zend_Application_Resource_ModulesTest::main();
  190. }