2
0

CustomDijitTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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-2008 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. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2008 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_CustomDijitTest 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(__CLASS__);
  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. }
  67. /**
  68. * Tears down the fixture, for example, close a network connection.
  69. * This method is called after a test is executed.
  70. *
  71. * @return void
  72. */
  73. public function tearDown()
  74. {
  75. }
  76. public function getView()
  77. {
  78. require_once 'Zend/View.php';
  79. $view = new Zend_View();
  80. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  81. return $view;
  82. }
  83. /**
  84. * @expectedException Zend_Dojo_View_Exception
  85. */
  86. public function testHelperShouldRaiseExceptionIfNoDojoTypePassed()
  87. {
  88. $this->view->customDijit('foo');
  89. }
  90. public function testHelperInDeclarativeModeShouldGenerateDivWithPassedDojoType()
  91. {
  92. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  93. $this->assertContains('dojoType="custom.Dijit"', $content);
  94. }
  95. public function testHelperInDeclarativeModeShouldRegisterDojoTypeAsModule()
  96. {
  97. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  98. $dojo = $this->view->dojo();
  99. $modules = $dojo->getModules();
  100. $this->assertContains('custom.Dijit', $modules);
  101. }
  102. public function testHelperInProgrammaticModeShouldRegisterDojoTypeAsModule()
  103. {
  104. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  105. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  106. $dojo = $this->view->dojo();
  107. $modules = $dojo->getModules();
  108. $this->assertContains('custom.Dijit', $modules);
  109. }
  110. public function testHelperInProgrammaticModeShouldGenerateDivWithoutPassedDojoType()
  111. {
  112. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  113. $content = $this->view->customDijit('foo', 'content', array('dojoType' => 'custom.Dijit'));
  114. $this->assertNotContains('dojoType="custom.Dijit"', $content);
  115. }
  116. public function testHelperShouldAllowCapturingContent()
  117. {
  118. $this->view->customDijit()->captureStart('foo', array('dojoType' => 'custom.Dijit'));
  119. echo "Captured content started\n";
  120. $content = $this->view->customDijit()->captureEnd('foo');
  121. $this->assertContains(">Captured content started\n<", $content);
  122. }
  123. public function testUsesDefaultDojoTypeWhenPresent()
  124. {
  125. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  126. $helper->setView($this->view);
  127. $content = $helper->fooContentPane('foo');
  128. $this->assertContains('dojoType="foo.ContentPane"', $content);
  129. }
  130. public function testCapturingUsesDefaultDojoTypeWhenPresent()
  131. {
  132. $helper = new Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane();
  133. $helper->setView($this->view);
  134. $helper->fooContentPane()->captureStart('foo');
  135. echo "Captured content started\n";
  136. $content = $helper->fooContentPane()->captureEnd('foo');
  137. $this->assertContains(">Captured content started\n<", $content);
  138. $this->assertContains('dojoType="foo.ContentPane"', $content);
  139. }
  140. }
  141. class Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane
  142. extends Zend_Dojo_View_Helper_CustomDijit
  143. {
  144. protected $_defaultDojoType = 'foo.ContentPane';
  145. public function fooContentPane($id = null, $value = null, array $params = array(), array $attribs = array())
  146. {
  147. return $this->customDijit($id, $value, $params, $attribs);
  148. }
  149. }
  150. // Call Zend_Dojo_View_Helper_CustomDijitTest::main() if this source file is executed directly.
  151. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_CustomDijitTest::main") {
  152. Zend_Dojo_View_Helper_CustomDijitTest::main();
  153. }