StandaloneContainerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2012 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. /** Zend_View_Helper_Placeholder_Container_Standalone */
  27. require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';
  28. /** Zend_Registry */
  29. require_once 'Zend/Registry.php';
  30. /** Zend_View_Helper_Placeholder_Registry */
  31. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  32. /** Zend_View */
  33. require_once 'Zend/View.php';
  34. /**
  35. * Test class for Zend_View_Helper_Placeholder_StandaloneContainer.
  36. *
  37. * @category Zend
  38. * @package Zend_View
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_View
  43. * @group Zend_View_Helper
  44. */
  45. class Zend_View_Helper_Placeholder_StandaloneContainerTest extends PHPUnit_Framework_TestCase
  46. {
  47. /**
  48. * Runs the test methods of this class.
  49. *
  50. * @return void
  51. */
  52. public static function main()
  53. {
  54. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_Placeholder_StandaloneContainerTest");
  55. $result = PHPUnit_TextUI_TestRunner::run($suite);
  56. }
  57. /**
  58. * Sets up the fixture, for example, open a network connection.
  59. * This method is called before a test is executed.
  60. *
  61. * @return void
  62. */
  63. public function setUp()
  64. {
  65. $regKey = Zend_View_Helper_Placeholder_Registry::REGISTRY_KEY;
  66. if (Zend_Registry::isRegistered($regKey)) {
  67. $registry = Zend_Registry::getInstance();
  68. unset($registry[$regKey]);
  69. }
  70. $this->basePath = dirname(__FILE__) . '/_files/modules';
  71. $this->helper = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo();
  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->helper);
  82. }
  83. public function testViewAccessorWorks()
  84. {
  85. $view = new Zend_View();
  86. $this->helper->setView($view);
  87. $this->assertSame($view, $this->helper->view);
  88. }
  89. public function testContainersPersistBetweenInstances()
  90. {
  91. $foo1 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  92. $foo1->append('Foo');
  93. $foo1->setSeparator(' - ');
  94. $foo2 = new Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo;
  95. $foo2->append('Bar');
  96. $test = $foo1->toString();
  97. $this->assertContains('Foo', $test);
  98. $this->assertContains(' - ', $test);
  99. $this->assertContains('Bar', $test);
  100. }
  101. }
  102. class Zend_View_Helper_Placeholder_StandaloneContainerTest_Foo extends Zend_View_Helper_Placeholder_Container_Standalone
  103. {
  104. protected $_regKey = 'foo';
  105. }
  106. // Call Zend_View_Helper_Placeholder_StandaloneContainerTest::main() if this source file is executed directly.
  107. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_Placeholder_StandaloneContainerTest::main") {
  108. Zend_View_Helper_Placeholder_StandaloneContainerTest::main();
  109. }