PlaceholderTest.php 4.5 KB

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