AccordionContainerTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_Dojo
  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_Dojo_View_Helper_AccordionContainerTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_View_Helper_AccordionContainerTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_View_Helper_AccordionContainer */
  28. require_once 'Zend/Dojo/View/Helper/AccordionContainer.php';
  29. /** Zend_View */
  30. require_once 'Zend/View.php';
  31. /** Zend_Registry */
  32. require_once 'Zend/Registry.php';
  33. /** Zend_Dojo_View_Helper_Dojo */
  34. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  35. /**
  36. * Test class for Zend_Dojo_View_Helper_AccordionContainer.
  37. *
  38. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Dojo_View_Helper_AccordionContainerTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @return void
  49. */
  50. public static function main()
  51. {
  52. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_View_Helper_AccordionContainerTest");
  53. $result = PHPUnit_TextUI_TestRunner::run($suite);
  54. }
  55. /**
  56. * Sets up the fixture, for example, open a network connection.
  57. * This method is called before a test is executed.
  58. *
  59. * @return void
  60. */
  61. public function setUp()
  62. {
  63. Zend_Registry::_unsetInstance();
  64. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  65. $this->view = $this->getView();
  66. $this->helper = new Zend_Dojo_View_Helper_AccordionContainer();
  67. $this->helper->setView($this->view);
  68. }
  69. /**
  70. * Tears down the fixture, for example, close a network connection.
  71. * This method is called after a test is executed.
  72. *
  73. * @return void
  74. */
  75. public function tearDown()
  76. {
  77. }
  78. public function getView()
  79. {
  80. require_once 'Zend/View.php';
  81. $view = new Zend_View();
  82. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  83. return $view;
  84. }
  85. public function getContainer()
  86. {
  87. $html = '';
  88. for ($i = 1; $i < 6; ++$i) {
  89. $id = 'pane' . $i;
  90. $title = 'Pane ' . $i;
  91. $content = 'This is the content of pane ' . $i;
  92. $html .= $this->view->accordionPane($id, $content, array('title' => $title));
  93. }
  94. return $this->helper->accordionContainer('container', $html, array(), array('style' => 'height: 200px; width: 100px;'));
  95. }
  96. public function testShouldAllowDeclarativeDijitCreation()
  97. {
  98. $html = $this->getContainer();
  99. $this->assertRegexp('/<div[^>]*(dojoType="dijit.layout.AccordionContainer")/', $html, $html);
  100. }
  101. public function testShouldAllowProgrammaticDijitCreation()
  102. {
  103. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  104. $html = $this->getContainer();
  105. $this->assertNotRegexp('/<div[^>]*(dojoType="dijit.layout.AccordionContainer")/', $html);
  106. $this->assertNotNull($this->view->dojo()->getDijit('container'));
  107. }
  108. public function testShouldAllowCapturingNestedContent()
  109. {
  110. $this->helper->captureStart('foo', array(), array('style' => 'height: 200px; width: 100px;'));
  111. $this->view->accordionPane()->captureStart('bar', array('title' => 'Captured Pane'));
  112. echo "Captured content started\n";
  113. $this->view->accordionPane()->captureStart('baz', array('title' => 'Nested Pane'));
  114. echo 'Nested Content';
  115. echo $this->view->accordionPane()->captureEnd('baz');
  116. echo "Captured content ended\n";
  117. echo $this->view->accordionPane()->captureEnd('bar');
  118. $html = $this->helper->captureEnd('foo');
  119. $this->assertRegexp('/<div[^>]*(id="bar")/', $html);
  120. $this->assertRegexp('/<div[^>]*(id="baz")/', $html);
  121. $this->assertRegexp('/<div[^>]*(id="foo")/', $html);
  122. $this->assertEquals(2, substr_count($html, 'dijit.layout.AccordionPane'));
  123. $this->assertEquals(1, substr_count($html, 'dijit.layout.AccordionContainer'));
  124. $this->assertContains('started', $html);
  125. $this->assertContains('ended', $html);
  126. $this->assertContains('Nested Content', $html);
  127. }
  128. /**
  129. * @expectedException Zend_Dojo_View_Exception
  130. */
  131. public function testCapturingShouldRaiseErrorWhenDuplicateIdDiscovered()
  132. {
  133. $this->helper->captureStart('foo', array(), array('style' => 'height: 200px; width: 100px;'));
  134. $this->view->accordionPane()->captureStart('bar', array('title' => 'Captured Pane'));
  135. $this->view->accordionPane()->captureStart('bar', array('title' => 'Captured Pane'));
  136. echo 'Captured Content';
  137. echo $this->view->accordionPane()->captureEnd('bar');
  138. echo $this->view->accordionPane()->captureEnd('bar');
  139. $html = $this->helper->captureEnd('foo');
  140. }
  141. /**
  142. * @expectedException Zend_Dojo_View_Exception
  143. */
  144. public function testCapturingShouldRaiseErrorWhenNonexistentIdPassedToEnd()
  145. {
  146. $this->helper->captureStart('foo', array(), array('style' => 'height: 200px; width: 100px;'));
  147. $html = $this->helper->captureEnd('bar');
  148. }
  149. }
  150. // Call Zend_Dojo_View_Helper_AccordionContainerTest::main() if this source file is executed directly.
  151. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_AccordionContainerTest::main") {
  152. Zend_Dojo_View_Helper_AccordionContainerTest::main();
  153. }