CustomDijitTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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-2015 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. /** Zend_Dojo_View_Helper_CustomDijit */
  27. require_once 'Zend/Dojo/View/Helper/CustomDijit.php';
  28. /** Zend_View */
  29. require_once 'Zend/View.php';
  30. /** Zend_Registry */
  31. require_once 'Zend/Registry.php';
  32. /** Zend_Dojo_View_Helper_Dojo */
  33. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  34. /**
  35. * Test class for Zend_Dojo_View_Helper_CustomDijit
  36. *
  37. * @category Zend
  38. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_Dojo
  43. * @group Zend_Dojo_View
  44. */
  45. class Zend_Dojo_View_Helper_CustomDijitTest 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(__CLASS__);
  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. Zend_Registry::_unsetInstance();
  66. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  67. $this->view = $this->getView();
  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. /**
  86. * @expectedException Zend_Dojo_View_Exception
  87. */
  88. public function testHelperShouldRaiseExceptionIfNoDojoTypePassed()
  89. {
  90. $this->view->customDijit('foo');
  91. }
  92. public function testHelperInDeclarativeModeShouldGenerateDivWithPassedDojoType()
  93. {
  94. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  95. $this->assertContains('dojoType="custom.Dijit"', $content);
  96. }
  97. public function testHelperInDeclarativeModeShouldRegisterDojoTypeAsModule()
  98. {
  99. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  100. $dojo = $this->view->dojo();
  101. $modules = $dojo->getModules();
  102. $this->assertContains('custom.Dijit', $modules);
  103. }
  104. public function testHelperInProgrammaticModeShouldRegisterDojoTypeAsModule()
  105. {
  106. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  107. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  108. $dojo = $this->view->dojo();
  109. $modules = $dojo->getModules();
  110. $this->assertContains('custom.Dijit', $modules);
  111. }
  112. public function testHelperInProgrammaticModeShouldGenerateDivWithoutPassedDojoType()
  113. {
  114. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  115. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  116. $this->assertNotContains('dojoType="custom.Dijit"', $content);
  117. }
  118. public function testHelperShouldAllowCapturingContent()
  119. {
  120. $this->view->customDijit()->captureStart('foo', array('dojoType' => 'custom.Dijit'));
  121. echo "Captured content started\n";
  122. $content = $this->view->customDijit()->captureEnd('foo');
  123. $this->assertContains(">Captured content started\n<", $content);
  124. }
  125. public function testUsesDefaultDojoTypeWhenPresent()
  126. {
  127. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  128. $helper->setView($this->view);
  129. $content = $helper->fooContentPane('foo');
  130. $this->assertContains('dojoType="foo.ContentPane"', $content);
  131. }
  132. public function testCapturingUsesDefaultDojoTypeWhenPresent()
  133. {
  134. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  135. $helper->setView($this->view);
  136. $helper->fooContentPane()->captureStart('foo');
  137. echo "Captured content started\n";
  138. $content = $helper->fooContentPane()->captureEnd('foo');
  139. $this->assertContains(">Captured content started\n<", $content);
  140. $this->assertContains('dojoType="foo.ContentPane"', $content);
  141. }
  142. /**
  143. * @group ZF-7890
  144. */
  145. public function testHelperShouldAllowSpecifyingRootNode()
  146. {
  147. $content = $this->view->customDijit('foo', 'content', array(
  148. 'dojoType' => 'custom.Dijit',
  149. 'rootNode' => 'select',
  150. ));
  151. $this->assertContains('<select', $content);
  152. }
  153. }
  154. class Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane
  155. extends Zend_Dojo_View_Helper_CustomDijit
  156. {
  157. protected $_defaultDojoType = 'foo.ContentPane';
  158. public function fooContentPane($id = null, $value = null, array $params = array(), array $attribs = array())
  159. {
  160. return $this->customDijit($id, $value, $params, $attribs);
  161. }
  162. }
  163. // Call Zend_Dojo_View_Helper_CustomDijitTest::main() if this source file is executed directly.
  164. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_CustomDijitTest::main") {
  165. Zend_Dojo_View_Helper_CustomDijitTest::main();
  166. }