PageRenderTime 59ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Dojo/Form/Element/EditorTest.php

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