2
0

HelperTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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-2009 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 dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
  27. require_once "PHPUnit/Framework/TestCase.php";
  28. require_once "PHPUnit/Framework/TestSuite.php";
  29. require_once 'Zend/Layout/Controller/Action/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_Layout_Controller_Action_Helper_Layout
  35. *
  36. * @category Zend
  37. * @package Zend_Layout
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Layout
  42. */
  43. class Zend_Layout_HelperTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @return void
  49. */
  50. public static function main()
  51. {
  52. require_once "PHPUnit/TextUI/TestRunner.php";
  53. $suite = new PHPUnit_Framework_TestSuite("Zend_Layout_HelperTest");
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. /**
  57. * Sets up the fixture, for example, open a network connection.
  58. * This method is called before a test is executed.
  59. *
  60. * @return void
  61. */
  62. public function setUp()
  63. {
  64. Zend_Layout_HelperTest_Layout::resetMvcInstance();
  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. }
  73. /**
  74. * Tears down the fixture, for example, close a network connection.
  75. * This method is called after a test is executed.
  76. *
  77. * @return void
  78. */
  79. public function tearDown()
  80. {
  81. }
  82. public function testConstructorWithLayoutObject()
  83. {
  84. $layout = new Zend_Layout();
  85. $helper = new Zend_Layout_Controller_Action_Helper_Layout($layout);
  86. $this->assertSame($layout, $helper->getLayoutInstance());
  87. }
  88. public function testGetLayoutCreatesLayoutObjectWhenNoPluginRegistered()
  89. {
  90. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  91. $layout = $helper->getLayoutInstance();
  92. $this->assertTrue($layout instanceof Zend_Layout);
  93. }
  94. public function testGetLayoutInstancePullsMvcLayoutInstance()
  95. {
  96. $layout = Zend_Layout::startMvc();
  97. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  98. $this->assertSame($layout, $helper->getLayoutInstance());
  99. }
  100. public function testSetLayoutInstanceReplacesExistingLayoutObject()
  101. {
  102. $layout = Zend_Layout::startMvc();
  103. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  104. $this->assertSame($layout, $helper->getLayoutInstance());
  105. $newLayout = new Zend_Layout();
  106. $this->assertNotSame($layout, $newLayout);
  107. $helper->setLayoutInstance($newLayout);
  108. $this->assertSame($newLayout, $helper->getLayoutInstance());
  109. }
  110. public function testDirectFetchesLayoutObject()
  111. {
  112. $layout = Zend_Layout::startMvc();
  113. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  114. $received = $helper->direct();
  115. $this->assertSame($layout, $received);
  116. }
  117. public function testHelperProxiesToLayoutObjectMethods()
  118. {
  119. $layout = Zend_Layout::startMvc();
  120. $helper = new Zend_Layout_Controller_Action_Helper_Layout();
  121. $helper->setOptions(array(
  122. 'layout' => 'foo.phtml',
  123. 'layoutPath' => dirname(__FILE__) . '/_files/layouts',
  124. 'contentKey' => 'foo'
  125. ));
  126. $this->assertEquals('foo.phtml', $helper->getLayout());
  127. $this->assertEquals(dirname(__FILE__) . '/_files/layouts', $helper->getLayoutPath());
  128. $this->assertEquals('foo', $helper->getContentKey());
  129. }
  130. }
  131. /**
  132. * Zend_Layout extension to allow resetting MVC instance
  133. */
  134. class Zend_Layout_HelperTest_Layout extends Zend_Layout
  135. {
  136. public static function resetMvcInstance()
  137. {
  138. self::$_mvcInstance = null;
  139. }
  140. }
  141. // Call Zend_Layout_HelperTest::main() if this source file is executed directly.
  142. if (PHPUnit_MAIN_METHOD == "Zend_Layout_HelperTest::main") {
  143. Zend_Layout_HelperTest::main();
  144. }