HorizontalSliderTest.php 13 KB

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