LayoutTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_LayoutTest::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_LayoutTest 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. Zend_Controller_Front::getInstance()->resetInstance();
  58. }
  59. public function tearDown()
  60. {
  61. // Restore original autoloaders
  62. $loaders = spl_autoload_functions();
  63. foreach ($loaders as $loader) {
  64. spl_autoload_unregister($loader);
  65. }
  66. foreach ($this->loaders as $loader) {
  67. spl_autoload_register($loader);
  68. }
  69. // Reset autoloader instance so it doesn't affect other tests
  70. Zend_Loader_Autoloader::resetInstance();
  71. }
  72. public function testInitializationInitializesLayoutObject()
  73. {
  74. $resource = new Zend_Application_Resource_Layout(array());
  75. $resource->setBootstrap($this->bootstrap);
  76. $resource->init();
  77. $this->assertTrue($resource->getLayout() instanceof Zend_Layout);
  78. }
  79. public function testInitializationReturnsLayoutObject()
  80. {
  81. $resource = new Zend_Application_Resource_Layout(array());
  82. $resource->setBootstrap($this->bootstrap);
  83. $test = $resource->init();
  84. $this->assertTrue($test instanceof Zend_Layout);
  85. }
  86. public function testOptionsPassedToResourceAreUsedToSetLayoutState()
  87. {
  88. $options = array(
  89. 'layout' => 'foo.phtml',
  90. 'layoutPath' => dirname(__FILE__),
  91. );
  92. $resource = new Zend_Application_Resource_Layout($options);
  93. $resource->setBootstrap($this->bootstrap);
  94. $resource->init();
  95. $layout = $resource->getLayout();
  96. $test = array(
  97. 'layout' => $layout->getLayout(),
  98. 'layoutPath' => $layout->getLayoutPath(),
  99. );
  100. $this->assertEquals($options, $test);
  101. }
  102. }
  103. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LayoutTest::main') {
  104. Zend_Application_Resource_LayoutTest::main();
  105. }