TimeTextBoxTest.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_Form_Element_TimeTextBoxTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_TimeTextBoxTest::main");
  25. }
  26. /** Zend_Dojo_Form_Element_TimeTextBox */
  27. require_once 'Zend/Dojo/Form/Element/TimeTextBox.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_Form_Element_TimeTextBox.
  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_Form
  44. */
  45. class Zend_Dojo_Form_Element_TimeTextBoxTest 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_Form_Element_TimeTextBoxTest");
  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->element = $this->getElement();
  69. $this->element->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. $element = new Zend_Dojo_Form_Element_TimeTextBox(
  90. 'foo',
  91. array(
  92. 'value' => 'some text',
  93. 'label' => 'TimeTextBox',
  94. 'class' => 'someclass',
  95. 'style' => 'width: 100px;',
  96. )
  97. );
  98. return $element;
  99. }
  100. public function testShouldExtendDateTextBox()
  101. {
  102. $this->assertTrue($this->element instanceof Zend_Dojo_Form_Element_DateTextBox);
  103. }
  104. public function testTimePatternAccessorsShouldProxyToConstraints()
  105. {
  106. $this->assertNull($this->element->getTimePattern());
  107. $this->assertFalse($this->element->hasConstraint('timePattern'));
  108. $this->element->setTimePattern('h:mm a');
  109. $this->assertEquals('h:mm a', $this->element->getTimePattern());
  110. $this->assertTrue($this->element->hasConstraint('timePattern'));
  111. $this->assertEquals('h:mm a', $this->element->dijitParams['constraints']['timePattern']);
  112. }
  113. public function testClickableIncrementAccessorsShouldProxyToConstraints()
  114. {
  115. $this->assertNull($this->element->getClickableIncrement());
  116. $this->assertFalse($this->element->hasConstraint('clickableIncrement'));
  117. $this->element->setClickableIncrement('T00:15:00');
  118. $this->assertEquals('T00:15:00', $this->element->getClickableIncrement());
  119. $this->assertTrue($this->element->hasConstraint('clickableIncrement'));
  120. $this->assertEquals('T00:15:00', $this->element->dijitParams['constraints']['clickableIncrement']);
  121. }
  122. /**
  123. * @expectedException Zend_Form_Element_Exception
  124. */
  125. public function testClickableIncrementMutatorShouldRaiseExceptionOnInvalidFormat()
  126. {
  127. $this->element->setClickableIncrement('en-US');
  128. }
  129. public function testVisibleIncrementAccessorsShouldProxyToDijitParams()
  130. {
  131. $this->assertNull($this->element->getVisibleIncrement());
  132. $this->assertFalse($this->element->hasConstraint('visibleIncrement'));
  133. $this->element->setVisibleIncrement('T00:15:00');
  134. $this->assertEquals('T00:15:00', $this->element->getVisibleIncrement());
  135. $this->assertTrue($this->element->hasConstraint('visibleIncrement'));
  136. $this->assertEquals('T00:15:00', $this->element->dijitParams['constraints']['visibleIncrement']);
  137. }
  138. /**
  139. * @expectedException Zend_Form_Element_Exception
  140. */
  141. public function testVisibleIncrementMutatorShouldRaiseExceptionOnInvalidFormat()
  142. {
  143. $this->element->setVisibleIncrement('en-US');
  144. }
  145. public function testVisibleRangeAccessorsShouldProxyToDijitParams()
  146. {
  147. $this->assertNull($this->element->getVisibleRange());
  148. $this->assertFalse($this->element->hasConstraint('visibleRange'));
  149. $this->element->setVisibleRange('T00:15:00');
  150. $this->assertEquals('T00:15:00', $this->element->getVisibleRange());
  151. $this->assertTrue($this->element->hasConstraint('visibleRange'));
  152. $this->assertEquals('T00:15:00', $this->element->dijitParams['constraints']['visibleRange']);
  153. }
  154. /**
  155. * @expectedException Zend_Form_Element_Exception
  156. */
  157. public function testVisibleRangeMutatorShouldRaiseExceptionOnInvalidFormat()
  158. {
  159. $this->element->setVisibleRange('en-US');
  160. }
  161. public function testShouldRenderTimeTextBoxDijit()
  162. {
  163. $html = $this->element->render();
  164. $this->assertContains('dojoType="dijit.form.TimeTextBox"', $html);
  165. }
  166. /**
  167. * @group ZF-7813
  168. */
  169. public function testCanSetValue()
  170. {
  171. $this->element->setValue('T08:00');
  172. $html = $this->element->render();
  173. $this->assertSame('T08:00', $this->element->getValue());
  174. $this->assertContains('value="T08:00"', $html);
  175. }
  176. }
  177. // Call Zend_Dojo_Form_Element_TimeTextBoxTest::main() if this source file is executed directly.
  178. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_TimeTextBoxTest::main") {
  179. Zend_Dojo_Form_Element_TimeTextBoxTest::main();
  180. }