PlaceholderTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // Call Zend_View_Helper_PlaceholderTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_PlaceholderTest::main");
  5. }
  6. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  7. require_once "PHPUnit/Framework/TestCase.php";
  8. require_once "PHPUnit/Framework/TestSuite.php";
  9. /** Zend_View_Helper_Placeholder */
  10. require_once 'Zend/View/Helper/Placeholder.php';
  11. /** Zend_View_Helper_Placeholder_Registry */
  12. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  13. /** Zend_Registry */
  14. require_once 'Zend/Registry.php';
  15. /**
  16. * Test class for Zend_View_Helper_Placeholder.
  17. *
  18. * @category Zend
  19. * @package Zend_View
  20. * @subpackage UnitTests
  21. */
  22. class Zend_View_Helper_PlaceholderTest extends PHPUnit_Framework_TestCase
  23. {
  24. /**
  25. * @var Zend_View_Helper_Placeholder
  26. */
  27. public $placeholder;
  28. /**
  29. * Runs the test methods of this class.
  30. *
  31. * @return void
  32. */
  33. public static function main()
  34. {
  35. require_once "PHPUnit/TextUI/TestRunner.php";
  36. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_PlaceholderTest");
  37. $result = PHPUnit_TextUI_TestRunner::run($suite);
  38. }
  39. /**
  40. * Sets up the fixture, for example, open a network connection.
  41. * This method is called before a test is executed.
  42. *
  43. * @return void
  44. */
  45. public function setUp()
  46. {
  47. $this->placeholder = new Zend_View_Helper_Placeholder();
  48. }
  49. /**
  50. * Tears down the fixture, for example, close a network connection.
  51. * This method is called after a test is executed.
  52. *
  53. * @return void
  54. */
  55. public function tearDown()
  56. {
  57. unset($this->placeholder);
  58. Zend_Registry::getInstance()->offsetUnset(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY);
  59. }
  60. /**
  61. * @return void
  62. */
  63. public function testConstructorCreatesRegistryOffset()
  64. {
  65. $this->assertTrue(Zend_Registry::isRegistered(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY));
  66. }
  67. public function testMultiplePlaceholdersUseSameRegistry()
  68. {
  69. $this->assertTrue(Zend_Registry::isRegistered(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY));
  70. $registry = Zend_Registry::get(Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY);
  71. $this->assertSame($registry, $this->placeholder->getRegistry());
  72. $placeholder = new Zend_View_Helper_Placeholder();
  73. $this->assertSame($registry, $placeholder->getRegistry());
  74. $this->assertSame($this->placeholder->getRegistry(), $placeholder->getRegistry());
  75. }
  76. /**
  77. * @return void
  78. */
  79. public function testSetView()
  80. {
  81. include_once 'Zend/View.php';
  82. $view = new Zend_View();
  83. $this->placeholder->setView($view);
  84. $this->assertSame($view, $this->placeholder->view);
  85. }
  86. /**
  87. * @return void
  88. */
  89. public function testPlaceholderRetrievesContainer()
  90. {
  91. $container = $this->placeholder->placeholder('foo');
  92. $this->assertTrue($container instanceof Zend_View_Helper_Placeholder_Container_Abstract);
  93. }
  94. /**
  95. * @return void
  96. */
  97. public function testPlaceholderRetrievesSameContainerOnSubsequentCalls()
  98. {
  99. $container1 = $this->placeholder->placeholder('foo');
  100. $container2 = $this->placeholder->placeholder('foo');
  101. $this->assertSame($container1, $container2);
  102. }
  103. }
  104. // Call Zend_View_Helper_PlaceholderTest::main() if this source file is executed directly.
  105. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_PlaceholderTest::main") {
  106. Zend_View_Helper_PlaceholderTest::main();
  107. }