CustomDijitTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_CustomDijitTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_View_Helper_CustomDijitTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_View_Helper_CustomDijit */
  28. require_once 'Zend/Dojo/View/Helper/CustomDijit.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_CustomDijit
  37. *
  38. * @category Zend
  39. * @package Zend_Dojo
  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_Dojo
  44. * @group Zend_Dojo_View
  45. */
  46. class Zend_Dojo_View_Helper_CustomDijitTest 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(__CLASS__);
  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. Zend_Registry::_unsetInstance();
  67. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  68. $this->view = $this->getView();
  69. }
  70. /**
  71. * Tears down the fixture, for example, close a network connection.
  72. * This method is called after a test is executed.
  73. *
  74. * @return void
  75. */
  76. public function tearDown()
  77. {
  78. }
  79. public function getView()
  80. {
  81. require_once 'Zend/View.php';
  82. $view = new Zend_View();
  83. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  84. return $view;
  85. }
  86. /**
  87. * @expectedException Zend_Dojo_View_Exception
  88. */
  89. public function testHelperShouldRaiseExceptionIfNoDojoTypePassed()
  90. {
  91. $this->view->customDijit('foo');
  92. }
  93. public function testHelperInDeclarativeModeShouldGenerateDivWithPassedDojoType()
  94. {
  95. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  96. $this->assertContains('dojoType="custom.Dijit"', $content);
  97. }
  98. public function testHelperInDeclarativeModeShouldRegisterDojoTypeAsModule()
  99. {
  100. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  101. $dojo = $this->view->dojo();
  102. $modules = $dojo->getModules();
  103. $this->assertContains('custom.Dijit', $modules);
  104. }
  105. public function testHelperInProgrammaticModeShouldRegisterDojoTypeAsModule()
  106. {
  107. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  108. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  109. $dojo = $this->view->dojo();
  110. $modules = $dojo->getModules();
  111. $this->assertContains('custom.Dijit', $modules);
  112. }
  113. public function testHelperInProgrammaticModeShouldGenerateDivWithoutPassedDojoType()
  114. {
  115. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  116. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  117. $this->assertNotContains('dojoType="custom.Dijit"', $content);
  118. }
  119. public function testHelperShouldAllowCapturingContent()
  120. {
  121. $this->view->customDijit()->captureStart('foo', array('dojoType' => 'custom.Dijit'));
  122. echo "Captured content started\n";
  123. $content = $this->view->customDijit()->captureEnd('foo');
  124. $this->assertContains(">Captured content started\n<", $content);
  125. }
  126. public function testUsesDefaultDojoTypeWhenPresent()
  127. {
  128. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  129. $helper->setView($this->view);
  130. $content = $helper->fooContentPane('foo');
  131. $this->assertContains('dojoType="foo.ContentPane"', $content);
  132. }
  133. public function testCapturingUsesDefaultDojoTypeWhenPresent()
  134. {
  135. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  136. $helper->setView($this->view);
  137. $helper->fooContentPane()->captureStart('foo');
  138. echo "Captured content started\n";
  139. $content = $helper->fooContentPane()->captureEnd('foo');
  140. $this->assertContains(">Captured content started\n<", $content);
  141. $this->assertContains('dojoType="foo.ContentPane"', $content);
  142. }
  143. /**
  144. * @group ZF-7890
  145. */
  146. public function testHelperShouldAllowSpecifyingRootNode()
  147. {
  148. $content = $this->view->customDijit('foo', 'content', array(
  149. 'dojoType' => 'custom.Dijit',
  150. 'rootNode' => 'select',
  151. ));
  152. $this->assertContains('<select', $content);
  153. }
  154. }
  155. class Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane
  156. extends Zend_Dojo_View_Helper_CustomDijit
  157. {
  158. protected $_defaultDojoType = 'foo.ContentPane';
  159. public function fooContentPane($id = null, $value = null, array $params = array(), array $attribs = array())
  160. {
  161. return $this->customDijit($id, $value, $params, $attribs);
  162. }
  163. }
  164. // Call Zend_Dojo_View_Helper_CustomDijitTest::main() if this source file is executed directly.
  165. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_CustomDijitTest::main") {
  166. Zend_Dojo_View_Helper_CustomDijitTest::main();
  167. }