HelperTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_Layout
  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_Layout_HelperTest::main");
  25. }
  26. require_once 'Zend/Layout/Controller/Action/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_Layout_Controller_Action_Helper_Layout
  32. *
  33. * @category Zend
  34. * @package Zend_Layout
  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_Layout
  39. */
  40. class Zend_Layout_HelperTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Runs the test methods of this class.
  44. *
  45. * @return void
  46. */
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite("Zend_Layout_HelperTest");
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. /**
  53. * Sets up the fixture, for example, open a network connection.
  54. * This method is called before a test is executed.
  55. *
  56. * @return void
  57. */
  58. public function setUp()
  59. {
  60. Zend_Layout_HelperTest_Layout::resetMvcInstance();
  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. }
  69. /**
  70. * Tears down the fixture, for example, close a network connection.
  71. * This method is called after a test is executed.
  72. *
  73. * @return void
  74. */
  75. public function tearDown()
  76. {
  77. }
  78. public function testConstructorWithLayoutObject()
  79. {
  80. $layout = new Zend_Layout();
  81. $helper = new Zend_Layout_Controller_Action_Helper_Layout($layout);
  82. $this->assertSame($layout, $helper->getLayoutInstance());
  83. }
  84. public function testGetLayoutCreatesLayoutObjectWhenNoPluginRegistered()
  85. {
  86. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  87. $layout = $helper->getLayoutInstance();
  88. $this->assertTrue($layout instanceof Zend_Layout);
  89. }
  90. public function testGetLayoutInstancePullsMvcLayoutInstance()
  91. {
  92. $layout = Zend_Layout::startMvc();
  93. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  94. $this->assertSame($layout, $helper->getLayoutInstance());
  95. }
  96. public function testSetLayoutInstanceReplacesExistingLayoutObject()
  97. {
  98. $layout = Zend_Layout::startMvc();
  99. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  100. $this->assertSame($layout, $helper->getLayoutInstance());
  101. $newLayout = new Zend_Layout();
  102. $this->assertNotSame($layout, $newLayout);
  103. $helper->setLayoutInstance($newLayout);
  104. $this->assertSame($newLayout, $helper->getLayoutInstance());
  105. }
  106. public function testDirectFetchesLayoutObject()
  107. {
  108. $layout = Zend_Layout::startMvc();
  109. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  110. $received = $helper->direct();
  111. $this->assertSame($layout, $received);
  112. }
  113. public function testHelperProxiesToLayoutObjectMethods()
  114. {
  115. $layout = Zend_Layout::startMvc();
  116. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  117. $helper->setOptions(array(
  118. 'layout' => 'foo.phtml',
  119. 'layoutPath' => dirname(__FILE__) . '/_files/layouts',
  120. 'contentKey' => 'foo'
  121. ));
  122. $this->assertEquals('foo.phtml', $helper->getLayout());
  123. $this->assertEquals(dirname(__FILE__) . '/_files/layouts', $helper->getLayoutPath());
  124. $this->assertEquals('foo', $helper->getContentKey());
  125. }
  126. }
  127. /**
  128. * Zend_Layout extension to allow resetting MVC instance
  129. */
  130. class Zend_Layout_HelperTest_Layout extends Zend_Layout
  131. {
  132. public static function resetMvcInstance()
  133. {
  134. self::$_mvcInstance = null;
  135. }
  136. }
  137. // Call Zend_Layout_HelperTest::main() if this source file is executed directly.
  138. if (PHPUnit_MAIN_METHOD == "Zend_Layout_HelperTest::main") {
  139. Zend_Layout_HelperTest::main();
  140. }