VerticalSliderTest.php 10 KB

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