| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Application
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Application_Bootstrap_BootstrapAbstractTest::main');
- }
- /**
- * Zend_Loader_Autoloader
- */
- require_once 'Zend/Loader/Autoloader.php';
- /**
- * Zend_Application_Resource_ResourceAbstract
- */
- require_once 'Zend/Application/Resource/ResourceAbstract.php';
- /**
- * Zend_Application_Bootstrap_Bootstrapper
- */
- require_once 'Zend/Application/Bootstrap/Bootstrapper.php';
- /**
- * Zend_Application_Bootstrap_ResourceBootstrapper
- */
- require_once 'Zend/Application/Bootstrap/ResourceBootstrapper.php';
- /**
- * Zend_Application_Bootstrap_BootstrapAbstract
- */
- require_once 'Zend/Application/Bootstrap/BootstrapAbstract.php';
- /**
- * Zend_Application_Bootstrap_Bootstrap
- */
- require_once 'Zend/Application/Bootstrap/Bootstrap.php';
- /**
- * @category Zend
- * @package Zend_Application
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Application
- */
- class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework_TestCase
- {
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- public function setUp()
- {
- // Store original autoloaders
- $this->loaders = spl_autoload_functions();
- if (!is_array($this->loaders)) {
- // spl_autoload_functions does not return empty array when no
- // autoloaders registered...
- $this->loaders = array();
- }
- Zend_Loader_Autoloader::resetInstance();
- $this->autoloader = Zend_Loader_Autoloader::getInstance();
- $this->application = new Zend_Application('testing');
- $this->error = false;
- }
- public function tearDown()
- {
- // Restore original autoloaders
- $loaders = spl_autoload_functions();
- foreach ($loaders as $loader) {
- spl_autoload_unregister($loader);
- }
- foreach ($this->loaders as $loader) {
- spl_autoload_register($loader);
- }
- // Reset autoloader instance so it doesn't affect other tests
- Zend_Loader_Autoloader::resetInstance();
- }
- public function handleError($errno, $errstr)
- {
- $this->error = $errstr;
- return true;
- }
- public function testConstructorShouldPopulateApplication()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertSame($this->application, $bootstrap->getApplication());
- }
- public function testConstructorShouldPopulateOptionsFromApplicationObject()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $options = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- );
- $this->application->setOptions($options);
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertSame($options, $bootstrap->getOptions());
- }
- public function testConstructorShouldAllowPassingAnotherBootstrapObject()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap1 = new ZfAppBootstrap($this->application);
- $bootstrap2 = new ZfAppBootstrap($bootstrap1);
- $this->assertSame($bootstrap1, $bootstrap2->getApplication());
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testConstructorShouldRaiseExceptionForInvalidApplicationArgument()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap(new stdClass);
- }
- public function testSettingOptionsShouldProxyToInternalSetters()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $options = array(
- 'arbitrary' => 'foo',
- );
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions($options);
- $this->assertEquals('foo', $bootstrap->getArbitrary());
- }
- /**
- * @group ZF-6459
- */
- public function testCallingSetOptionsMultipleTimesShouldMergeOptionsRecursively()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $options = array(
- 'deep' => array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- ),
- );
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions($options);
- $options2 = array(
- 'deep' => array(
- 'bar' => 'bat',
- 'baz' => 'foo',
- ),
- );
- $bootstrap->setOptions($options2);
- $expected = $bootstrap->mergeOptions($options, $options2);
- $test = $bootstrap->getOptions();
- $this->assertEquals($expected, $test);
- }
- public function testPluginPathsOptionKeyShouldAddPrefixPathsToPluginLoader()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions(array(
- 'pluginPaths' => array(
- 'Foo' => 'foo/bar/path/',
- ),
- ));
- $loader = $bootstrap->getPluginLoader();
- $paths = $loader->getPaths('Foo');
- $this->assertTrue(is_array($paths));
- }
- public function testResourcesOptionKeyShouldRegisterBootstrapPluginResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions(array(
- 'resources' => array(
- 'view' => array(
- 'basePath' => dirname(__FILE__) . '/../_files/views/scripts',
- ),
- ),
- ));
- $this->assertTrue($bootstrap->hasPluginResource('view'));
- }
- public function testHasOptionShouldReturnFalseWhenOptionUnavailable()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertFalse($bootstrap->hasOption('foo'));
- }
- public function testHasOptionShouldReturnTrueWhenOptionPresent()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions(array('foo' => 'bar'));
- $this->assertTrue($bootstrap->hasOption('foo'));
- }
- public function testGetOptionShouldReturnNullWhenOptionUnavailable()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertNull($bootstrap->getOption('foo'));
- }
- public function testGetOptionShouldReturnOptionValue()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->setOptions(array('foo' => 'bar'));
- $this->assertEquals('bar', $bootstrap->getOption('foo'));
- }
- public function testInternalIntializersShouldBeRegisteredAsClassResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $test = $bootstrap->getClassResources();
- $resources = array('foo' => '_initFoo', 'bar' => '_initBar', 'barbaz' => '_initBarbaz');
- $this->assertEquals($resources, $test);
- }
- public function testInternalInitializersShouldRegisterResourceNames()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $test = $bootstrap->getClassResourceNames();
- $resources = array('foo', 'bar', 'barbaz');
- $this->assertEquals($resources, $test);
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testRegisterPluginResourceShouldThrowExceptionForInvalidResourceType()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource(array());
- }
- public function testShouldAllowRegisteringConcretePluginResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $resource = new Zend_Application_Resource_View();
- $bootstrap->registerPluginResource($resource);
- $test = $bootstrap->getPluginResource('view');
- $this->assertSame($resource, $test);
- }
- public function testRegisteringSecondPluginResourceOfSameTypeShouldOverwrite()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $resource1 = new Zend_Application_Resource_View();
- $resource2 = new Zend_Application_Resource_View();
- $bootstrap->registerPluginResource($resource1)
- ->registerPluginResource($resource2);
- $test = $bootstrap->getPluginResource('view');
- $this->assertSame($resource2, $test);
- }
- public function testShouldAllowRegisteringPluginResourceUsingNameOnly()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource('view');
- $test = $bootstrap->getPluginResource('view');
- $this->assertEquals('Zend_Application_Resource_View', get_class($test));
- }
- public function testShouldAllowUnregisteringPluginResourcesUsingConcreteInstance()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $resource = new Zend_Application_Resource_View();
- $bootstrap->registerPluginResource($resource);
- $bootstrap->unregisterPluginResource($resource);
- $this->assertFalse($bootstrap->hasPluginResource('view'));
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testAttemptingToUnregisterPluginResourcesUsingInvalidResourceTypeShouldThrowException()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource('view');
- $bootstrap->unregisterPluginResource(array());
- }
- public function testShouldAllowUnregisteringPluginResourcesByName()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource('view');
- $bootstrap->unregisterPluginResource('view');
- $this->assertFalse($bootstrap->hasPluginResource('view'));
- }
- public function testRetrievingNonExistentPluginResourceShouldReturnNull()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertNull($bootstrap->getPluginResource('view'));
- }
- public function testRetrievingPluginResourcesShouldRetrieveConcreteInstances()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource('view');
- $test = $bootstrap->getPluginResources();
- foreach ($test as $type => $resource) {
- $this->assertTrue($resource instanceof Zend_Application_Resource_Resource);
- }
- }
- public function testShouldAllowRetrievingOnlyPluginResourceNames()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->registerPluginResource('view');
- $test = $bootstrap->getPluginResourceNames();
- $this->assertEquals(array('view'), $test);
- }
- public function testShouldAllowSettingAlternativePluginLoaderInstance()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $loader = new Zend_Loader_PluginLoader();
- $bootstrap->setPluginLoader($loader);
- $this->assertSame($loader, $bootstrap->getPluginLoader());
- }
- public function testDefaultPluginLoaderShouldRegisterPrefixPathForResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $loader = $bootstrap->getPluginLoader();
- $paths = $loader->getPaths('Zend_Application_Resource');
- $this->assertFalse(empty($paths));
- }
- public function testEnvironmentShouldMatchApplicationEnvironment()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $this->assertSame($this->application->getEnvironment(), $bootstrap->getEnvironment());
- }
- public function testBootstrappingShouldOnlyExecuteEachInitializerOnce()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap('foo');
- $bootstrap->bootstrap('foo');
- $this->assertEquals(1, $bootstrap->fooExecuted);
- }
- /**
- * @group ZF-7955
- */
- public function testBootstrappingIsCaseInsensitive()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap('Foo');
- $bootstrap->bootstrap('Foo');
- $bootstrap->bootstrap('foo');
- $bootstrap->bootstrap('foo');
- $this->assertEquals(1, $bootstrap->fooExecuted);
- }
- public function testBootstrappingShouldFavorInternalResourcesOverPlugins()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
- $bootstrap->bootstrap('foo');
- $this->assertFalse($bootstrap->executedFooResource);
- }
- public function testBootstrappingShouldAllowPassingAnArrayOfResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap(array('foo', 'bar'));
- $this->assertEquals(1, $bootstrap->fooExecuted);
- $this->assertEquals(1, $bootstrap->barExecuted);
- }
- public function testPassingNoValuesToBootstrapExecutesAllResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
- $bootstrap->registerPluginResource('foobar');
- $bootstrap->bootstrap();
- $this->assertEquals(1, $bootstrap->fooExecuted);
- $this->assertEquals(1, $bootstrap->barExecuted);
- $this->assertTrue($bootstrap->executedFoobarResource);
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testPassingInvalidResourceArgumentToBootstrapShouldThrowException()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap(new stdClass);
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testPassingUnknownResourceToBootstrapShouldThrowException()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap('bazbat');
- }
- public function testCallShouldOverloadToBootstrap()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrapFoo();
- $this->assertEquals(1, $bootstrap->fooExecuted);
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testCallShouldThrowExceptionForInvalidMethodCall()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->initFoo();
- }
- /**
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testDependencyTrackingShouldDetectCircularDependencies()
- {
- require_once dirname(__FILE__) . '/../_files/BootstrapBaseCircularDependency.php';
- $bootstrap = new BootstrapBaseCircularDependency($this->application);
- $bootstrap->bootstrap();
- }
- public function testContainerShouldBeRegistryInstanceByDefault()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $container = $bootstrap->getContainer();
- $this->assertTrue($container instanceof Zend_Registry);
- }
- public function testContainerShouldAggregateReturnValuesFromClassResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap('barbaz');
- $container = $bootstrap->getContainer();
- $this->assertEquals('Baz', $container->barbaz->baz);
- }
- public function testContainerShouldAggregateReturnValuesFromPluginResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
- $bootstrap->registerPluginResource('baz');
- $bootstrap->bootstrap('baz');
- $container = $bootstrap->getContainer();
- $this->assertEquals('Baz', $container->baz->baz);
- }
- public function testClassResourcesShouldBeAvailableFollowingBootstrapping()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->bootstrap('barbaz');
- $this->assertTrue($bootstrap->hasResource('barbaz'));
- $resource = $bootstrap->getResource('barbaz');
- $this->assertEquals('Baz', $resource->baz);
- }
- public function testPluginResourcesShouldBeAvailableFollowingBootstrapping()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
- $bootstrap->registerPluginResource('baz');
- $bootstrap->bootstrap('baz');
- $this->assertTrue($bootstrap->hasResource('baz'));
- $resource = $bootstrap->getResource('baz');
- $this->assertEquals('Baz', $resource->baz);
- }
- public function testMagicMethodsForPluginResources()
- {
- require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
- $bootstrap = new ZfAppBootstrap($this->application);
- $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
- $bootstrap->registerPluginResource('baz');
- $bootstrap->bootstrap('baz');
- $this->assertTrue(isset($bootstrap->baz));
- $resource = $bootstrap->baz;
- $this->assertEquals('Baz', $resource->baz);
- }
- /**
- * @group ZF-6543
- */
- public function testPassingPluginResourcesByFullClassNameWithMatchingPluginPathShouldRegisterAsShortName()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
- ),
- 'pluginPaths' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $this->assertTrue($bootstrap->hasPluginResource('View'), var_export(array_keys($bootstrap->getPluginResources()), 1));
- }
- /**
- * @group ZF-6543
- */
- public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldRegisterAsTheClassName()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $this->assertTrue($bootstrap->hasPluginResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View'));
- }
- /**
- * @group ZF-6543
- */
- public function testPassingFullViewClassNameNotMatchingARegisteredPrefixShouldReturnAppropriateResource()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
- $resource = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
- $this->assertTrue($resource instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
- }
- /**
- * @group ZF-6543
- */
- public function testCanMixAndMatchPluginResourcesAndFullClassNames()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest_View' => array(),
- 'view' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $bootstrap->bootstrap('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
- $resource1 = $bootstrap->getResource('Zend_Application_Bootstrap_BootstrapAbstractTest_View');
- $bootstrap->bootstrap('view');
- $resource2 = $bootstrap->getResource('view');
- $this->assertNotSame($resource1, $resource2);
- $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_View, var_export(array_keys($bootstrap->getPluginResources()), 1));
- $this->assertTrue($resource2 instanceof Zend_View);
- }
- /**
- * @group ZF-6543
- */
- public function testPluginClassesDefiningExplicitTypeWillBeRegisteredWithThatValue()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest_Layout' => array(),
- 'layout' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $bootstrap->bootstrap('BootstrapAbstractTestLayout');
- $resource1 = $bootstrap->getResource('BootstrapAbstractTestLayout');
- $bootstrap->bootstrap('layout');
- $resource2 = $bootstrap->getResource('layout');
- $this->assertNotSame($resource1, $resource2);
- $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_Layout, var_export(array_keys($bootstrap->getPluginResources()), 1));
- $this->assertTrue($resource2 instanceof Zend_Layout);
- }
- /**
- * @group ZF-6471
- */
- public function testBootstrapShouldPassItselfToResourcePluginConstructor()
- {
- $this->application->setOptions(array(
- 'pluginPaths' => array(
- 'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
- ),
- 'resources' => array(
- 'Foo' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $resource = $bootstrap->getPluginResource('foo');
- $this->assertTrue($resource->bootstrapSetInConstructor, var_export(get_object_vars($resource), 1));
- }
- /**
- * @group ZF-6591
- */
- public function testRequestingPluginsByShortNameShouldNotRaiseFatalErrors()
- {
- $this->autoloader->setFallbackAutoloader(true)
- ->suppressNotFoundWarnings(false);
- $this->application->setOptions(array(
- 'resources' => array(
- 'FrontController' => array(),
- ),
- ));
- set_error_handler(array($this, 'handleError'));
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $resource = $bootstrap->getPluginResource('FrontController');
- restore_error_handler();
- $this->assertTrue(false === $this->error, $this->error);
- }
- /**
- * @group ZF-7550
- */
- public function testRequestingPluginsByAutoloadableClassNameShouldNotRaiseFatalErrors()
- {
- // Using namesapce 'zabt' to prevent conflict with Zend namespace
- $rl = new Zend_Loader_Autoloader_Resource(array(
- 'namespace' => 'Zabt',
- 'basePath' => dirname(__FILE__) . '/../_files',
- ));
- $rl->addResourceType('resources', 'resources', 'Resource');
- $options = array(
- 'resources' => array(
- 'Zabt_Resource_Autoloaded' => array('bar' => 'baz')
- ),
- );
- $this->application->setOptions($options);
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $bootstrap->bootstrap();
- }
- /**
- * @group ZF-7690
- */
- public function testCallingSetOptionsMultipleTimesShouldUpdateOptionKeys()
- {
- $this->application->setOptions(array(
- 'resources' => array(
- 'layout' => array(),
- ),
- ));
- $bootstrap = new Zend_Application_Bootstrap_BootstrapAbstractTest_OptionKeys($this->application);
- $bootstrap->setOptions(array(
- 'pluginPaths' => array(
- 'Foo' => dirname(__FILE__),
- ),
- ));
- $expected = array('resources', 'pluginpaths');
- $actual = $bootstrap->getOptionKeys();
- $this->assertEquals($expected, $actual);
- }
- /**
- * @group ZF-9110
- * @expectedException Zend_Application_Bootstrap_Exception
- */
- public function testPassingSameBootstrapAsApplicationShouldNotCauseRecursion()
- {
- $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
- $bootstrap->setApplication($bootstrap);
- }
- /**
- * @group ZF-7696
- */
- public function testUsingFallbackAutoloaderWithModulesShouldNotResultInFrontcontrollerNotFoundWarning()
- {
- require_once dirname(__FILE__) . '/../_files/Zf7696Bootstrap.php';
- $this->autoloader->setFallbackAutoloader(true);
- $options = array(
- 'Resources' => array(
- 'modules' => array(),
- ),
- );
- $this->application->setOptions($options);
- $bootstrap = new Zf7696Bootstrap($this->application);
- $bootstrap->bootstrap(array('modules'));
- }
- /**
- * @group ZF-10199
- */
- public function testHasOptionShouldTreatOptionKeysAsCaseInsensitive()
- {
- $application = $this->application;
- $application->setOptions(array(
- 'fooBar' => 'baz',
- ));
- $this->assertTrue($application->getBootstrap()->hasOption('FooBar'));
- }
- /**
- * @group ZF-10199
- */
- public function testGetOptionShouldTreatOptionKeysAsCaseInsensitive()
- {
- $application = $this->application;
- $application->setOptions(array(
- 'fooBar' => 'baz',
- ));
- $this->assertEquals('baz', $application->getBootstrap()->getOption('FooBar'));
- }
- /**
- * @group ZF-8751
- * @group ZF-10842
- */
- public function testPathDefaultZendXToPluginsResources()
- {
- $application = $this->application
- ->getBootstrap()
- ->getPluginLoader();
- $paths = $application->getPaths('ZendX_Application_Resource_');
- $this->assertEquals('ZendX/Application/Resource/', $paths[0]);
- }
- }
- class Zend_Application_Bootstrap_BootstrapAbstractTest_View
- extends Zend_Application_Resource_ResourceAbstract
- {
- public function init()
- {
- return $this;
- }
- }
- class Zend_Application_Bootstrap_BootstrapAbstractTest_Layout
- extends Zend_Application_Resource_ResourceAbstract
- {
- public $_explicitType = 'BootstrapAbstractTestLayout';
- public $bootstrapSetInConstructor = false;
- public function __construct($options = null)
- {
- parent::__construct($options);
- if (null !== $this->getBootstrap()) {
- $this->bootstrapSetInConstructor = true;
- }
- }
- public function init()
- {
- return $this;
- }
- }
- class Zend_Application_Bootstrap_BootstrapAbstractTest_Foo
- extends Zend_Application_Resource_ResourceAbstract
- {
- public $bootstrapSetInConstructor = false;
- public function __construct($options = null)
- {
- parent::__construct($options);
- if (null !== $this->getBootstrap()) {
- $this->bootstrapSetInConstructor = true;
- }
- }
- public function init()
- {
- return $this;
- }
- }
- class Zend_Application_Bootstrap_BootstrapAbstractTest_OptionKeys
- extends Zend_Application_Bootstrap_Bootstrap
- {
- public function getOptionKeys()
- {
- return $this->_optionKeys;
- }
- }
- if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapAbstractTest::main') {
- Zend_Application_Bootstrap_BootstrapAbstractTest::main();
- }
|