DateTextBoxTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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-2012 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_DateTextBoxTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_DateTextBoxTest::main");
  25. }
  26. /** Zend_Dojo_Form_Element_DateTextBox */
  27. require_once 'Zend/Dojo/Form/Element/DateTextBox.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_DateTextBox.
  36. *
  37. * @category Zend
  38. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2012 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_DateTextBoxTest 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_DateTextBoxTest");
  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_DateTextBox(
  90. 'foo',
  91. array(
  92. 'value' => 'some text',
  93. 'label' => 'DateTextBox',
  94. 'class' => 'someclass',
  95. 'style' => 'width: 100px;',
  96. )
  97. );
  98. return $element;
  99. }
  100. public function testAmPmAccessorsShouldProxyToConstraints()
  101. {
  102. $this->assertFalse($this->element->getAmPm());
  103. $constraints = $this->element->getConstraints();
  104. $this->assertFalse(array_key_exists('am,pm', $constraints));
  105. $this->element->setAmPm(true);
  106. $this->assertTrue($this->element->getAmPm());
  107. $constraints = $this->element->getConstraints();
  108. $this->assertTrue(array_key_exists('am,pm', $constraints));
  109. $this->assertEquals('true', $this->element->dijitParams['constraints']['am,pm']);
  110. }
  111. public function testStrictAccessorsShouldProxyToConstraints()
  112. {
  113. $this->assertFalse($this->element->getStrict());
  114. $constraints = $this->element->getConstraints();
  115. $this->assertFalse(array_key_exists('strict', $constraints));
  116. $this->element->setStrict(true);
  117. $this->assertTrue($this->element->getStrict());
  118. $constraints = $this->element->getConstraints();
  119. $this->assertTrue(array_key_exists('strict', $constraints));
  120. $this->assertEquals('true', $this->element->dijitParams['constraints']['strict']);
  121. }
  122. public function testLocaleAccessorsShouldProxyToConstraints()
  123. {
  124. $this->assertNull($this->element->getLocale());
  125. $constraints = $this->element->getConstraints();
  126. $this->assertFalse(array_key_exists('locale', $constraints));
  127. $this->element->setLocale('en-US');
  128. $this->assertEquals('en-US', $this->element->getLocale());
  129. $constraints = $this->element->getConstraints();
  130. $this->assertEquals('en-US', $this->element->dijitParams['constraints']['locale']);
  131. }
  132. public function testFormatLengthAccessorsShouldProxyToConstraints()
  133. {
  134. $this->assertNull($this->element->getFormatLength());
  135. $constraints = $this->element->getConstraints();
  136. $this->assertFalse(array_key_exists('formatLength', $constraints));
  137. $this->element->setFormatLength('long');
  138. $this->assertEquals('long', $this->element->getFormatLength());
  139. $constraints = $this->element->getConstraints();
  140. $this->assertEquals('long', $this->element->dijitParams['constraints']['formatLength']);
  141. }
  142. /**
  143. * @expectedException Zend_Form_Element_Exception
  144. */
  145. public function testFormatLengthMutatorShouldThrowExceptionWithInvalidFormatLength()
  146. {
  147. $this->element->setFormatLength('foobar');
  148. }
  149. public function testSelectorAccessorsShouldProxyToConstraints()
  150. {
  151. $this->assertNull($this->element->getSelector());
  152. $constraints = $this->element->getConstraints();
  153. $this->assertFalse(array_key_exists('selector', $constraints));
  154. $this->element->setSelector('time');
  155. $this->assertEquals('time', $this->element->getSelector());
  156. $constraints = $this->element->getConstraints();
  157. $this->assertEquals('time', $this->element->dijitParams['constraints']['selector']);
  158. }
  159. /**
  160. * @expectedException Zend_Form_Element_Exception
  161. */
  162. public function testSelectorMutatorShouldThrowExceptionWithInvalidSelector()
  163. {
  164. $this->element->setSelector('foobar');
  165. }
  166. public function testDatePatternAccessorsShouldProxyToConstraints()
  167. {
  168. $this->assertNull($this->element->getDatePattern());
  169. $this->assertFalse($this->element->hasConstraint('datePattern'));
  170. $this->element->setDatePattern('EEE, MMM d, Y');
  171. $this->assertEquals('EEE, MMM d, Y', $this->element->getDatePattern());
  172. $this->assertEquals('EEE, MMM d, Y', $this->element->dijitParams['constraints']['datePattern']);
  173. }
  174. public function testShouldRenderDateTextBoxDijit()
  175. {
  176. $html = $this->element->render();
  177. $this->assertContains('dojoType="dijit.form.DateTextBox"', $html);
  178. }
  179. /**
  180. * @group ZF-7813
  181. */
  182. public function testCanSetValue()
  183. {
  184. $this->element->setValue('2011-05-10');
  185. $html = $this->element->render();
  186. $this->assertSame('2011-05-10', $this->element->getValue());
  187. $this->assertContains('value="2011-05-10"', $html);
  188. }
  189. }
  190. // Call Zend_Dojo_Form_Element_DateTextBoxTest::main() if this source file is executed directly.
  191. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_DateTextBoxTest::main") {
  192. Zend_Dojo_Form_Element_DateTextBoxTest::main();
  193. }