EditorTest.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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_Form_Element_EditorTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_EditorTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_Form_Element_Editor */
  28. require_once 'Zend/Dojo/Form/Element/Editor.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_Form_Element_Dijit.
  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_Form_Element_EditorTest 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_Form_Element_EditorTest");
  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->element = $this->getElement();
  67. $this->element->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 getElement()
  86. {
  87. $element = new Zend_Dojo_Form_Element_Editor(
  88. 'foo',
  89. array(
  90. 'value' => 'some text',
  91. 'label' => 'Editor',
  92. 'class' => 'someclass',
  93. 'style' => 'width: 100px;',
  94. )
  95. );
  96. return $element;
  97. }
  98. public function testShouldRenderEditorDijit()
  99. {
  100. $html = $this->element->render();
  101. $this->assertContains('dojoType="dijit.Editor"', $html, $html);
  102. }
  103. public function testShouldNotHaveCaptureEventsByDefault()
  104. {
  105. $events = $this->element->getCaptureEvents();
  106. $this->assertTrue(empty($events));
  107. }
  108. public function testCaptureEventAccessorsShouldProxyToDijitParams()
  109. {
  110. $this->element->setCaptureEvents(array('foo.bar', 'bar.baz', 'baz.bat'));
  111. $this->assertTrue($this->element->hasDijitParam('captureEvents'));
  112. $this->assertTrue($this->element->hasCaptureEvent('bar.baz'));
  113. $this->assertEquals($this->element->getDijitParam('captureEvents'), $this->element->getCaptureEvents());
  114. $this->element->removeCaptureEvent('bar.baz');
  115. $this->assertFalse($this->element->hasCaptureEvent('bar.baz'), var_export($this->element->getCaptureEvents(), 1));
  116. $events = $this->element->getDijitParam('captureEvents');
  117. $this->assertNotContains('bar.baz', $events, var_export($events, 1));
  118. }
  119. public function testShouldNotHaveEventsByDefault()
  120. {
  121. $events = $this->element->getEvents();
  122. $this->assertTrue(empty($events));
  123. }
  124. public function testEventAccessorsShouldProxyToDijitParams()
  125. {
  126. $this->element->setEvents(array('onClick', 'onKeyUp', 'onKeyDown'));
  127. $this->assertTrue($this->element->hasDijitParam('events'));
  128. $this->assertTrue($this->element->hasEvent('onKeyUp'));
  129. $this->assertEquals($this->element->getDijitParam('events'), $this->element->getEvents());
  130. $this->element->removeEvent('onKeyUp');
  131. $this->assertFalse($this->element->hasEvent('onKeyUp'), var_export($this->element->getEvents(), 1));
  132. $events = $this->element->getDijitParam('events');
  133. $this->assertNotContains('onKeyUp', $events, var_export($events, 1));
  134. }
  135. public function testShouldNotHavePluginsByDefault()
  136. {
  137. $plugins = $this->element->getPlugins();
  138. $this->assertTrue(empty($plugins));
  139. }
  140. public function testPluginAccessorsShouldProxyToDijitParams()
  141. {
  142. $this->element->setPlugins(array('undo', 'bold', 'italic'));
  143. $this->assertTrue($this->element->hasDijitParam('plugins'));
  144. $this->assertTrue($this->element->hasPlugin('bold'));
  145. $this->assertEquals($this->element->getDijitParam('plugins'), $this->element->getPlugins());
  146. $this->element->removePlugin('bold');
  147. $this->assertFalse($this->element->hasPlugin('bold'), var_export($this->element->getPlugins(), 1));
  148. $plugins = $this->element->getDijitParam('plugins');
  149. $this->assertNotContains('bold', $plugins, var_export($plugins, 1));
  150. }
  151. public function testEditActionIntervalShouldDefaultToThree()
  152. {
  153. $this->assertEquals(3, $this->element->getEditActionInterval());
  154. }
  155. public function testEditActionIntervalAccessorsShouldProxyToDijitParams()
  156. {
  157. $this->element->setEditActionInterval(60);
  158. $this->assertEquals($this->element->getDijitParam('editActionInterval'), $this->element->getEditActionInterval());
  159. $this->assertEquals(60, $this->element->getEditActionInterval());
  160. }
  161. public function testFocusOnLoadShouldBeFalseByDefault()
  162. {
  163. $this->assertFalse($this->element->getFocusOnLoad());
  164. }
  165. public function testFocusOnLoadAccessorsShouldProxyToDijitParams()
  166. {
  167. $this->element->setFocusOnLoad(true);
  168. $this->assertEquals($this->element->getDijitParam('focusOnLoad'), $this->element->getFocusOnLoad());
  169. $this->assertTrue($this->element->getFocusOnLoad());
  170. }
  171. public function testHeightShouldHaveDefaultValue()
  172. {
  173. $this->assertEquals('300px', $this->element->getHeight());
  174. }
  175. public function testHeightAccessorsShouldProxyToDijitParams()
  176. {
  177. $this->element->setHeight('25em');
  178. $this->assertEquals($this->element->getDijitParam('height'), $this->element->getHeight());
  179. $this->assertEquals('25em', $this->element->getHeight());
  180. }
  181. public function testInheritWidthShouldBeFalseByDefault()
  182. {
  183. $this->assertFalse($this->element->getInheritWidth());
  184. }
  185. public function testInheritWidthAccessorsShouldProxyToDijitParams()
  186. {
  187. $this->element->setInheritWidth(true);
  188. $this->assertEquals($this->element->getDijitParam('inheritWidth'), $this->element->getInheritWidth());
  189. $this->assertTrue($this->element->getInheritWidth());
  190. }
  191. public function testMinHeightShouldHaveDefaultValue()
  192. {
  193. $this->assertEquals('1em', $this->element->getMinHeight());
  194. }
  195. public function testMinHeightAccessorsShouldProxyToDijitParams()
  196. {
  197. $this->element->setMinHeight('25em');
  198. $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
  199. $this->assertEquals('25em', $this->element->getMinHeight());
  200. }
  201. public function testShouldNotHaveStyleSheetsByDefault()
  202. {
  203. $styleSheets = $this->element->getStyleSheets();
  204. $this->assertTrue(empty($styleSheets));
  205. }
  206. public function testStyleSheetAccessorsShouldProxyToDijitParams()
  207. {
  208. $this->element->setStyleSheets(array('/js/dojo/resources/dojo.css', '/js/custom/styles.css', '/js/dijit/themes/tundra/tundra.css'));
  209. $this->assertTrue($this->element->hasDijitParam('styleSheets'));
  210. $this->assertTrue($this->element->hasStyleSheet('/js/custom/styles.css'));
  211. $this->assertEquals($this->element->getDijitParam('styleSheets'), $this->element->getStyleSheets());
  212. $this->element->removeStyleSheet('/js/custom/styles.css');
  213. $this->assertFalse($this->element->hasStyleSheet('/js/custom/styles.css'), var_export($this->element->getStyleSheets(), 1));
  214. $styleSheets = $this->element->getDijitParam('styleSheets');
  215. $this->assertNotContains('/js/custom/styles.css', $styleSheets, var_export($styleSheets, 1));
  216. }
  217. public function testUpdateIntervalShouldHaveDefaultValue()
  218. {
  219. $this->assertEquals(200, $this->element->getUpdateInterval());
  220. }
  221. public function testUpdateIntervalAccessorsShouldProxyToDijitParams()
  222. {
  223. $this->element->setUpdateInterval(300);
  224. $this->assertEquals($this->element->getDijitParam('updateInterval'), $this->element->getUpdateInterval());
  225. $this->assertEquals(300, $this->element->getUpdateInterval());
  226. }
  227. }
  228. // Call Zend_Dojo_Form_Element_EditorTest::main() if this source file is executed directly.
  229. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_EditorTest::main") {
  230. Zend_Dojo_Form_Element_EditorTest::main();
  231. }