VerticalSliderTest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_View_Helper_VerticalSliderTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_View_Helper_VerticalSliderTest::main");
  25. }
  26. /** Zend_Dojo_View_Helper_VerticalSlider */
  27. require_once 'Zend/Dojo/View/Helper/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_View_Helper_VerticalSlider.
  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_View
  44. */
  45. class Zend_Dojo_View_Helper_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_View_Helper_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->helper = new Zend_Dojo_View_Helper_VerticalSlider();
  69. $this->helper->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. return $this->helper->verticalSlider(
  90. 'elementId',
  91. '',
  92. array(
  93. 'minimum' => -10,
  94. 'maximum' => 10,
  95. 'discreteValues' => 11,
  96. 'topDecoration' => array(
  97. 'labels' => array(
  98. ' ',
  99. '20%',
  100. '40%',
  101. '60%',
  102. '80%',
  103. ' ',
  104. ),
  105. 'attribs' => array(
  106. 'container' => array(
  107. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  108. ),
  109. 'labels' => array(
  110. 'style' => 'height:1em; font-size=75%;color:gray;',
  111. ),
  112. ),
  113. 'dijit' => 'VerticalRuleLabels',
  114. ),
  115. 'bottomDecoration' => array(
  116. 'labels' => array(
  117. '0%',
  118. '50%',
  119. '100%',
  120. ),
  121. 'attribs' => array(
  122. 'labels' => array(
  123. 'style' => 'height:1em; font-size=75%;color:gray;',
  124. ),
  125. ),
  126. ),
  127. 'leftDecoration' => array(
  128. 'labels' => array(
  129. ' ',
  130. '20%',
  131. '40%',
  132. '60%',
  133. '80%',
  134. ' ',
  135. ),
  136. 'attribs' => array(
  137. 'container' => array(
  138. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  139. ),
  140. 'labels' => array(
  141. 'style' => 'height:1em; font-size=75%;color:gray;',
  142. ),
  143. ),
  144. 'dijit' => 'VerticalRuleLabels',
  145. ),
  146. 'rightDecoration' => array(
  147. 'labels' => array(
  148. '0%',
  149. '50%',
  150. '100%',
  151. ),
  152. 'attribs' => array(
  153. 'labels' => array(
  154. 'style' => 'height:1em; font-size=75%;color:gray;',
  155. ),
  156. ),
  157. ),
  158. ),
  159. array()
  160. );
  161. }
  162. public function testShouldAllowDeclarativeDijitCreation()
  163. {
  164. $html = $this->getElement();
  165. $this->assertRegexp('/<div[^>]*(dojoType="dijit.form.VerticalSlider")/', $html, $html);
  166. }
  167. public function testShouldAllowProgrammaticDijitCreation()
  168. {
  169. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  170. $html = $this->getElement();
  171. $this->assertNotRegexp('/<div[^>]*(dojoType="dijit.form.VerticalSlider")/', $html);
  172. $this->assertNotNull($this->view->dojo()->getDijit('elementId-slider'));
  173. }
  174. public function testShouldCreateOnChangeAttributeByDefault()
  175. {
  176. $html = $this->getElement();
  177. // Note that ' is converted to &#39; in Zend_View_Helper_HtmlElement::_htmlAttribs() (line 116)
  178. $this->assertContains('onChange="dojo.byId(&#39;elementId&#39;).value = arguments[0];"', $html, $html);
  179. }
  180. public function testShouldCreateHiddenElementWithValue()
  181. {
  182. $html = $this->getElement();
  183. if (!preg_match('/(<input[^>]*(type="hidden")[^>]*>)/', $html, $m)) {
  184. $this->fail('No hidden element found');
  185. }
  186. $this->assertContains('id="elementId"', $m[1]);
  187. $this->assertContains('value="', $m[1]);
  188. }
  189. public function testShouldCreateLeftAndRightDecorationsWhenRequested()
  190. {
  191. $html = $this->getElement();
  192. $this->assertRegexp('/<div[^>]*(dojoType="dijit.form.VerticalRule")/', $html, $html);
  193. $this->assertRegexp('/<ol[^>]*(dojoType="dijit.form.VerticalRuleLabels")/', $html, $html);
  194. $this->assertContains('leftDecoration', $html);
  195. $this->assertContains('rightDecoration', $html);
  196. }
  197. public function testShouldIgnoreTopAndBottomDecorationsWhenPassed()
  198. {
  199. $html = $this->getElement();
  200. $this->assertNotContains('topDecoration', $html);
  201. $this->assertNotContains('bottomDecoration', $html);
  202. }
  203. }
  204. // Call Zend_Dojo_View_Helper_VerticalSliderTest::main() if this source file is executed directly.
  205. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_VerticalSliderTest::main") {
  206. Zend_Dojo_View_Helper_VerticalSliderTest::main();
  207. }