NumberSpinnerTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_NumberSpinnerTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_NumberSpinnerTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_Form_Element_NumberSpinner */
  28. require_once 'Zend/Dojo/Form/Element/NumberSpinner.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-2009 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_NumberSpinnerTest 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_NumberSpinnerTest");
  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_NumberSpinner(
  88. 'foo',
  89. array(
  90. 'value' => 'some text',
  91. 'label' => 'NumberSpinner',
  92. 'class' => 'someclass',
  93. 'style' => 'width: 100px;',
  94. )
  95. );
  96. return $element;
  97. }
  98. public function testDefaultTimeoutAccessorsShouldProxyToDijitParams()
  99. {
  100. $this->assertNull($this->element->getDefaultTimeout());
  101. $this->assertFalse(array_key_exists('defaultTimeout', $this->element->dijitParams));
  102. $this->element->setDefaultTimeout(20);
  103. $this->assertEquals(20, $this->element->getDefaultTimeout());
  104. $this->assertEquals(20, $this->element->dijitParams['defaultTimeout']);
  105. }
  106. public function testTimeoutChangeRateAccessorsShouldProxyToDijitParams()
  107. {
  108. $this->assertNull($this->element->getTimeoutChangeRate());
  109. $this->assertFalse(array_key_exists('timeoutChangeRate', $this->element->dijitParams));
  110. $this->element->setTimeoutChangeRate(20);
  111. $this->assertEquals(20, $this->element->getTimeoutChangeRate());
  112. $this->assertEquals(20, $this->element->dijitParams['timeoutChangeRate']);
  113. }
  114. public function testLargeDeltaAccessorsShouldProxyToDijitParams()
  115. {
  116. $this->assertNull($this->element->getLargeDelta());
  117. $this->assertFalse(array_key_exists('largeDelta', $this->element->dijitParams));
  118. $this->element->setLargeDelta(20);
  119. $this->assertEquals(20, $this->element->getLargeDelta());
  120. $this->assertEquals(20, $this->element->dijitParams['largeDelta']);
  121. }
  122. public function testSmallDeltaAccessorsShouldProxyToDijitParams()
  123. {
  124. $this->assertNull($this->element->getSmallDelta());
  125. $this->assertFalse(array_key_exists('smallDelta', $this->element->dijitParams));
  126. $this->element->setSmallDelta(20);
  127. $this->assertEquals(20, $this->element->getSmallDelta());
  128. $this->assertEquals(20, $this->element->dijitParams['smallDelta']);
  129. }
  130. public function testIntermediateChangesAccessorsShouldProxyToDijitParams()
  131. {
  132. $this->assertFalse($this->element->getIntermediateChanges());
  133. $this->assertFalse(array_key_exists('intermediateChanges', $this->element->dijitParams));
  134. $this->element->setIntermediateChanges(true);
  135. $this->assertTrue($this->element->getIntermediateChanges());
  136. $this->assertTrue($this->element->dijitParams['intermediateChanges']);
  137. }
  138. public function testRangeMessageAccessorsShouldProxyToDijitParams()
  139. {
  140. $this->assertNull($this->element->getRangeMessage());
  141. $this->assertFalse(array_key_exists('rangeMessage', $this->element->dijitParams));
  142. $this->element->setRangeMessage('foo');
  143. $this->assertEquals('foo', $this->element->getRangeMessage());
  144. $this->assertEquals('foo', $this->element->dijitParams['rangeMessage']);
  145. }
  146. public function testMinAccessorsShouldProxyToConstraintsDijitParam()
  147. {
  148. $this->assertNull($this->element->getMin());
  149. $this->assertFalse(array_key_exists('constraints', $this->element->dijitParams));
  150. $this->element->setMin(5);
  151. $this->assertEquals(5, $this->element->getMin());
  152. $this->assertEquals(5, $this->element->dijitParams['constraints']['min']);
  153. }
  154. public function testMaxAccessorsShouldProxyToConstraintsDijitParam()
  155. {
  156. $this->assertNull($this->element->getMax());
  157. $this->assertFalse(array_key_exists('constraints', $this->element->dijitParams));
  158. $this->element->setMax(5);
  159. $this->assertEquals(5, $this->element->getMax());
  160. $this->assertEquals(5, $this->element->dijitParams['constraints']['max']);
  161. }
  162. public function testShouldRenderNumberSpinnerDijit()
  163. {
  164. $html = $this->element->render();
  165. $this->assertContains('dojoType="dijit.form.NumberSpinner"', $html);
  166. }
  167. /**
  168. * @group ZF-4638
  169. */
  170. public function testRenderingShouldOutputMinAndMaxConstraints()
  171. {
  172. $this->element->setMin(5)
  173. ->setMax(10);
  174. $html = $this->element->render();
  175. $this->assertRegexp('/\'min\':\s*5/', $html, $html);
  176. $this->assertRegexp('/\'max\':\s*10/', $html, $html);
  177. }
  178. }
  179. // Call Zend_Dojo_Form_Element_NumberSpinnerTest::main() if this source file is executed directly.
  180. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_NumberSpinnerTest::main") {
  181. Zend_Dojo_Form_Element_NumberSpinnerTest::main();
  182. }