VerticalSliderTest.php 10 KB

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