HorizontalSliderTest.php 13 KB

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