2
0

StandaloneContainerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // Call Zend_View_Helper_Placeholder_StandaloneContainerTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_Placeholder_StandaloneContainerTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  7. /** Zend_View_Helper_Placeholder_Container_Standalone */
  8. require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
  9. /** Zend_Registry */
  10. require_once 'Zend/Registry.php';
  11. /** Zend_View_Helper_Placeholder_Registry */
  12. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  13. /** Zend_View */
  14. require_once 'Zend/View.php';
  15. /**
  16. * Test class for Zend_View_Helper_Placeholder_StandaloneContainer.
  17. *
  18. * @category Zend
  19. * @package Zend_View
  20. * @subpackage UnitTests
  21. */
  22. class Zend_View_Helper_Placeholder_StandaloneContainerTest extends PHPUnit_Framework_TestCase
  23. {
  24. /**
  25. * Runs the test methods of this class.
  26. *
  27. * @return void
  28. */
  29. public static function main()
  30. {
  31. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_Placeholder_StandaloneContainerTest");
  32. $result = PHPUnit_TextUI_TestRunner::run($suite);
  33. }
  34. /**
  35. * Sets up the fixture, for example, open a network connection.
  36. * This method is called before a test is executed.
  37. *
  38. * @return void
  39. */
  40. public function setUp()
  41. {
  42. $regKey = Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY;
  43. if (Zend_Registry::isRegistered($regKey)) {
  44. $registry = Zend_Registry::getInstance();
  45. unset($registry[$regKey]);
  46. }
  47. $this->basePath = dirname(__FILE__) . '/_files/modules';
  48. $this->helper = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo();
  49. }
  50. /**
  51. * Tears down the fixture, for example, close a network connection.
  52. * This method is called after a test is executed.
  53. *
  54. * @return void
  55. */
  56. public function tearDown()
  57. {
  58. unset($this->helper);
  59. }
  60. public function testViewAccessorWorks()
  61. {
  62. $view = new Zend_View();
  63. $this->helper->setView($view);
  64. $this->assertSame($view, $this->helper->view);
  65. }
  66. public function testContainersPersistBetweenInstances()
  67. {
  68. $foo1 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  69. $foo1->append('Foo');
  70. $foo1->setSeparator(' - ');
  71. $foo2 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  72. $foo2->append('Bar');
  73. $test = $foo1->toString();
  74. $this->assertContains('Foo', $test);
  75. $this->assertContains(' - ', $test);
  76. $this->assertContains('Bar', $test);
  77. }
  78. }
  79. class Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo extends Zend_View_Helper_Placeholder_Container_Standalone
  80. {
  81. protected $_regKey = 'foo';
  82. }
  83. // Call Zend_View_Helper_Placeholder_StandaloneContainerTest::main() if this source file is executed directly.
  84. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_Placeholder_StandaloneContainerTest::main") {
  85. Zend_View_Helper_Placeholder_StandaloneContainerTest::main();
  86. }