ソースを参照

Introducing Zend_Application_Resource_Dojo . Resolving #ZF-7939

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18620 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak 16 年 前
コミット
d8bd147e4e

+ 70 - 0
library/Zend/Application/Resource/Dojo.php

@@ -0,0 +1,70 @@
+<?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 Resource
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Layout.php 17687 2009-08-20 12:55:34Z thomas $
+ */
+
+/**
+ * Resource for settings Dojo options
+ *
+ * @uses       Zend_Application_Resource_ResourceAbstract
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage Resource
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Application_Resource_Dojo
+    extends Zend_Application_Resource_ResourceAbstract
+{
+    /**
+     * @var Zend_Dojo_View_Helper_Dojo_Container
+     */
+    protected $_dojo;
+
+    /**
+     * Defined by Zend_Application_Resource_Resource
+     *
+     * @return Zend_Dojo_View_Helper_Dojo_Container
+     */
+    public function init()
+    {
+        return $this->getDojo();
+    }
+
+    /**
+     * Retrieve Dojo View Helper
+     *
+     * @return Zend_Dojo_View_Dojo_Container
+     */
+    public function getDojo()
+    {
+        if (null === $this->_dojo) {
+            $this->getBootstrap()->bootstrap('view');
+            $view = $this->getBootstrap()->view;
+            
+            Zend_Dojo::enableView($view);
+            $view->dojo()->setOptions($this->getOptions());
+            
+            $this->_dojo = $view->dojo();
+        }
+        
+        return $this->_dojo;
+    }
+}

+ 2 - 0
tests/Zend/Application/Resource/AllTests.php

@@ -31,6 +31,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 
 require_once 'Zend/Application/Resource/ResourceAbstractTest.php';
 require_once 'Zend/Application/Resource/DbTest.php';
+require_once 'Zend/Application/Resource/DojoTest.php';
 require_once 'Zend/Application/Resource/FrontcontrollerTest.php';
 require_once 'Zend/Application/Resource/LayoutTest.php';
 require_once 'Zend/Application/Resource/LocaleTest.php';
@@ -61,6 +62,7 @@ class Zend_Application_Resource_AllTests
 
         $suite->addTestSuite('Zend_Application_Resource_ResourceAbstractTest');
         $suite->addTestSuite('Zend_Application_Resource_DbTest');
+        $suite->addTestSuite('Zend_Application_Resource_DojoTest');        
         $suite->addTestSuite('Zend_Application_Resource_FrontcontrollerTest');
         $suite->addTestSuite('Zend_Application_Resource_LayoutTest');
         $suite->addTestSuite('Zend_Application_Resource_LocaleTest');

+ 129 - 0
tests/Zend/Application/Resource/DojoTest.php

@@ -0,0 +1,129 @@
+<?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-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: LayoutTest.php 17667 2009-08-18 21:40:09Z mikaelkael $
+ */
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_LayoutTest::main');
+}
+
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
+
+/**
+ * Zend_Loader_Autoloader
+ */
+require_once 'Zend/Loader/Autoloader.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Application
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 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_Resource_DojoTest 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->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
+        $this->bootstrap->registerPluginResource('view');
+
+        Zend_Controller_Front::getInstance()->resetInstance();
+    }
+
+    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 testInitializationInitializesDojoContainer()
+    {
+        $resource = new Zend_Application_Resource_Dojo(array());
+        $resource->setBootstrap($this->bootstrap);
+        $resource->init();
+        $this->assertTrue($resource->getDojo() instanceof Zend_Dojo_View_Helper_Dojo_Container);
+    }
+
+    public function testInitializationReturnsDojoContainer()
+    {
+        $resource = new Zend_Application_Resource_Dojo(array());
+        $resource->setBootstrap($this->bootstrap);
+        $test = $resource->init();
+        $this->assertTrue($test instanceof Zend_Dojo_View_Helper_Dojo_Container);
+    }
+
+    public function testOptionsPassedToResourceAreUsedToSetDojosContainerState()
+    {
+        $options = array(
+            'requireModules'     => array('DojoTest'),
+            'localPath'          => '/ofc/ZF/Rules/',
+        );
+
+        $resource = new Zend_Application_Resource_Dojo($options);
+        $resource->setBootstrap($this->bootstrap);
+        $resource->init();
+        $resource->getBootstrap()->bootstrap('view');
+        $dojo = $resource->getBootstrap()->view->dojo();
+        
+        $test = array(
+            'requireModules' => $dojo->getModules(),
+            'localPath'      => $dojo->getLocalPath()
+        );
+        $this->assertEquals($options, $test);
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LayoutTest::main') {
+    Zend_Application_Resource_LayoutTest::main();
+}