LayoutTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_View
  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. // Call Zend_LayoutTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_LayoutTest::main");
  25. }
  26. require_once 'Zend/View/Helper/Layout.php';
  27. require_once 'Zend/Layout.php';
  28. require_once 'Zend/Controller/Front.php';
  29. require_once 'Zend/Controller/Action/HelperBroker.php';
  30. /**
  31. * Test class for Zend_View_Helper_Layout
  32. *
  33. * @category Zend
  34. * @package Zend_View
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_View
  39. * @group Zend_View_Helper
  40. */
  41. class Zend_View_Helper_LayoutTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_LayoutTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Sets up the fixture, for example, open a network connection.
  55. * This method is called before a test is executed.
  56. *
  57. * @return void
  58. */
  59. public function setUp()
  60. {
  61. Zend_Controller_Front::getInstance()->resetInstance();
  62. if (Zend_Controller_Action_HelperBroker::hasHelper('Layout')) {
  63. Zend_Controller_Action_HelperBroker::removeHelper('Layout');
  64. }
  65. if (Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
  66. Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
  67. }
  68. Zend_View_Helper_LayoutTest_Layout::resetMvcInstance();
  69. }
  70. /**
  71. * Tears down the fixture, for example, close a network connection.
  72. * This method is called after a test is executed.
  73. *
  74. * @return void
  75. */
  76. public function tearDown()
  77. {
  78. }
  79. public function testGetLayoutCreatesLayoutObjectWhenNoPluginRegistered()
  80. {
  81. $helper = new Zend_View_Helper_Layout();
  82. $layout = $helper->getLayout();
  83. $this->assertTrue($layout instanceof Zend_Layout);
  84. }
  85. public function testGetLayoutPullsLayoutObjectFromRegisteredPlugin()
  86. {
  87. $layout = Zend_Layout::startMvc();
  88. $helper = new Zend_View_Helper_Layout();
  89. $this->assertSame($layout, $helper->getLayout());
  90. }
  91. public function testSetLayoutReplacesExistingLayoutObject()
  92. {
  93. $layout = Zend_Layout::startMvc();
  94. $helper = new Zend_View_Helper_Layout();
  95. $this->assertSame($layout, $helper->getLayout());
  96. $newLayout = new Zend_Layout();
  97. $this->assertNotSame($layout, $newLayout);
  98. $helper->setLayout($newLayout);
  99. $this->assertSame($newLayout, $helper->getLayout());
  100. }
  101. public function testHelperMethodFetchesLayoutObject()
  102. {
  103. $layout = Zend_Layout::startMvc();
  104. $helper = new Zend_View_Helper_Layout();
  105. $received = $helper->layout();
  106. $this->assertSame($layout, $received);
  107. }
  108. }
  109. /**
  110. * Zend_Layout extension to allow resetting MVC instance
  111. */
  112. class Zend_View_Helper_LayoutTest_Layout extends Zend_Layout
  113. {
  114. public static function resetMvcInstance()
  115. {
  116. self::$_mvcInstance = null;
  117. }
  118. }
  119. // Call Zend_View_Helper_LayoutTest::main() if this source file is executed directly.
  120. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_LayoutTest::main") {
  121. Zend_View_Helper_LayoutTest::main();
  122. }