BootstrapAbstractTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Bootstrap_BootstrapAbstractTest::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. /**
  30. * Zend_Loader_Autoloader
  31. */
  32. require_once 'Zend/Loader/Autoloader.php';
  33. /**
  34. * Zend_Application_Resource_ResourceAbstract
  35. */
  36. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Application
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. */
  44. class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework_TestCase
  45. {
  46. public static function main()
  47. {
  48. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. public function setUp()
  52. {
  53. // Store original autoloaders
  54. $this->loaders = spl_autoload_functions();
  55. if (!is_array($this->loaders)) {
  56. // spl_autoload_functions does not return empty array when no
  57. // autoloaders registered...
  58. $this->loaders = array();
  59. }
  60. Zend_Loader_Autoloader::resetInstance();
  61. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  62. $this->application = new Zend_Application('testing');
  63. }
  64. public function tearDown()
  65. {
  66. // Restore original autoloaders
  67. $loaders = spl_autoload_functions();
  68. foreach ($loaders as $loader) {
  69. spl_autoload_unregister($loader);
  70. }
  71. foreach ($this->loaders as $loader) {
  72. spl_autoload_register($loader);
  73. }
  74. }
  75. public function testConstructorShouldPopulateApplication()
  76. {
  77. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  78. $bootstrap = new ZfAppBootstrap($this->application);
  79. $this->assertSame($this->application, $bootstrap->getApplication());
  80. }
  81. public function testConstructorShouldPopulateOptionsFromApplicationObject()
  82. {
  83. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  84. $options = array(
  85. 'foo' => 'bar',
  86. 'bar' => 'baz',
  87. );
  88. $this->application->setOptions($options);
  89. $bootstrap = new ZfAppBootstrap($this->application);
  90. $this->assertSame($options, $bootstrap->getOptions());
  91. }
  92. public function testConstructorShouldAllowPassingAnotherBootstrapObject()
  93. {
  94. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  95. $bootstrap1 = new ZfAppBootstrap($this->application);
  96. $bootstrap2 = new ZfAppBootstrap($bootstrap1);
  97. $this->assertSame($bootstrap1, $bootstrap2->getApplication());
  98. }
  99. /**
  100. * @expectedException Zend_Application_Bootstrap_Exception
  101. */
  102. public function testConstructorShouldRaiseExceptionForInvalidApplicationArgument()
  103. {
  104. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  105. $bootstrap = new ZfAppBootstrap(new stdClass);
  106. }
  107. public function testSettingOptionsShouldProxyToInternalSetters()
  108. {
  109. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  110. $options = array(
  111. 'arbitrary' => 'foo',
  112. );
  113. $bootstrap = new ZfAppBootstrap($this->application);
  114. $bootstrap->setOptions($options);
  115. $this->assertEquals('foo', $bootstrap->getArbitrary());
  116. }
  117. /**
  118. * @group ZF-6459
  119. */
  120. public function testCallingSetOptionsMultipleTimesShouldMergeOptionsRecursively()
  121. {
  122. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  123. $options = array(
  124. 'deep' => array(
  125. 'foo' => 'bar',
  126. 'bar' => 'baz',
  127. ),
  128. );
  129. $bootstrap = new ZfAppBootstrap($this->application);
  130. $bootstrap->setOptions($options);
  131. $options2 = array(
  132. 'deep' => array(
  133. 'bar' => 'bat',
  134. 'baz' => 'foo',
  135. ),
  136. );
  137. $bootstrap->setOptions($options2);
  138. $expected = array_merge_recursive($options, $options2);
  139. $test = $bootstrap->getOptions();
  140. $this->assertEquals($expected, $test);
  141. }
  142. public function testPluginPathsOptionKeyShouldAddPrefixPathsToPluginLoader()
  143. {
  144. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  145. $bootstrap = new ZfAppBootstrap($this->application);
  146. $bootstrap->setOptions(array(
  147. 'pluginPaths' => array(
  148. 'Foo' => 'foo/bar/path/',
  149. ),
  150. ));
  151. $loader = $bootstrap->getPluginLoader();
  152. $paths = $loader->getPaths('Foo');
  153. $this->assertTrue(is_array($paths));
  154. }
  155. public function testResourcesOptionKeyShouldRegisterBootstrapPluginResources()
  156. {
  157. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  158. $bootstrap = new ZfAppBootstrap($this->application);
  159. $bootstrap->setOptions(array(
  160. 'resources' => array(
  161. 'view' => array(
  162. 'basePath' => dirname(__FILE__) . '/../_files/views/scripts',
  163. ),
  164. ),
  165. ));
  166. $this->assertTrue($bootstrap->hasPluginResource('view'));
  167. }
  168. public function testHasOptionShouldReturnFalseWhenOptionUnavailable()
  169. {
  170. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  171. $bootstrap = new ZfAppBootstrap($this->application);
  172. $this->assertFalse($bootstrap->hasOption('foo'));
  173. }
  174. public function testHasOptionShouldReturnTrueWhenOptionPresent()
  175. {
  176. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  177. $bootstrap = new ZfAppBootstrap($this->application);
  178. $bootstrap->setOptions(array('foo' => 'bar'));
  179. $this->assertTrue($bootstrap->hasOption('foo'));
  180. }
  181. public function testGetOptionShouldReturnNullWhenOptionUnavailable()
  182. {
  183. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  184. $bootstrap = new ZfAppBootstrap($this->application);
  185. $this->assertNull($bootstrap->getOption('foo'));
  186. }
  187. public function testGetOptionShouldReturnOptionValue()
  188. {
  189. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  190. $bootstrap = new ZfAppBootstrap($this->application);
  191. $bootstrap->setOptions(array('foo' => 'bar'));
  192. $this->assertEquals('bar', $bootstrap->getOption('foo'));
  193. }
  194. public function testInternalIntializersShouldBeRegisteredAsClassResources()
  195. {
  196. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  197. $bootstrap = new ZfAppBootstrap($this->application);
  198. $test = $bootstrap->getClassResources();
  199. $resources = array('foo' => '_initFoo', 'bar' => '_initBar', 'barbaz' => '_initBarbaz');
  200. $this->assertEquals($resources, $test);
  201. }
  202. public function testInternalInitializersShouldRegisterResourceNames()
  203. {
  204. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  205. $bootstrap = new ZfAppBootstrap($this->application);
  206. $test = $bootstrap->getClassResourceNames();
  207. $resources = array('foo', 'bar', 'barbaz');
  208. $this->assertEquals($resources, $test);
  209. }
  210. /**
  211. * @expectedException Zend_Application_Bootstrap_Exception
  212. */
  213. public function testRegisterPluginResourceShouldThrowExceptionForInvalidResourceType()
  214. {
  215. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  216. $bootstrap = new ZfAppBootstrap($this->application);
  217. $bootstrap->registerPluginResource(array());
  218. }
  219. public function testShouldAllowRegisteringConcretePluginResources()
  220. {
  221. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  222. $bootstrap = new ZfAppBootstrap($this->application);
  223. $resource = new Zend_Application_Resource_View();
  224. $bootstrap->registerPluginResource($resource);
  225. $test = $bootstrap->getPluginResource('view');
  226. $this->assertSame($resource, $test);
  227. }
  228. public function testRegisteringSecondPluginResourceOfSameTypeShouldOverwrite()
  229. {
  230. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  231. $bootstrap = new ZfAppBootstrap($this->application);
  232. $resource1 = new Zend_Application_Resource_View();
  233. $resource2 = new Zend_Application_Resource_View();
  234. $bootstrap->registerPluginResource($resource1)
  235. ->registerPluginResource($resource2);
  236. $test = $bootstrap->getPluginResource('view');
  237. $this->assertSame($resource2, $test);
  238. }
  239. public function testShouldAllowRegisteringPluginResourceUsingNameOnly()
  240. {
  241. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  242. $bootstrap = new ZfAppBootstrap($this->application);
  243. $bootstrap->registerPluginResource('view');
  244. $test = $bootstrap->getPluginResource('view');
  245. $this->assertEquals('Zend_Application_Resource_View', get_class($test));
  246. }
  247. public function testShouldAllowUnregisteringPluginResourcesUsingConcreteInstance()
  248. {
  249. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  250. $bootstrap = new ZfAppBootstrap($this->application);
  251. $resource = new Zend_Application_Resource_View();
  252. $bootstrap->registerPluginResource($resource);
  253. $bootstrap->unregisterPluginResource($resource);
  254. $this->assertFalse($bootstrap->hasPluginResource('view'));
  255. }
  256. /**
  257. * @expectedException Zend_Application_Bootstrap_Exception
  258. */
  259. public function testAttemptingToUnregisterPluginResourcesUsingInvalidResourceTypeShouldThrowException()
  260. {
  261. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  262. $bootstrap = new ZfAppBootstrap($this->application);
  263. $bootstrap->registerPluginResource('view');
  264. $bootstrap->unregisterPluginResource(array());
  265. }
  266. public function testShouldAllowUnregisteringPluginResourcesByName()
  267. {
  268. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  269. $bootstrap = new ZfAppBootstrap($this->application);
  270. $bootstrap->registerPluginResource('view');
  271. $bootstrap->unregisterPluginResource('view');
  272. $this->assertFalse($bootstrap->hasPluginResource('view'));
  273. }
  274. public function testRetrievingNonExistentPluginResourceShouldReturnNull()
  275. {
  276. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  277. $bootstrap = new ZfAppBootstrap($this->application);
  278. $this->assertNull($bootstrap->getPluginResource('view'));
  279. }
  280. public function testRetrievingPluginResourcesShouldRetrieveConcreteInstances()
  281. {
  282. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  283. $bootstrap = new ZfAppBootstrap($this->application);
  284. $bootstrap->registerPluginResource('view');
  285. $test = $bootstrap->getPluginResources();
  286. foreach ($test as $type => $resource) {
  287. $this->assertTrue($resource instanceof Zend_Application_Resource_Resource);
  288. }
  289. }
  290. public function testShouldAllowRetrievingOnlyPluginResourceNames()
  291. {
  292. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  293. $bootstrap = new ZfAppBootstrap($this->application);
  294. $bootstrap->registerPluginResource('view');
  295. $test = $bootstrap->getPluginResourceNames();
  296. $this->assertEquals(array('view'), $test);
  297. }
  298. public function testShouldAllowSettingAlternativePluginLoaderInstance()
  299. {
  300. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  301. $bootstrap = new ZfAppBootstrap($this->application);
  302. $loader = new Zend_Loader_PluginLoader();
  303. $bootstrap->setPluginLoader($loader);
  304. $this->assertSame($loader, $bootstrap->getPluginLoader());
  305. }
  306. public function testDefaultPluginLoaderShouldRegisterPrefixPathForResources()
  307. {
  308. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  309. $bootstrap = new ZfAppBootstrap($this->application);
  310. $loader = $bootstrap->getPluginLoader();
  311. $paths = $loader->getPaths('Zend_Application_Resource');
  312. $this->assertFalse(empty($paths));
  313. }
  314. public function testEnvironmentShouldMatchApplicationEnvironment()
  315. {
  316. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  317. $bootstrap = new ZfAppBootstrap($this->application);
  318. $this->assertSame($this->application->getEnvironment(), $bootstrap->getEnvironment());
  319. }
  320. public function testBootstrappingShouldOnlyExecuteEachInitializerOnce()
  321. {
  322. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  323. $bootstrap = new ZfAppBootstrap($this->application);
  324. $bootstrap->bootstrap('foo');
  325. $bootstrap->bootstrap('foo');
  326. $this->assertEquals(1, $bootstrap->fooExecuted);
  327. }
  328. public function testBootstrappingShouldFavorInternalResourcesOverPlugins()
  329. {
  330. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  331. $bootstrap = new ZfAppBootstrap($this->application);
  332. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  333. $bootstrap->bootstrap('foo');
  334. $this->assertFalse($bootstrap->executedFooResource);
  335. }
  336. public function testBootstrappingShouldAllowPassingAnArrayOfResources()
  337. {
  338. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  339. $bootstrap = new ZfAppBootstrap($this->application);
  340. $bootstrap->bootstrap(array('foo', 'bar'));
  341. $this->assertEquals(1, $bootstrap->fooExecuted);
  342. $this->assertEquals(1, $bootstrap->barExecuted);
  343. }
  344. public function testPassingNoValuesToBootstrapExecutesAllResources()
  345. {
  346. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  347. $bootstrap = new ZfAppBootstrap($this->application);
  348. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  349. $bootstrap->registerPluginResource('foobar');
  350. $bootstrap->bootstrap();
  351. $this->assertEquals(1, $bootstrap->fooExecuted);
  352. $this->assertEquals(1, $bootstrap->barExecuted);
  353. $this->assertTrue($bootstrap->executedFoobarResource);
  354. }
  355. /**
  356. * @expectedException Zend_Application_Bootstrap_Exception
  357. */
  358. public function testPassingInvalidResourceArgumentToBootstrapShouldThrowException()
  359. {
  360. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  361. $bootstrap = new ZfAppBootstrap($this->application);
  362. $bootstrap->bootstrap(new stdClass);
  363. }
  364. /**
  365. * @expectedException Zend_Application_Bootstrap_Exception
  366. */
  367. public function testPassingUnknownResourceToBootstrapShouldThrowException()
  368. {
  369. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  370. $bootstrap = new ZfAppBootstrap($this->application);
  371. $bootstrap->bootstrap('bazbat');
  372. }
  373. public function testCallShouldOverloadToBootstrap()
  374. {
  375. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  376. $bootstrap = new ZfAppBootstrap($this->application);
  377. $bootstrap->bootstrapFoo();
  378. $this->assertEquals(1, $bootstrap->fooExecuted);
  379. }
  380. /**
  381. * @expectedException Zend_Application_Bootstrap_Exception
  382. */
  383. public function testCallShouldThrowExceptionForInvalidMethodCall()
  384. {
  385. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  386. $bootstrap = new ZfAppBootstrap($this->application);
  387. $bootstrap->initFoo();
  388. }
  389. /**
  390. * @expectedException Zend_Application_Bootstrap_Exception
  391. */
  392. public function testDependencyTrackingShouldDetectCircularDependencies()
  393. {
  394. require_once dirname(__FILE__) . '/../_files/BootstrapBaseCircularDependency.php';
  395. $bootstrap = new BootstrapBaseCircularDependency($this->application);
  396. $bootstrap->bootstrap();
  397. }
  398. public function testContainerShouldBeRegistryInstanceByDefault()
  399. {
  400. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  401. $bootstrap = new ZfAppBootstrap($this->application);
  402. $container = $bootstrap->getContainer();
  403. $this->assertTrue($container instanceof Zend_Registry);
  404. }
  405. public function testContainerShouldAggregateReturnValuesFromClassResources()
  406. {
  407. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  408. $bootstrap = new ZfAppBootstrap($this->application);
  409. $bootstrap->bootstrap('barbaz');
  410. $container = $bootstrap->getContainer();
  411. $this->assertEquals('Baz', $container->barbaz->baz);
  412. }
  413. public function testContainerShouldAggregateReturnValuesFromPluginResources()
  414. {
  415. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  416. $bootstrap = new ZfAppBootstrap($this->application);
  417. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  418. $bootstrap->registerPluginResource('baz');
  419. $bootstrap->bootstrap('baz');
  420. $container = $bootstrap->getContainer();
  421. $this->assertEquals('Baz', $container->baz->baz);
  422. }
  423. public function testClassResourcesShouldBeAvailableFollowingBootstrapping()
  424. {
  425. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  426. $bootstrap = new ZfAppBootstrap($this->application);
  427. $bootstrap->bootstrap('barbaz');
  428. $this->assertTrue($bootstrap->hasResource('barbaz'));
  429. $resource = $bootstrap->getResource('barbaz');
  430. $this->assertEquals('Baz', $resource->baz);
  431. }
  432. public function testPluginResourcesShouldBeAvailableFollowingBootstrapping()
  433. {
  434. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  435. $bootstrap = new ZfAppBootstrap($this->application);
  436. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  437. $bootstrap->registerPluginResource('baz');
  438. $bootstrap->bootstrap('baz');
  439. $this->assertTrue($bootstrap->hasResource('baz'));
  440. $resource = $bootstrap->getResource('baz');
  441. $this->assertEquals('Baz', $resource->baz);
  442. }
  443. /**
  444. * @group ZF-6543
  445. */
  446. public function testPassingPluginResourcesByFullClassNameWithMatchingPluginPathShouldRegisterAsShortName()
  447. {
  448. $this->application->setOptions(array(
  449. 'resources' => array(
  450. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  451. ),
  452. 'pluginPaths' => array(
  453. 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
  454. ),
  455. ));
  456. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  457. $this->assertTrue($bootstrap->hasPluginResource('View'), var_export(array_keys($bootstrap->getPluginResources()), 1));
  458. }
  459. /**
  460. * @group ZF-6543
  461. */
  462. public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldRegisterAsTheClassName()
  463. {
  464. $this->application->setOptions(array(
  465. 'resources' => array(
  466. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  467. ),
  468. ));
  469. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  470. $this->assertTrue($bootstrap->hasPluginResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View'));
  471. }
  472. /**
  473. * @group ZF-6543
  474. */
  475. public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldReturnAppropriateResource()
  476. {
  477. $this->application->setOptions(array(
  478. 'resources' => array(
  479. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  480. ),
  481. ));
  482. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  483. $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  484. $resource = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  485. $this->assertTrue($resource instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
  486. }
  487. /**
  488. * @group ZF-6543
  489. */
  490. public function testCanMixAndMatchPluginResourcesAndFullClassNames()
  491. {
  492. $this->application->setOptions(array(
  493. 'resources' => array(
  494. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  495. 'view' => array(),
  496. ),
  497. ));
  498. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  499. $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  500. $resource1 = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  501. $bootstrap->bootstrap('view');
  502. $resource2 = $bootstrap->getResource('view');
  503. $this->assertNotSame($resource1, $resource2);
  504. $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
  505. $this->assertTrue($resource2 instanceof Zend_View);
  506. }
  507. /**
  508. * @group ZF-6543
  509. */
  510. public function testPluginClassesDefiningExplicitTypeWillBeRegisteredWithThatValue()
  511. {
  512. $this->application->setOptions(array(
  513. 'resources' => array(
  514. 'Zend_Application_Bootstrap_BootstrapAbstractTest_Layout' => array(),
  515. 'layout' => array(),
  516. ),
  517. ));
  518. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  519. $bootstrap->bootstrap('BootstrapAbstractTestLayout');
  520. $resource1 = $bootstrap->getResource('BootstrapAbstractTestLayout');
  521. $bootstrap->bootstrap('layout');
  522. $resource2 = $bootstrap->getResource('layout');
  523. $this->assertNotSame($resource1, $resource2);
  524. $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_Layout, var_export(array_keys($bootstrap->getPluginResources()), 1));
  525. $this->assertTrue($resource2 instanceof Zend_Layout);
  526. }
  527. public function testBootstrapShouldPassItselfToResourcePluginConstructor()
  528. {
  529. $this->application->setOptions(array(
  530. 'pluginPaths' => array(
  531. 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
  532. ),
  533. 'resources' => array(
  534. 'Layout' => array(),
  535. ),
  536. ));
  537. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  538. $resource = $bootstrap->getPluginResource('layout');
  539. $this->assertTrue($resource->bootstrapSetInConstructor, var_export(get_object_vars($resource), 1));
  540. }
  541. }
  542. class Zend_Application_Bootstrap_BootstrapAbstractTest_View
  543. extends Zend_Application_Resource_ResourceAbstract
  544. {
  545. public function init()
  546. {
  547. return $this;
  548. }
  549. }
  550. class Zend_Application_Bootstrap_BootstrapAbstractTest_Layout
  551. extends Zend_Application_Resource_ResourceAbstract
  552. {
  553. public $_explicitType = 'BootstrapAbstractTestLayout';
  554. public $bootstrapSetInConstructor = false;
  555. public function __construct($options = null)
  556. {
  557. parent::__construct($options);
  558. if (null !== $this->getBootstrap()) {
  559. $this->bootstrapSetInConstructor = true;
  560. }
  561. }
  562. public function init()
  563. {
  564. return $this;
  565. }
  566. }
  567. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapAbstractTest::main') {
  568. Zend_Application_Bootstrap_BootstrapAbstractTest::main();
  569. }