PlaceholderTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_View_Helper_PlaceholderTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_PlaceholderTest::main");
  25. }
  26. /** Zend_View_Helper_Placeholder */
  27. require_once 'Zend/View/Helper/Placeholder.php';
  28. /** Zend_View_Helper_Placeholder_Registry */
  29. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  30. /** Zend_Registry */
  31. require_once 'Zend/Registry.php';
  32. /**
  33. * Test class for Zend_View_Helper_Placeholder.
  34. *
  35. * @category Zend
  36. * @package Zend_View
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_View
  41. * @group Zend_View_Helper
  42. */
  43. class Zend_View_Helper_PlaceholderTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * @var Zend_View_Helper_Placeholder
  47. */
  48. public $placeholder;
  49. /**
  50. * Runs the test methods of this class.
  51. *
  52. * @return void
  53. */
  54. public static function main()
  55. {
  56. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_PlaceholderTest");
  57. $result = PHPUnit_TextUI_TestRunner::run($suite);
  58. }
  59. /**
  60. * Sets up the fixture, for example, open a network connection.
  61. * This method is called before a test is executed.
  62. *
  63. * @return void
  64. */
  65. public function setUp()
  66. {
  67. $this->placeholder = new Zend_View_Helper_Placeholder();
  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. unset($this->placeholder);
  78. Zend_Registry::getInstance()->offsetUnset(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY);
  79. }
  80. /**
  81. * @return void
  82. */
  83. public function testConstructorCreatesRegistryOffset()
  84. {
  85. $this->assertTrue(Zend_Registry::isRegistered(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY));
  86. }
  87. public function testMultiplePlaceholdersUseSameRegistry()
  88. {
  89. $this->assertTrue(Zend_Registry::isRegistered(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY));
  90. $registry = Zend_Registry::get(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY);
  91. $this->assertSame($registry, $this->placeholder->getRegistry());
  92. $placeholder = new Zend_View_Helper_Placeholder();
  93. $this->assertSame($registry, $placeholder->getRegistry());
  94. $this->assertSame($this->placeholder->getRegistry(), $placeholder->getRegistry());
  95. }
  96. /**
  97. * @return void
  98. */
  99. public function testSetView()
  100. {
  101. include_once 'Zend/View.php';
  102. $view = new Zend_View();
  103. $this->placeholder->setView($view);
  104. $this->assertSame($view, $this->placeholder->view);
  105. }
  106. /**
  107. * @return void
  108. */
  109. public function testPlaceholderRetrievesContainer()
  110. {
  111. $container = $this->placeholder->placeholder('foo');
  112. $this->assertTrue($container instanceof Zend_View_Helper_Placeholder_Container_Abstract);
  113. }
  114. /**
  115. * @return void
  116. */
  117. public function testPlaceholderRetrievesSameContainerOnSubsequentCalls()
  118. {
  119. $container1 = $this->placeholder->placeholder('foo');
  120. $container2 = $this->placeholder->placeholder('foo');
  121. $this->assertSame($container1, $container2);
  122. }
  123. }
  124. // Call Zend_View_Helper_PlaceholderTest::main() if this source file is executed directly.
  125. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_PlaceholderTest::main") {
  126. Zend_View_Helper_PlaceholderTest::main();
  127. }