DojoTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: LayoutTest.php 17667 2009-08-18 21:40:09Z mikaelkael $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_DojoTest::main');
  24. }
  25. /**
  26. * Zend_Loader_Autoloader
  27. */
  28. require_once 'Zend/Loader/Autoloader.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Application
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Application
  36. */
  37. class Zend_Application_Resource_DojoTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. public function setUp()
  45. {
  46. // Store original autoloaders
  47. $this->loaders = spl_autoload_functions();
  48. if (!is_array($this->loaders)) {
  49. // spl_autoload_functions does not return empty array when no
  50. // autoloaders registered...
  51. $this->loaders = array();
  52. }
  53. Zend_Loader_Autoloader::resetInstance();
  54. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  55. $this->application = new Zend_Application('testing');
  56. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  57. $this->bootstrap->registerPluginResource('view');
  58. Zend_Controller_Front::getInstance()->resetInstance();
  59. }
  60. public function tearDown()
  61. {
  62. // Restore original autoloaders
  63. $loaders = spl_autoload_functions();
  64. foreach ($loaders as $loader) {
  65. spl_autoload_unregister($loader);
  66. }
  67. foreach ($this->loaders as $loader) {
  68. spl_autoload_register($loader);
  69. }
  70. // Reset autoloader instance so it doesn't affect other tests
  71. Zend_Loader_Autoloader::resetInstance();
  72. }
  73. public function testInitializationInitializesDojoContainer()
  74. {
  75. $resource = new Zend_Application_Resource_Dojo(array());
  76. $resource->setBootstrap($this->bootstrap);
  77. $resource->init();
  78. $this->assertTrue($resource->getDojo() instanceof Zend_Dojo_View_Helper_Dojo_Container);
  79. }
  80. public function testInitializationReturnsDojoContainer()
  81. {
  82. $resource = new Zend_Application_Resource_Dojo(array());
  83. $resource->setBootstrap($this->bootstrap);
  84. $test = $resource->init();
  85. $this->assertTrue($test instanceof Zend_Dojo_View_Helper_Dojo_Container);
  86. }
  87. public function testOptionsPassedToResourceAreUsedToSetDojosContainerState()
  88. {
  89. $options = array(
  90. 'requireModules' => array('DojoTest'),
  91. 'localPath' => '/ofc/ZF/Rules/',
  92. );
  93. $resource = new Zend_Application_Resource_Dojo($options);
  94. $resource->setBootstrap($this->bootstrap);
  95. $resource->init();
  96. $resource->getBootstrap()->bootstrap('view');
  97. $dojo = $resource->getBootstrap()->view->dojo();
  98. $test = array(
  99. 'requireModules' => $dojo->getModules(),
  100. 'localPath' => $dojo->getLocalPath()
  101. );
  102. $this->assertEquals($options, $test);
  103. }
  104. }
  105. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_DojoTest::main') {
  106. Zend_Application_Resource_DojoTest::main();
  107. }