HorizontalSliderTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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_HorizontalSliderTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_HorizontalSliderTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_Form_Element_HorizontalSlider */
  28. require_once 'Zend/Dojo/Form/Element/HorizontalSlider.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_HorizontalSliderTest 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_HorizontalSliderTest");
  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_HorizontalSlider(
  88. 'foo',
  89. array(
  90. 'value' => 'some text',
  91. 'label' => 'HorizontalSlider',
  92. 'class' => 'someclass',
  93. 'style' => 'width: 100px;',
  94. )
  95. );
  96. return $element;
  97. }
  98. public function testClickSelectAccessorsShouldProxyToDijitParams()
  99. {
  100. $this->assertFalse($this->element->getClickSelect());
  101. $this->assertFalse(array_key_exists('clickSelect', $this->element->dijitParams));
  102. $this->element->setClickSelect(true);
  103. $this->assertTrue($this->element->getClickSelect());
  104. $this->assertTrue($this->element->dijitParams['clickSelect']);
  105. }
  106. public function testIntermediateChangesAccessorsShouldProxyToDijitParams()
  107. {
  108. $this->assertFalse($this->element->getIntermediateChanges());
  109. $this->assertFalse(array_key_exists('intermediateChanges', $this->element->dijitParams));
  110. $this->element->setIntermediateChanges(true);
  111. $this->assertTrue($this->element->getIntermediateChanges());
  112. $this->assertTrue($this->element->dijitParams['intermediateChanges']);
  113. }
  114. public function testShowButtonsAccessorsShouldProxyToDijitParams()
  115. {
  116. $this->assertFalse($this->element->getShowButtons());
  117. $this->assertFalse(array_key_exists('showButtons', $this->element->dijitParams));
  118. $this->element->setShowButtons(true);
  119. $this->assertTrue($this->element->getShowButtons());
  120. $this->assertTrue($this->element->dijitParams['showButtons']);
  121. }
  122. public function testDiscreteValuesAccessorsShouldProxyToDijitParams()
  123. {
  124. $this->assertNull($this->element->getDiscreteValues());
  125. $this->assertFalse(array_key_exists('discreteValues', $this->element->dijitParams));
  126. $this->element->setDiscreteValues(20);
  127. $this->assertEquals(20, $this->element->getDiscreteValues());
  128. $this->assertEquals(20, $this->element->dijitParams['discreteValues']);
  129. }
  130. public function testMinimumAccessorsShouldProxyToDijitParams()
  131. {
  132. $this->assertNull($this->element->getMinimum());
  133. $this->assertFalse(array_key_exists('minimum', $this->element->dijitParams));
  134. $this->element->setMinimum(20);
  135. $this->assertEquals(20, $this->element->getMinimum());
  136. $this->assertEquals(20, $this->element->dijitParams['minimum']);
  137. }
  138. public function testMaximumAccessorsShouldProxyToDijitParams()
  139. {
  140. $this->assertNull($this->element->getMaximum());
  141. $this->assertFalse(array_key_exists('maximum', $this->element->dijitParams));
  142. $this->element->setMaximum(20);
  143. $this->assertEquals(20, $this->element->getMaximum());
  144. $this->assertEquals(20, $this->element->dijitParams['maximum']);
  145. }
  146. public function testPageIncrementAccessorsShouldProxyToDijitParams()
  147. {
  148. $this->assertNull($this->element->getPageIncrement());
  149. $this->assertFalse(array_key_exists('pageIncrement', $this->element->dijitParams));
  150. $this->element->setPageIncrement(20);
  151. $this->assertEquals(20, $this->element->getPageIncrement());
  152. $this->assertEquals(20, $this->element->dijitParams['pageIncrement']);
  153. }
  154. public function testSettingTopDecorationDijitShouldProxyToTopDecorationDijitParam()
  155. {
  156. $this->element->setTopDecorationDijit('HorizontalRule');
  157. $this->assertTrue($this->element->hasDijitParam('topDecoration'));
  158. $topDecoration = $this->element->getDijitParam('topDecoration');
  159. $test = $this->element->getTopDecoration();
  160. $this->assertSame($topDecoration, $test);
  161. $this->assertTrue(array_key_exists('dijit', $topDecoration));
  162. $this->assertEquals('HorizontalRule', $topDecoration['dijit']);
  163. }
  164. public function testSettingTopDecorationContainerShouldProxyToTopDecorationDijitParam()
  165. {
  166. $this->element->setTopDecorationContainer('top');
  167. $this->assertTrue($this->element->hasDijitParam('topDecoration'));
  168. $topDecoration = $this->element->getDijitParam('topDecoration');
  169. $test = $this->element->getTopDecoration();
  170. $this->assertSame($topDecoration, $test);
  171. $this->assertTrue(array_key_exists('container', $topDecoration));
  172. $this->assertEquals('top', $topDecoration['container']);
  173. }
  174. public function testSettingTopDecorationLabelsShouldProxyToTopDecorationDijitParam()
  175. {
  176. $labels = array('0%', '50%', '100%');
  177. $this->element->setTopDecorationLabels($labels);
  178. $this->assertTrue($this->element->hasDijitParam('topDecoration'));
  179. $topDecoration = $this->element->getDijitParam('topDecoration');
  180. $test = $this->element->getTopDecoration();
  181. $this->assertSame($topDecoration, $test);
  182. $this->assertTrue(array_key_exists('labels', $topDecoration));
  183. $this->assertSame($labels, $topDecoration['labels']);
  184. }
  185. public function testSettingTopDecorationParamsShouldProxyToTopDecorationDijitParam()
  186. {
  187. $params = array(
  188. 'container' => array(
  189. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  190. ),
  191. 'list' => array(
  192. 'style' => 'height:1em; font-size=75%;color:gray;',
  193. ),
  194. );
  195. $this->element->setTopDecorationParams($params);
  196. $this->assertTrue($this->element->hasDijitParam('topDecoration'));
  197. $topDecoration = $this->element->getDijitParam('topDecoration');
  198. $test = $this->element->getTopDecoration();
  199. $this->assertSame($topDecoration, $test);
  200. $this->assertTrue(array_key_exists('params', $topDecoration));
  201. $this->assertSame($params, $topDecoration['params']);
  202. }
  203. public function testSettingTopDecorationAttribsShouldProxyToTopDecorationDijitParam()
  204. {
  205. $attribs = array(
  206. 'container' => array(
  207. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  208. ),
  209. 'list' => array(
  210. 'style' => 'height:1em; font-size=75%;color:gray;',
  211. ),
  212. );
  213. $this->element->setTopDecorationAttribs($attribs);
  214. $this->assertTrue($this->element->hasDijitParam('topDecoration'));
  215. $topDecoration = $this->element->getDijitParam('topDecoration');
  216. $test = $this->element->getTopDecoration();
  217. $this->assertSame($topDecoration, $test);
  218. $this->assertTrue(array_key_exists('attribs', $topDecoration));
  219. $this->assertSame($attribs, $topDecoration['attribs']);
  220. }
  221. public function testSettingBottomDecorationDijitShouldProxyToBottomDecorationDijitParam()
  222. {
  223. $this->element->setBottomDecorationDijit('HorizontalRule');
  224. $this->assertTrue($this->element->hasDijitParam('bottomDecoration'));
  225. $bottomDecoration = $this->element->getDijitParam('bottomDecoration');
  226. $test = $this->element->getBottomDecoration();
  227. $this->assertSame($bottomDecoration, $test);
  228. $this->assertTrue(array_key_exists('dijit', $bottomDecoration));
  229. $this->assertEquals('HorizontalRule', $bottomDecoration['dijit']);
  230. }
  231. public function testSettingBottomDecorationContainerShouldProxyToBottomDecorationDijitParam()
  232. {
  233. $this->element->setBottomDecorationContainer('bottom');
  234. $this->assertTrue($this->element->hasDijitParam('bottomDecoration'));
  235. $bottomDecoration = $this->element->getDijitParam('bottomDecoration');
  236. $test = $this->element->getBottomDecoration();
  237. $this->assertSame($bottomDecoration, $test);
  238. $this->assertTrue(array_key_exists('container', $bottomDecoration));
  239. $this->assertEquals('bottom', $bottomDecoration['container']);
  240. }
  241. public function testSettingBottomDecorationLabelsShouldProxyToBottomDecorationDijitParam()
  242. {
  243. $labels = array('0%', '50%', '100%');
  244. $this->element->setBottomDecorationLabels($labels);
  245. $this->assertTrue($this->element->hasDijitParam('bottomDecoration'));
  246. $bottomDecoration = $this->element->getDijitParam('bottomDecoration');
  247. $test = $this->element->getBottomDecoration();
  248. $this->assertSame($bottomDecoration, $test);
  249. $this->assertTrue(array_key_exists('labels', $bottomDecoration));
  250. $this->assertSame($labels, $bottomDecoration['labels']);
  251. }
  252. public function testSettingBottomDecorationParamsShouldProxyToBottomDecorationDijitParam()
  253. {
  254. $params = array(
  255. 'container' => array(
  256. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  257. ),
  258. 'list' => array(
  259. 'style' => 'height:1em; font-size=75%;color:gray;',
  260. ),
  261. );
  262. $this->element->setBottomDecorationParams($params);
  263. $this->assertTrue($this->element->hasDijitParam('bottomDecoration'));
  264. $bottomDecoration = $this->element->getDijitParam('bottomDecoration');
  265. $test = $this->element->getBottomDecoration();
  266. $this->assertSame($bottomDecoration, $test);
  267. $this->assertTrue(array_key_exists('params', $bottomDecoration));
  268. $this->assertSame($params, $bottomDecoration['params']);
  269. }
  270. public function testSettingBottomDecorationAttribsShouldProxyToBottomDecorationDijitParam()
  271. {
  272. $attribs = array(
  273. 'container' => array(
  274. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  275. ),
  276. 'list' => array(
  277. 'style' => 'height:1em; font-size=75%;color:gray;',
  278. ),
  279. );
  280. $this->element->setBottomDecorationAttribs($attribs);
  281. $this->assertTrue($this->element->hasDijitParam('bottomDecoration'));
  282. $bottomDecoration = $this->element->getDijitParam('bottomDecoration');
  283. $test = $this->element->getBottomDecoration();
  284. $this->assertSame($bottomDecoration, $test);
  285. $this->assertTrue(array_key_exists('attribs', $bottomDecoration));
  286. $this->assertSame($attribs, $bottomDecoration['attribs']);
  287. }
  288. public function testShouldRenderHorizontalSliderDijit()
  289. {
  290. $this->element->setMinimum(-10)
  291. ->setMaximum(10)
  292. ->setDiscreteValues(11);
  293. $html = $this->element->render();
  294. $this->assertContains('dojoType="dijit.form.HorizontalSlider"', $html);
  295. }
  296. }
  297. // Call Zend_Dojo_Form_Element_HorizontalSliderTest::main() if this source file is executed directly.
  298. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_HorizontalSliderTest::main") {
  299. Zend_Dojo_Form_Element_HorizontalSliderTest::main();
  300. }