2
0

EditorTest.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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-2010 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_Editor.
  37. *
  38. * @category Zend
  39. * @package Zend_Dojo
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2010 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_Form
  45. */
  46. class Zend_Dojo_Form_Element_EditorTest 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("Zend_Dojo_Form_Element_EditorTest");
  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. $this->element = $this->getElement();
  70. $this->element->setView($this->view);
  71. }
  72. /**
  73. * Tears down the fixture, for example, close a network connection.
  74. * This method is called after a test is executed.
  75. *
  76. * @return void
  77. */
  78. public function tearDown()
  79. {
  80. }
  81. public function getView()
  82. {
  83. require_once 'Zend/View.php';
  84. $view = new Zend_View();
  85. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  86. return $view;
  87. }
  88. public function getElement()
  89. {
  90. $element = new Zend_Dojo_Form_Element_Editor(
  91. 'foo',
  92. array(
  93. 'value' => 'some text',
  94. 'label' => 'Editor',
  95. 'class' => 'someclass',
  96. 'style' => 'width: 100px;',
  97. )
  98. );
  99. return $element;
  100. }
  101. public function testShouldRenderEditorDijit()
  102. {
  103. $html = $this->element->render();
  104. $this->assertContains('dojoType="dijit.Editor"', $html, $html);
  105. }
  106. public function testShouldNotHaveCaptureEventsByDefault()
  107. {
  108. $events = $this->element->getCaptureEvents();
  109. $this->assertTrue(empty($events));
  110. }
  111. public function testCaptureEventAccessorsShouldProxyToDijitParams()
  112. {
  113. $this->element->setCaptureEvents(array('foo.bar', 'bar.baz', 'baz.bat'));
  114. $this->assertTrue($this->element->hasDijitParam('captureEvents'));
  115. $this->assertTrue($this->element->hasCaptureEvent('bar.baz'));
  116. $this->assertEquals($this->element->getDijitParam('captureEvents'), $this->element->getCaptureEvents());
  117. $this->element->removeCaptureEvent('bar.baz');
  118. $this->assertFalse($this->element->hasCaptureEvent('bar.baz'), var_export($this->element->getCaptureEvents(), 1));
  119. $events = $this->element->getDijitParam('captureEvents');
  120. $this->assertNotContains('bar.baz', $events, var_export($events, 1));
  121. }
  122. public function testShouldNotHaveEventsByDefault()
  123. {
  124. $events = $this->element->getEvents();
  125. $this->assertTrue(empty($events));
  126. }
  127. public function testEventAccessorsShouldProxyToDijitParams()
  128. {
  129. $this->element->setEvents(array('onClick', 'onKeyUp', 'onKeyDown'));
  130. $this->assertTrue($this->element->hasDijitParam('events'));
  131. $this->assertTrue($this->element->hasEvent('onKeyUp'));
  132. $this->assertEquals($this->element->getDijitParam('events'), $this->element->getEvents());
  133. $this->element->removeEvent('onKeyUp');
  134. $this->assertFalse($this->element->hasEvent('onKeyUp'), var_export($this->element->getEvents(), 1));
  135. $events = $this->element->getDijitParam('events');
  136. $this->assertNotContains('onKeyUp', $events, var_export($events, 1));
  137. }
  138. public function testShouldNotHavePluginsByDefault()
  139. {
  140. $plugins = $this->element->getPlugins();
  141. $this->assertTrue(empty($plugins));
  142. }
  143. public function testPluginAccessorsShouldProxyToDijitParams()
  144. {
  145. $this->element->setPlugins(array('undo', 'bold', 'italic'));
  146. $this->assertTrue($this->element->hasDijitParam('plugins'));
  147. $this->assertTrue($this->element->hasPlugin('bold'));
  148. $this->assertEquals($this->element->getDijitParam('plugins'), $this->element->getPlugins());
  149. $this->element->removePlugin('bold');
  150. $this->assertFalse($this->element->hasPlugin('bold'), var_export($this->element->getPlugins(), 1));
  151. $plugins = $this->element->getDijitParam('plugins');
  152. $this->assertNotContains('bold', $plugins, var_export($plugins, 1));
  153. }
  154. public function testEditActionIntervalShouldDefaultToThree()
  155. {
  156. $this->assertEquals(3, $this->element->getEditActionInterval());
  157. }
  158. public function testEditActionIntervalAccessorsShouldProxyToDijitParams()
  159. {
  160. $this->element->setEditActionInterval(60);
  161. $this->assertEquals($this->element->getDijitParam('editActionInterval'), $this->element->getEditActionInterval());
  162. $this->assertEquals(60, $this->element->getEditActionInterval());
  163. }
  164. public function testFocusOnLoadShouldBeFalseByDefault()
  165. {
  166. $this->assertFalse($this->element->getFocusOnLoad());
  167. }
  168. public function testFocusOnLoadAccessorsShouldProxyToDijitParams()
  169. {
  170. $this->element->setFocusOnLoad(true);
  171. $this->assertEquals($this->element->getDijitParam('focusOnLoad'), $this->element->getFocusOnLoad());
  172. $this->assertTrue($this->element->getFocusOnLoad());
  173. }
  174. public function testHeightShouldHaveDefaultValue()
  175. {
  176. $this->assertEquals('300px', $this->element->getHeight());
  177. }
  178. public function testHeightAccessorsShouldProxyToDijitParams()
  179. {
  180. $this->element->setHeight('25em');
  181. $this->assertEquals($this->element->getDijitParam('height'), $this->element->getHeight());
  182. $this->assertEquals('25em', $this->element->getHeight());
  183. }
  184. public function testInheritWidthShouldBeFalseByDefault()
  185. {
  186. $this->assertFalse($this->element->getInheritWidth());
  187. }
  188. public function testInheritWidthAccessorsShouldProxyToDijitParams()
  189. {
  190. $this->element->setInheritWidth(true);
  191. $this->assertEquals($this->element->getDijitParam('inheritWidth'), $this->element->getInheritWidth());
  192. $this->assertTrue($this->element->getInheritWidth());
  193. }
  194. public function testMinHeightShouldHaveDefaultValue()
  195. {
  196. $this->assertEquals('1em', $this->element->getMinHeight());
  197. }
  198. public function testMinHeightAccessorsShouldProxyToDijitParams()
  199. {
  200. $this->element->setMinHeight('25em');
  201. $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
  202. $this->assertEquals('25em', $this->element->getMinHeight());
  203. }
  204. public function testShouldNotHaveStyleSheetsByDefault()
  205. {
  206. $styleSheets = $this->element->getStyleSheets();
  207. $this->assertTrue(empty($styleSheets));
  208. }
  209. public function testStyleSheetAccessorsShouldProxyToDijitParams()
  210. {
  211. $this->element->setStyleSheets(array('/js/dojo/resources/dojo.css', '/js/custom/styles.css', '/js/dijit/themes/tundra/tundra.css'));
  212. $this->assertTrue($this->element->hasDijitParam('styleSheets'));
  213. $this->assertTrue($this->element->hasStyleSheet('/js/custom/styles.css'));
  214. $this->assertEquals($this->element->getDijitParam('styleSheets'), $this->element->getStyleSheets());
  215. $this->element->removeStyleSheet('/js/custom/styles.css');
  216. $this->assertFalse($this->element->hasStyleSheet('/js/custom/styles.css'), var_export($this->element->getStyleSheets(), 1));
  217. $styleSheets = $this->element->getDijitParam('styleSheets');
  218. $this->assertNotContains('/js/custom/styles.css', $styleSheets, var_export($styleSheets, 1));
  219. }
  220. public function testUpdateIntervalShouldHaveDefaultValue()
  221. {
  222. $this->assertEquals(200, $this->element->getUpdateInterval());
  223. }
  224. public function testUpdateIntervalAccessorsShouldProxyToDijitParams()
  225. {
  226. $this->element->setUpdateInterval(300);
  227. $this->assertEquals($this->element->getDijitParam('updateInterval'), $this->element->getUpdateInterval());
  228. $this->assertEquals(300, $this->element->getUpdateInterval());
  229. }
  230. }
  231. // Call Zend_Dojo_Form_Element_EditorTest::main() if this source file is executed directly.
  232. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_EditorTest::main") {
  233. Zend_Dojo_Form_Element_EditorTest::main();
  234. }