VerticalSliderTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_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. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_View_Helper_VerticalSlider */
  28. require_once 'Zend/Dojo/View/Helper/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_View_Helper_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_View
  45. */
  46. class Zend_Dojo_View_Helper_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_View_Helper_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->helper = new Zend_Dojo_View_Helper_VerticalSlider();
  70. $this->helper->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. return $this->helper->verticalSlider(
  91. 'elementId',
  92. '',
  93. array(
  94. 'minimum' => -10,
  95. 'maximum' => 10,
  96. 'discreteValues' => 11,
  97. 'topDecoration' => array(
  98. 'labels' => array(
  99. ' ',
  100. '20%',
  101. '40%',
  102. '60%',
  103. '80%',
  104. ' ',
  105. ),
  106. 'attribs' => array(
  107. 'container' => array(
  108. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  109. ),
  110. 'labels' => array(
  111. 'style' => 'height:1em; font-size=75%;color:gray;',
  112. ),
  113. ),
  114. 'dijit' => 'VerticalRuleLabels',
  115. ),
  116. 'bottomDecoration' => array(
  117. 'labels' => array(
  118. '0%',
  119. '50%',
  120. '100%',
  121. ),
  122. 'attribs' => array(
  123. 'labels' => array(
  124. 'style' => 'height:1em; font-size=75%;color:gray;',
  125. ),
  126. ),
  127. ),
  128. 'leftDecoration' => array(
  129. 'labels' => array(
  130. ' ',
  131. '20%',
  132. '40%',
  133. '60%',
  134. '80%',
  135. ' ',
  136. ),
  137. 'attribs' => array(
  138. 'container' => array(
  139. 'style' => 'height:1.2em; font-size=75%;color:gray;',
  140. ),
  141. 'labels' => array(
  142. 'style' => 'height:1em; font-size=75%;color:gray;',
  143. ),
  144. ),
  145. 'dijit' => 'VerticalRuleLabels',
  146. ),
  147. 'rightDecoration' => array(
  148. 'labels' => array(
  149. '0%',
  150. '50%',
  151. '100%',
  152. ),
  153. 'attribs' => array(
  154. 'labels' => array(
  155. 'style' => 'height:1em; font-size=75%;color:gray;',
  156. ),
  157. ),
  158. ),
  159. ),
  160. array()
  161. );
  162. }
  163. public function testShouldAllowDeclarativeDijitCreation()
  164. {
  165. $html = $this->getElement();
  166. $this->assertRegexp('/<div[^>]*(dojoType="dijit.form.VerticalSlider")/', $html, $html);
  167. }
  168. public function testShouldAllowProgrammaticDijitCreation()
  169. {
  170. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  171. $html = $this->getElement();
  172. $this->assertNotRegexp('/<div[^>]*(dojoType="dijit.form.VerticalSlider")/', $html);
  173. $this->assertNotNull($this->view->dojo()->getDijit('elementId-slider'));
  174. }
  175. public function testShouldCreateOnChangeAttributeByDefault()
  176. {
  177. $html = $this->getElement();
  178. $this->assertContains('onChange="dojo.byId(\'elementId\').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. }