PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Application/Bootstrap/BootstrapAbstractTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 843 lines | 635 code | 85 blank | 123 comment | 6 complexity | ab7500a5392e1c7564b4d85336440106 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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: BootstrapAbstractTest.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Bootstrap_BootstrapAbstractTest::main');
  24. }
  25. /**
  26. * Zend_Loader_Autoloader
  27. */
  28. require_once 'Zend/Loader/Autoloader.php';
  29. /**
  30. * Zend_Application_Resource_ResourceAbstract
  31. */
  32. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  33. /**
  34. * Zend_Application_Bootstrap_Bootstrapper
  35. */
  36. require_once 'Zend/Application/Bootstrap/Bootstrapper.php';
  37. /**
  38. * Zend_Application_Bootstrap_ResourceBootstrapper
  39. */
  40. require_once 'Zend/Application/Bootstrap/ResourceBootstrapper.php';
  41. /**
  42. * Zend_Application_Bootstrap_BootstrapAbstract
  43. */
  44. require_once 'Zend/Application/Bootstrap/BootstrapAbstract.php';
  45. /**
  46. * Zend_Application_Bootstrap_Bootstrap
  47. */
  48. require_once 'Zend/Application/Bootstrap/Bootstrap.php';
  49. /**
  50. * @category Zend
  51. * @package Zend_Application
  52. * @subpackage UnitTests
  53. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  54. * @license http://framework.zend.com/license/new-bsd New BSD License
  55. * @group Zend_Application
  56. */
  57. class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework_TestCase
  58. {
  59. public static function main()
  60. {
  61. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  62. $result = PHPUnit_TextUI_TestRunner::run($suite);
  63. }
  64. public function setUp()
  65. {
  66. // Store original autoloaders
  67. $this->loaders = spl_autoload_functions();
  68. if (!is_array($this->loaders)) {
  69. // spl_autoload_functions does not return empty array when no
  70. // autoloaders registered...
  71. $this->loaders = array();
  72. }
  73. Zend_Loader_Autoloader::resetInstance();
  74. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  75. $this->application = new Zend_Application('testing');
  76. $this->error = false;
  77. }
  78. public function tearDown()
  79. {
  80. // Restore original autoloaders
  81. $loaders = spl_autoload_functions();
  82. foreach ($loaders as $loader) {
  83. spl_autoload_unregister($loader);
  84. }
  85. foreach ($this->loaders as $loader) {
  86. spl_autoload_register($loader);
  87. }
  88. // Reset autoloader instance so it doesn't affect other tests
  89. Zend_Loader_Autoloader::resetInstance();
  90. }
  91. public function handleError($errno, $errstr)
  92. {
  93. $this->error = $errstr;
  94. return true;
  95. }
  96. public function testConstructorShouldPopulateApplication()
  97. {
  98. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  99. $bootstrap = new ZfAppBootstrap($this->application);
  100. $this->assertSame($this->application, $bootstrap->getApplication());
  101. }
  102. public function testConstructorShouldPopulateOptionsFromApplicationObject()
  103. {
  104. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  105. $options = array(
  106. 'foo' => 'bar',
  107. 'bar' => 'baz',
  108. );
  109. $this->application->setOptions($options);
  110. $bootstrap = new ZfAppBootstrap($this->application);
  111. $this->assertSame($options, $bootstrap->getOptions());
  112. }
  113. public function testConstructorShouldAllowPassingAnotherBootstrapObject()
  114. {
  115. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  116. $bootstrap1 = new ZfAppBootstrap($this->application);
  117. $bootstrap2 = new ZfAppBootstrap($bootstrap1);
  118. $this->assertSame($bootstrap1, $bootstrap2->getApplication());
  119. }
  120. /**
  121. * @expectedException Zend_Application_Bootstrap_Exception
  122. */
  123. public function testConstructorShouldRaiseExceptionForInvalidApplicationArgument()
  124. {
  125. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  126. $bootstrap = new ZfAppBootstrap(new stdClass);
  127. }
  128. public function testSettingOptionsShouldProxyToInternalSetters()
  129. {
  130. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  131. $options = array(
  132. 'arbitrary' => 'foo',
  133. );
  134. $bootstrap = new ZfAppBootstrap($this->application);
  135. $bootstrap->setOptions($options);
  136. $this->assertEquals('foo', $bootstrap->getArbitrary());
  137. }
  138. /**
  139. * @group ZF-6459
  140. */
  141. public function testCallingSetOptionsMultipleTimesShouldMergeOptionsRecursively()
  142. {
  143. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  144. $options = array(
  145. 'deep' => array(
  146. 'foo' => 'bar',
  147. 'bar' => 'baz',
  148. ),
  149. );
  150. $bootstrap = new ZfAppBootstrap($this->application);
  151. $bootstrap->setOptions($options);
  152. $options2 = array(
  153. 'deep' => array(
  154. 'bar' => 'bat',
  155. 'baz' => 'foo',
  156. ),
  157. );
  158. $bootstrap->setOptions($options2);
  159. $expected = $bootstrap->mergeOptions($options, $options2);
  160. $test = $bootstrap->getOptions();
  161. $this->assertEquals($expected, $test);
  162. }
  163. public function testPluginPathsOptionKeyShouldAddPrefixPathsToPluginLoader()
  164. {
  165. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  166. $bootstrap = new ZfAppBootstrap($this->application);
  167. $bootstrap->setOptions(array(
  168. 'pluginPaths' => array(
  169. 'Foo' => 'foo/bar/path/',
  170. ),
  171. ));
  172. $loader = $bootstrap->getPluginLoader();
  173. $paths = $loader->getPaths('Foo');
  174. $this->assertTrue(is_array($paths));
  175. }
  176. public function testResourcesOptionKeyShouldRegisterBootstrapPluginResources()
  177. {
  178. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  179. $bootstrap = new ZfAppBootstrap($this->application);
  180. $bootstrap->setOptions(array(
  181. 'resources' => array(
  182. 'view' => array(
  183. 'basePath' => dirname(__FILE__) . '/../_files/views/scripts',
  184. ),
  185. ),
  186. ));
  187. $this->assertTrue($bootstrap->hasPluginResource('view'));
  188. }
  189. public function testHasOptionShouldReturnFalseWhenOptionUnavailable()
  190. {
  191. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  192. $bootstrap = new ZfAppBootstrap($this->application);
  193. $this->assertFalse($bootstrap->hasOption('foo'));
  194. }
  195. public function testHasOptionShouldReturnTrueWhenOptionPresent()
  196. {
  197. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  198. $bootstrap = new ZfAppBootstrap($this->application);
  199. $bootstrap->setOptions(array('foo' => 'bar'));
  200. $this->assertTrue($bootstrap->hasOption('foo'));
  201. }
  202. public function testGetOptionShouldReturnNullWhenOptionUnavailable()
  203. {
  204. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  205. $bootstrap = new ZfAppBootstrap($this->application);
  206. $this->assertNull($bootstrap->getOption('foo'));
  207. }
  208. public function testGetOptionShouldReturnOptionValue()
  209. {
  210. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  211. $bootstrap = new ZfAppBootstrap($this->application);
  212. $bootstrap->setOptions(array('foo' => 'bar'));
  213. $this->assertEquals('bar', $bootstrap->getOption('foo'));
  214. }
  215. public function testInternalIntializersShouldBeRegisteredAsClassResources()
  216. {
  217. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  218. $bootstrap = new ZfAppBootstrap($this->application);
  219. $test = $bootstrap->getClassResources();
  220. $resources = array('foo' => '_initFoo', 'bar' => '_initBar', 'barbaz' => '_initBarbaz');
  221. $this->assertEquals($resources, $test);
  222. }
  223. public function testInternalInitializersShouldRegisterResourceNames()
  224. {
  225. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  226. $bootstrap = new ZfAppBootstrap($this->application);
  227. $test = $bootstrap->getClassResourceNames();
  228. $resources = array('foo', 'bar', 'barbaz');
  229. $this->assertEquals($resources, $test);
  230. }
  231. /**
  232. * @expectedException Zend_Application_Bootstrap_Exception
  233. */
  234. public function testRegisterPluginResourceShouldThrowExceptionForInvalidResourceType()
  235. {
  236. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  237. $bootstrap = new ZfAppBootstrap($this->application);
  238. $bootstrap->registerPluginResource(array());
  239. }
  240. public function testShouldAllowRegisteringConcretePluginResources()
  241. {
  242. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  243. $bootstrap = new ZfAppBootstrap($this->application);
  244. $resource = new Zend_Application_Resource_View();
  245. $bootstrap->registerPluginResource($resource);
  246. $test = $bootstrap->getPluginResource('view');
  247. $this->assertSame($resource, $test);
  248. }
  249. public function testRegisteringSecondPluginResourceOfSameTypeShouldOverwrite()
  250. {
  251. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  252. $bootstrap = new ZfAppBootstrap($this->application);
  253. $resource1 = new Zend_Application_Resource_View();
  254. $resource2 = new Zend_Application_Resource_View();
  255. $bootstrap->registerPluginResource($resource1)
  256. ->registerPluginResource($resource2);
  257. $test = $bootstrap->getPluginResource('view');
  258. $this->assertSame($resource2, $test);
  259. }
  260. public function testShouldAllowRegisteringPluginResourceUsingNameOnly()
  261. {
  262. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  263. $bootstrap = new ZfAppBootstrap($this->application);
  264. $bootstrap->registerPluginResource('view');
  265. $test = $bootstrap->getPluginResource('view');
  266. $this->assertEquals('Zend_Application_Resource_View', get_class($test));
  267. }
  268. public function testShouldAllowUnregisteringPluginResourcesUsingConcreteInstance()
  269. {
  270. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  271. $bootstrap = new ZfAppBootstrap($this->application);
  272. $resource = new Zend_Application_Resource_View();
  273. $bootstrap->registerPluginResource($resource);
  274. $bootstrap->unregisterPluginResource($resource);
  275. $this->assertFalse($bootstrap->hasPluginResource('view'));
  276. }
  277. /**
  278. * @expectedException Zend_Application_Bootstrap_Exception
  279. */
  280. public function testAttemptingToUnregisterPluginResourcesUsingInvalidResourceTypeShouldThrowException()
  281. {
  282. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  283. $bootstrap = new ZfAppBootstrap($this->application);
  284. $bootstrap->registerPluginResource('view');
  285. $bootstrap->unregisterPluginResource(array());
  286. }
  287. public function testShouldAllowUnregisteringPluginResourcesByName()
  288. {
  289. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  290. $bootstrap = new ZfAppBootstrap($this->application);
  291. $bootstrap->registerPluginResource('view');
  292. $bootstrap->unregisterPluginResource('view');
  293. $this->assertFalse($bootstrap->hasPluginResource('view'));
  294. }
  295. public function testRetrievingNonExistentPluginResourceShouldReturnNull()
  296. {
  297. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  298. $bootstrap = new ZfAppBootstrap($this->application);
  299. $this->assertNull($bootstrap->getPluginResource('view'));
  300. }
  301. public function testRetrievingPluginResourcesShouldRetrieveConcreteInstances()
  302. {
  303. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  304. $bootstrap = new ZfAppBootstrap($this->application);
  305. $bootstrap->registerPluginResource('view');
  306. $test = $bootstrap->getPluginResources();
  307. foreach ($test as $type => $resource) {
  308. $this->assertTrue($resource instanceof Zend_Application_Resource_Resource);
  309. }
  310. }
  311. public function testShouldAllowRetrievingOnlyPluginResourceNames()
  312. {
  313. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  314. $bootstrap = new ZfAppBootstrap($this->application);
  315. $bootstrap->registerPluginResource('view');
  316. $test = $bootstrap->getPluginResourceNames();
  317. $this->assertEquals(array('view'), $test);
  318. }
  319. public function testShouldAllowSettingAlternativePluginLoaderInstance()
  320. {
  321. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  322. $bootstrap = new ZfAppBootstrap($this->application);
  323. $loader = new Zend_Loader_PluginLoader();
  324. $bootstrap->setPluginLoader($loader);
  325. $this->assertSame($loader, $bootstrap->getPluginLoader());
  326. }
  327. public function testDefaultPluginLoaderShouldRegisterPrefixPathForResources()
  328. {
  329. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  330. $bootstrap = new ZfAppBootstrap($this->application);
  331. $loader = $bootstrap->getPluginLoader();
  332. $paths = $loader->getPaths('Zend_Application_Resource');
  333. $this->assertFalse(empty($paths));
  334. }
  335. public function testEnvironmentShouldMatchApplicationEnvironment()
  336. {
  337. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  338. $bootstrap = new ZfAppBootstrap($this->application);
  339. $this->assertSame($this->application->getEnvironment(), $bootstrap->getEnvironment());
  340. }
  341. public function testBootstrappingShouldOnlyExecuteEachInitializerOnce()
  342. {
  343. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  344. $bootstrap = new ZfAppBootstrap($this->application);
  345. $bootstrap->bootstrap('foo');
  346. $bootstrap->bootstrap('foo');
  347. $this->assertEquals(1, $bootstrap->fooExecuted);
  348. }
  349. /**
  350. * @group ZF-7955
  351. */
  352. public function testBootstrappingIsCaseInsensitive()
  353. {
  354. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  355. $bootstrap = new ZfAppBootstrap($this->application);
  356. $bootstrap->bootstrap('Foo');
  357. $bootstrap->bootstrap('Foo');
  358. $bootstrap->bootstrap('foo');
  359. $bootstrap->bootstrap('foo');
  360. $this->assertEquals(1, $bootstrap->fooExecuted);
  361. }
  362. public function testBootstrappingShouldFavorInternalResourcesOverPlugins()
  363. {
  364. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  365. $bootstrap = new ZfAppBootstrap($this->application);
  366. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  367. $bootstrap->bootstrap('foo');
  368. $this->assertFalse($bootstrap->executedFooResource);
  369. }
  370. public function testBootstrappingShouldAllowPassingAnArrayOfResources()
  371. {
  372. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  373. $bootstrap = new ZfAppBootstrap($this->application);
  374. $bootstrap->bootstrap(array('foo', 'bar'));
  375. $this->assertEquals(1, $bootstrap->fooExecuted);
  376. $this->assertEquals(1, $bootstrap->barExecuted);
  377. }
  378. public function testPassingNoValuesToBootstrapExecutesAllResources()
  379. {
  380. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  381. $bootstrap = new ZfAppBootstrap($this->application);
  382. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  383. $bootstrap->registerPluginResource('foobar');
  384. $bootstrap->bootstrap();
  385. $this->assertEquals(1, $bootstrap->fooExecuted);
  386. $this->assertEquals(1, $bootstrap->barExecuted);
  387. $this->assertTrue($bootstrap->executedFoobarResource);
  388. }
  389. /**
  390. * @expectedException Zend_Application_Bootstrap_Exception
  391. */
  392. public function testPassingInvalidResourceArgumentToBootstrapShouldThrowException()
  393. {
  394. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  395. $bootstrap = new ZfAppBootstrap($this->application);
  396. $bootstrap->bootstrap(new stdClass);
  397. }
  398. /**
  399. * @expectedException Zend_Application_Bootstrap_Exception
  400. */
  401. public function testPassingUnknownResourceToBootstrapShouldThrowException()
  402. {
  403. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  404. $bootstrap = new ZfAppBootstrap($this->application);
  405. $bootstrap->bootstrap('bazbat');
  406. }
  407. public function testCallShouldOverloadToBootstrap()
  408. {
  409. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  410. $bootstrap = new ZfAppBootstrap($this->application);
  411. $bootstrap->bootstrapFoo();
  412. $this->assertEquals(1, $bootstrap->fooExecuted);
  413. }
  414. /**
  415. * @expectedException Zend_Application_Bootstrap_Exception
  416. */
  417. public function testCallShouldThrowExceptionForInvalidMethodCall()
  418. {
  419. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  420. $bootstrap = new ZfAppBootstrap($this->application);
  421. $bootstrap->initFoo();
  422. }
  423. /**
  424. * @expectedException Zend_Application_Bootstrap_Exception
  425. */
  426. public function testDependencyTrackingShouldDetectCircularDependencies()
  427. {
  428. require_once dirname(__FILE__) . '/../_files/BootstrapBaseCircularDependency.php';
  429. $bootstrap = new BootstrapBaseCircularDependency($this->application);
  430. $bootstrap->bootstrap();
  431. }
  432. public function testContainerShouldBeRegistryInstanceByDefault()
  433. {
  434. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  435. $bootstrap = new ZfAppBootstrap($this->application);
  436. $container = $bootstrap->getContainer();
  437. $this->assertTrue($container instanceof Zend_Registry);
  438. }
  439. public function testContainerShouldAggregateReturnValuesFromClassResources()
  440. {
  441. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  442. $bootstrap = new ZfAppBootstrap($this->application);
  443. $bootstrap->bootstrap('barbaz');
  444. $container = $bootstrap->getContainer();
  445. $this->assertEquals('Baz', $container->barbaz->baz);
  446. }
  447. public function testContainerShouldAggregateReturnValuesFromPluginResources()
  448. {
  449. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  450. $bootstrap = new ZfAppBootstrap($this->application);
  451. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  452. $bootstrap->registerPluginResource('baz');
  453. $bootstrap->bootstrap('baz');
  454. $container = $bootstrap->getContainer();
  455. $this->assertEquals('Baz', $container->baz->baz);
  456. }
  457. public function testClassResourcesShouldBeAvailableFollowingBootstrapping()
  458. {
  459. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  460. $bootstrap = new ZfAppBootstrap($this->application);
  461. $bootstrap->bootstrap('barbaz');
  462. $this->assertTrue($bootstrap->hasResource('barbaz'));
  463. $resource = $bootstrap->getResource('barbaz');
  464. $this->assertEquals('Baz', $resource->baz);
  465. }
  466. public function testPluginResourcesShouldBeAvailableFollowingBootstrapping()
  467. {
  468. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  469. $bootstrap = new ZfAppBootstrap($this->application);
  470. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  471. $bootstrap->registerPluginResource('baz');
  472. $bootstrap->bootstrap('baz');
  473. $this->assertTrue($bootstrap->hasResource('baz'));
  474. $resource = $bootstrap->getResource('baz');
  475. $this->assertEquals('Baz', $resource->baz);
  476. }
  477. public function testMagicMethodsForPluginResources()
  478. {
  479. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  480. $bootstrap = new ZfAppBootstrap($this->application);
  481. $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
  482. $bootstrap->registerPluginResource('baz');
  483. $bootstrap->bootstrap('baz');
  484. $this->assertTrue(isset($bootstrap->baz));
  485. $resource = $bootstrap->baz;
  486. $this->assertEquals('Baz', $resource->baz);
  487. }
  488. /**
  489. * @group ZF-6543
  490. */
  491. public function testPassingPluginResourcesByFullClassNameWithMatchingPluginPathShouldRegisterAsShortName()
  492. {
  493. $this->application->setOptions(array(
  494. 'resources' => array(
  495. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  496. ),
  497. 'pluginPaths' => array(
  498. 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
  499. ),
  500. ));
  501. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  502. $this->assertTrue($bootstrap->hasPluginResource('View'), var_export(array_keys($bootstrap->getPluginResources()), 1));
  503. }
  504. /**
  505. * @group ZF-6543
  506. */
  507. public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldRegisterAsTheClassName()
  508. {
  509. $this->application->setOptions(array(
  510. 'resources' => array(
  511. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  512. ),
  513. ));
  514. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  515. $this->assertTrue($bootstrap->hasPluginResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View'));
  516. }
  517. /**
  518. * @group ZF-6543
  519. */
  520. public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldReturnAppropriateResource()
  521. {
  522. $this->application->setOptions(array(
  523. 'resources' => array(
  524. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  525. ),
  526. ));
  527. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  528. $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  529. $resource = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  530. $this->assertTrue($resource instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
  531. }
  532. /**
  533. * @group ZF-6543
  534. */
  535. public function testCanMixAndMatchPluginResourcesAndFullClassNames()
  536. {
  537. $this->application->setOptions(array(
  538. 'resources' => array(
  539. 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
  540. 'view' => array(),
  541. ),
  542. ));
  543. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  544. $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  545. $resource1 = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
  546. $bootstrap->bootstrap('view');
  547. $resource2 = $bootstrap->getResource('view');
  548. $this->assertNotSame($resource1, $resource2);
  549. $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
  550. $this->assertTrue($resource2 instanceof Zend_View);
  551. }
  552. /**
  553. * @group ZF-6543
  554. */
  555. public function testPluginClassesDefiningExplicitTypeWillBeRegisteredWithThatValue()
  556. {
  557. $this->application->setOptions(array(
  558. 'resources' => array(
  559. 'Zend_Application_Bootstrap_BootstrapAbstractTest_Layout' => array(),
  560. 'layout' => array(),
  561. ),
  562. ));
  563. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  564. $bootstrap->bootstrap('BootstrapAbstractTestLayout');
  565. $resource1 = $bootstrap->getResource('BootstrapAbstractTestLayout');
  566. $bootstrap->bootstrap('layout');
  567. $resource2 = $bootstrap->getResource('layout');
  568. $this->assertNotSame($resource1, $resource2);
  569. $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_Layout, var_export(array_keys($bootstrap->getPluginResources()), 1));
  570. $this->assertTrue($resource2 instanceof Zend_Layout);
  571. }
  572. /**
  573. * @group ZF-6471
  574. */
  575. public function testBootstrapShouldPassItselfToResourcePluginConstructor()
  576. {
  577. $this->application->setOptions(array(
  578. 'pluginPaths' => array(
  579. 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
  580. ),
  581. 'resources' => array(
  582. 'Foo' => array(),
  583. ),
  584. ));
  585. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  586. $resource = $bootstrap->getPluginResource('foo');
  587. $this->assertTrue($resource->bootstrapSetInConstructor, var_export(get_object_vars($resource), 1));
  588. }
  589. /**
  590. * @group ZF-6591
  591. */
  592. public function testRequestingPluginsByShortNameShouldNotRaiseFatalErrors()
  593. {
  594. $this->autoloader->setFallbackAutoloader(true)
  595. ->suppressNotFoundWarnings(false);
  596. $this->application->setOptions(array(
  597. 'resources' => array(
  598. 'FrontController' => array(),
  599. ),
  600. ));
  601. set_error_handler(array($this, 'handleError'));
  602. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  603. $resource = $bootstrap->getPluginResource('FrontController');
  604. restore_error_handler();
  605. $this->assertTrue(false === $this->error, $this->error);
  606. }
  607. /**
  608. * @group ZF-7550
  609. */
  610. public function testRequestingPluginsByAutoloadableClassNameShouldNotRaiseFatalErrors()
  611. {
  612. // Using namesapce 'zabt' to prevent conflict with Zend namespace
  613. $rl = new Zend_Loader_Autoloader_Resource(array(
  614. 'namespace' => 'Zabt',
  615. 'basePath' => dirname(__FILE__) . '/../_files',
  616. ));
  617. $rl->addResourceType('resources', 'resources', 'Resource');
  618. $options = array(
  619. 'resources' => array(
  620. 'Zabt_Resource_Autoloaded' => array('bar' => 'baz')
  621. ),
  622. );
  623. $this->application->setOptions($options);
  624. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  625. $bootstrap->bootstrap();
  626. }
  627. /**
  628. * @group ZF-7690
  629. */
  630. public function testCallingSetOptionsMultipleTimesShouldUpdateOptionKeys()
  631. {
  632. $this->application->setOptions(array(
  633. 'resources' => array(
  634. 'layout' => array(),
  635. ),
  636. ));
  637. $bootstrap = new Zend_Application_Bootstrap_BootstrapAbstractTest_OptionKeys($this->application);
  638. $bootstrap->setOptions(array(
  639. 'pluginPaths' => array(
  640. 'Foo' => dirname(__FILE__),
  641. ),
  642. ));
  643. $expected = array('resources', 'pluginpaths');
  644. $actual = $bootstrap->getOptionKeys();
  645. $this->assertEquals($expected, $actual);
  646. }
  647. /**
  648. * @group ZF-9110
  649. * @expectedException Zend_Application_Bootstrap_Exception
  650. */
  651. public function testPassingSameBootstrapAsApplicationShouldNotCauseRecursion()
  652. {
  653. $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  654. $bootstrap->setApplication($bootstrap);
  655. }
  656. /**
  657. * @group ZF-7696
  658. */
  659. public function testUsingFallbackAutoloaderWithModulesShouldNotResultInFrontcontrollerNotFoundWarning()
  660. {
  661. require_once dirname(__FILE__) . '/../_files/Zf7696Bootstrap.php';
  662. $this->autoloader->setFallbackAutoloader(true);
  663. $options = array(
  664. 'Resources' => array(
  665. 'modules' => array(),
  666. ),
  667. );
  668. $this->application->setOptions($options);
  669. $bootstrap = new Zf7696Bootstrap($this->application);
  670. $bootstrap->bootstrap(array('modules'));
  671. }
  672. /**
  673. * @group ZF-10199
  674. */
  675. public function testHasOptionShouldTreatOptionKeysAsCaseInsensitive()
  676. {
  677. $application = $this->application;
  678. $application->setOptions(array(
  679. 'fooBar' => 'baz',
  680. ));
  681. $this->assertTrue($application->getBootstrap()->hasOption('FooBar'));
  682. }
  683. /**
  684. * @group ZF-10199
  685. */
  686. public function testGetOptionShouldTreatOptionKeysAsCaseInsensitive()
  687. {
  688. $application = $this->application;
  689. $application->setOptions(array(
  690. 'fooBar' => 'baz',
  691. ));
  692. $this->assertEquals('baz', $application->getBootstrap()->getOption('FooBar'));
  693. }
  694. /**
  695. * @group ZF-8751
  696. * @group ZF-10842
  697. */
  698. public function testPathDefaultZendXToPluginsResources()
  699. {
  700. $application = $this->application
  701. ->getBootstrap()
  702. ->getPluginLoader();
  703. $paths = $application->getPaths('ZendX_Application_Resource_');
  704. $this->assertEquals('ZendX/Application/Resource/', $paths[0]);
  705. }
  706. }
  707. class Zend_Application_Bootstrap_BootstrapAbstractTest_View
  708. extends Zend_Application_Resource_ResourceAbstract
  709. {
  710. public function init()
  711. {
  712. return $this;
  713. }
  714. }
  715. class Zend_Application_Bootstrap_BootstrapAbstractTest_Layout
  716. extends Zend_Application_Resource_ResourceAbstract
  717. {
  718. public $_explicitType = 'BootstrapAbstractTestLayout';
  719. public $bootstrapSetInConstructor = false;
  720. public function __construct($options = null)
  721. {
  722. parent::__construct($options);
  723. if (null !== $this->getBootstrap()) {
  724. $this->bootstrapSetInConstructor = true;
  725. }
  726. }
  727. public function init()
  728. {
  729. return $this;
  730. }
  731. }
  732. class Zend_Application_Bootstrap_BootstrapAbstractTest_Foo
  733. extends Zend_Application_Resource_ResourceAbstract
  734. {
  735. public $bootstrapSetInConstructor = false;
  736. public function __construct($options = null)
  737. {
  738. parent::__construct($options);
  739. if (null !== $this->getBootstrap()) {
  740. $this->bootstrapSetInConstructor = true;
  741. }
  742. }
  743. public function init()
  744. {
  745. return $this;
  746. }
  747. }
  748. class Zend_Application_Bootstrap_BootstrapAbstractTest_OptionKeys
  749. extends Zend_Application_Bootstrap_Bootstrap
  750. {
  751. public function getOptionKeys()
  752. {
  753. return $this->_optionKeys;
  754. }
  755. }
  756. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapAbstractTest::main') {
  757. Zend_Application_Bootstrap_BootstrapAbstractTest::main();
  758. }