VerticalSliderTest.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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-2012 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_VerticalSliderTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_VerticalSliderTest::main");
  25. }
  26. /** Zend_Dojo_Form_Element_VerticalSlider */
  27. require_once 'Zend/Dojo/Form/Element/VerticalSlider.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_VerticalSlider.
  36. *
  37. * @category Zend
  38. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2012 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_VerticalSliderTest 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_VerticalSliderTest");
  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_VerticalSlider(
  90. 'foo',
  91. array(
  92. 'value' => 'some text',
  93. 'label' => 'VerticalSlider',
  94. 'class' => 'someclass',
  95. 'style' => 'width: 100px;',
  96. )
  97. );
  98. return $element;
  99. }
  100. public function testSettingLeftDecorationDijitShouldProxyToLeftDecorationDijitParam()
  101. {
  102. $this->element->setLeftDecorationDijit('VerticalRule');
  103. $this->assertTrue($this->element->hasDijitParam('leftDecoration'));
  104. $leftDecoration = $this->element->getDijitParam('leftDecoration');
  105. $test = $this->element->getLeftDecoration();
  106. $this->assertSame($leftDecoration, $test);
  107. $this->assertTrue(array_key_exists('dijit', $leftDecoration));
  108. $this->assertEquals('VerticalRule', $leftDecoration['dijit']);
  109. }
  110. public function testSettingLeftDecorationContainerShouldProxyToLeftDecorationDijitParam()
  111. {
  112. $this->element->setLeftDecorationContainer('left');
  113. $this->assertTrue($this->element->hasDijitParam('leftDecoration'));
  114. $leftDecoration = $this->element->getDijitParam('leftDecoration');
  115. $test = $this->element->getLeftDecoration();
  116. $this->assertSame($leftDecoration, $test);
  117. $this->assertTrue(array_key_exists('container', $leftDecoration));
  118. $this->assertEquals('left', $leftDecoration['container']);
  119. }
  120. public function testSettingLeftDecorationLabelsShouldProxyToLeftDecorationDijitParam()
  121. {
  122. $labels = array('0%', '50%', '100%');
  123. $this->element->setLeftDecorationLabels($labels);
  124. $this->assertTrue($this->element->hasDijitParam('leftDecoration'));
  125. $leftDecoration = $this->element->getDijitParam('leftDecoration');
  126. $test = $this->element->getLeftDecoration();
  127. $this->assertSame($leftDecoration, $test);
  128. $this->assertTrue(array_key_exists('labels', $leftDecoration));
  129. $this->assertSame($labels, $leftDecoration['labels']);
  130. }
  131. public function testSettingLeftDecorationParamsShouldProxyToLeftDecorationDijitParam()
  132. {
  133. $params = array(
  134. 'container' => array(
  135. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  136. ),
  137. 'list' => array(
  138. 'style' => 'height:1em; font-size=75%;color:gray;',
  139. ),
  140. );
  141. $this->element->setLeftDecorationParams($params);
  142. $this->assertTrue($this->element->hasDijitParam('leftDecoration'));
  143. $leftDecoration = $this->element->getDijitParam('leftDecoration');
  144. $test = $this->element->getLeftDecoration();
  145. $this->assertSame($leftDecoration, $test);
  146. $this->assertTrue(array_key_exists('params', $leftDecoration));
  147. $this->assertSame($params, $leftDecoration['params']);
  148. }
  149. public function testSettingLeftDecorationAttribsShouldProxyToLeftDecorationDijitParam()
  150. {
  151. $attribs = array(
  152. 'container' => array(
  153. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  154. ),
  155. 'list' => array(
  156. 'style' => 'height:1em; font-size=75%;color:gray;',
  157. ),
  158. );
  159. $this->element->setLeftDecorationAttribs($attribs);
  160. $this->assertTrue($this->element->hasDijitParam('leftDecoration'));
  161. $leftDecoration = $this->element->getDijitParam('leftDecoration');
  162. $test = $this->element->getLeftDecoration();
  163. $this->assertSame($leftDecoration, $test);
  164. $this->assertTrue(array_key_exists('attribs', $leftDecoration));
  165. $this->assertSame($attribs, $leftDecoration['attribs']);
  166. }
  167. public function testSettingRightDecorationDijitShouldProxyToRightDecorationDijitParam()
  168. {
  169. $this->element->setRightDecorationDijit('VerticalRule');
  170. $this->assertTrue($this->element->hasDijitParam('rightDecoration'));
  171. $rightDecoration = $this->element->getDijitParam('rightDecoration');
  172. $test = $this->element->getRightDecoration();
  173. $this->assertSame($rightDecoration, $test);
  174. $this->assertTrue(array_key_exists('dijit', $rightDecoration));
  175. $this->assertEquals('VerticalRule', $rightDecoration['dijit']);
  176. }
  177. public function testSettingRightDecorationContainerShouldProxyToRightDecorationDijitParam()
  178. {
  179. $this->element->setRightDecorationContainer('right');
  180. $this->assertTrue($this->element->hasDijitParam('rightDecoration'));
  181. $rightDecoration = $this->element->getDijitParam('rightDecoration');
  182. $test = $this->element->getRightDecoration();
  183. $this->assertSame($rightDecoration, $test);
  184. $this->assertTrue(array_key_exists('container', $rightDecoration));
  185. $this->assertEquals('right', $rightDecoration['container']);
  186. }
  187. public function testSettingRightDecorationLabelsShouldProxyToRightDecorationDijitParam()
  188. {
  189. $labels = array('0%', '50%', '100%');
  190. $this->element->setRightDecorationLabels($labels);
  191. $this->assertTrue($this->element->hasDijitParam('rightDecoration'));
  192. $rightDecoration = $this->element->getDijitParam('rightDecoration');
  193. $test = $this->element->getRightDecoration();
  194. $this->assertSame($rightDecoration, $test);
  195. $this->assertTrue(array_key_exists('labels', $rightDecoration));
  196. $this->assertSame($labels, $rightDecoration['labels']);
  197. }
  198. public function testSettingRightDecorationParamsShouldProxyToRightDecorationDijitParam()
  199. {
  200. $params = array(
  201. 'container' => array(
  202. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  203. ),
  204. 'list' => array(
  205. 'style' => 'height:1em; font-size=75%;color:gray;',
  206. ),
  207. );
  208. $this->element->setRightDecorationParams($params);
  209. $this->assertTrue($this->element->hasDijitParam('rightDecoration'));
  210. $rightDecoration = $this->element->getDijitParam('rightDecoration');
  211. $test = $this->element->getRightDecoration();
  212. $this->assertSame($rightDecoration, $test);
  213. $this->assertTrue(array_key_exists('params', $rightDecoration));
  214. $this->assertSame($params, $rightDecoration['params']);
  215. }
  216. public function testSettingRightDecorationAttribsShouldProxyToRightDecorationDijitParam()
  217. {
  218. $attribs = array(
  219. 'container' => array(
  220. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  221. ),
  222. 'list' => array(
  223. 'style' => 'height:1em; font-size=75%;color:gray;',
  224. ),
  225. );
  226. $this->element->setRightDecorationAttribs($attribs);
  227. $this->assertTrue($this->element->hasDijitParam('rightDecoration'));
  228. $rightDecoration = $this->element->getDijitParam('rightDecoration');
  229. $test = $this->element->getRightDecoration();
  230. $this->assertSame($rightDecoration, $test);
  231. $this->assertTrue(array_key_exists('attribs', $rightDecoration));
  232. $this->assertSame($attribs, $rightDecoration['attribs']);
  233. }
  234. public function testShouldRenderVerticalSliderDijit()
  235. {
  236. $this->element->setMinimum(-10)
  237. ->setMaximum(10)
  238. ->setDiscreteValues(11);
  239. $html = $this->element->render();
  240. $this->assertContains('dojoType="dijit.form.VerticalSlider"', $html);
  241. }
  242. }
  243. // Call Zend_Dojo_Form_Element_VerticalSliderTest::main() if this source file is executed directly.
  244. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_VerticalSliderTest::main") {
  245. Zend_Dojo_Form_Element_VerticalSliderTest::main();
  246. }