LayoutTest.php 4.3 KB

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