StandaloneContainerTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_Placeholder_StandaloneContainerTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_Placeholder_StandaloneContainerTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_View_Helper_Placeholder_Container_Standalone */
  28. require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
  29. /** Zend_Registry */
  30. require_once 'Zend/Registry.php';
  31. /** Zend_View_Helper_Placeholder_Registry */
  32. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  33. /** Zend_View */
  34. require_once 'Zend/View.php';
  35. /**
  36. * Test class for Zend_View_Helper_Placeholder_StandaloneContainer.
  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_Placeholder_StandaloneContainerTest extends PHPUnit_Framework_TestCase
  47. {
  48. /**
  49. * Runs the test methods of this class.
  50. *
  51. * @return void
  52. */
  53. public static function main()
  54. {
  55. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_Placeholder_StandaloneContainerTest");
  56. $result = PHPUnit_TextUI_TestRunner::run($suite);
  57. }
  58. /**
  59. * Sets up the fixture, for example, open a network connection.
  60. * This method is called before a test is executed.
  61. *
  62. * @return void
  63. */
  64. public function setUp()
  65. {
  66. $regKey = Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY;
  67. if (Zend_Registry::isRegistered($regKey)) {
  68. $registry = Zend_Registry::getInstance();
  69. unset($registry[$regKey]);
  70. }
  71. $this->basePath = dirname(__FILE__) . '/_files/modules';
  72. $this->helper = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo();
  73. }
  74. /**
  75. * Tears down the fixture, for example, close a network connection.
  76. * This method is called after a test is executed.
  77. *
  78. * @return void
  79. */
  80. public function tearDown()
  81. {
  82. unset($this->helper);
  83. }
  84. public function testViewAccessorWorks()
  85. {
  86. $view = new Zend_View();
  87. $this->helper->setView($view);
  88. $this->assertSame($view, $this->helper->view);
  89. }
  90. public function testContainersPersistBetweenInstances()
  91. {
  92. $foo1 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  93. $foo1->append('Foo');
  94. $foo1->setSeparator(' - ');
  95. $foo2 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  96. $foo2->append('Bar');
  97. $test = $foo1->toString();
  98. $this->assertContains('Foo', $test);
  99. $this->assertContains(' - ', $test);
  100. $this->assertContains('Bar', $test);
  101. }
  102. }
  103. class Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo extends Zend_View_Helper_Placeholder_Container_Standalone
  104. {
  105. protected $_regKey = 'foo';
  106. }
  107. // Call Zend_View_Helper_Placeholder_StandaloneContainerTest::main() if this source file is executed directly.
  108. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_Placeholder_StandaloneContainerTest::main") {
  109. Zend_View_Helper_Placeholder_StandaloneContainerTest::main();
  110. }