NumberTextBoxTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_NumberTextBoxTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_NumberTextBoxTest::main");
  25. }
  26. require_once 'Zend/Dojo/Form/Element/NumberTextBox.php';
  27. /** Zend_View */
  28. require_once 'Zend/View.php';
  29. /** Zend_Registry */
  30. require_once 'Zend/Registry.php';
  31. /** Zend_Dojo_View_Helper_Dojo */
  32. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  33. /**
  34. * Test class for Zend_Dojo_Form_Element_NumberTextBox.
  35. *
  36. * @category Zend
  37. * @package Zend_Dojo
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Dojo
  42. * @group Zend_Dojo_Form
  43. */
  44. class Zend_Dojo_Form_Element_NumberTextBoxTest extends PHPUnit_Framework_TestCase
  45. {
  46. /**
  47. * Runs the test methods of this class.
  48. *
  49. * @return void
  50. */
  51. public static function main()
  52. {
  53. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_NumberTextBoxTest");
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. /**
  57. * Sets up the fixture, for example, open a network connection.
  58. * This method is called before a test is executed.
  59. *
  60. * @return void
  61. */
  62. public function setUp()
  63. {
  64. Zend_Registry::_unsetInstance();
  65. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  66. $this->view = $this->getView();
  67. $this->element = $this->getElement();
  68. $this->element->setView($this->view);
  69. }
  70. /**
  71. * Tears down the fixture, for example, close a network connection.
  72. * This method is called after a test is executed.
  73. *
  74. * @return void
  75. */
  76. public function tearDown()
  77. {
  78. }
  79. public function getView()
  80. {
  81. require_once 'Zend/View.php';
  82. $view = new Zend_View();
  83. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  84. return $view;
  85. }
  86. public function getElement()
  87. {
  88. $element = new Zend_Dojo_Form_Element_NumberTextBox(
  89. 'foo',
  90. array(
  91. 'value' => 'some text',
  92. 'label' => 'NumberTextBox',
  93. 'class' => 'someclass',
  94. 'style' => 'width: 100px;',
  95. )
  96. );
  97. return $element;
  98. }
  99. public function testLocaleAccessorsShouldProxyToConstraints()
  100. {
  101. $this->assertNull($this->element->getLocale());
  102. $this->assertNull($this->element->getConstraint('locale'));
  103. $this->element->setLocale('en-US');
  104. $this->assertEquals('en-US', $this->element->getLocale());
  105. $this->assertTrue($this->element->hasConstraint('locale'));
  106. $this->assertEquals('en-US', $this->element->dijitParams['constraints']['locale']);
  107. }
  108. public function testPatternAccessorsShouldProxyToConstraints()
  109. {
  110. $this->assertNull($this->element->getPattern());
  111. $this->assertFalse($this->element->hasConstraint('pattern'));
  112. $this->element->setPattern('###0.#####');
  113. $this->assertEquals('###0.#####', $this->element->getPattern());
  114. $this->assertTrue($this->element->hasConstraint('pattern'));
  115. $this->assertEquals('###0.#####', $this->element->dijitParams['constraints']['pattern']);
  116. }
  117. public function testTypeAccessorsShouldProxyToConstraints()
  118. {
  119. $this->assertNull($this->element->getType());
  120. $this->assertFalse($this->element->hasConstraint('type'));
  121. $this->element->setType('percent');
  122. $this->assertEquals('percent', $this->element->getType());
  123. $this->assertTrue($this->element->hasConstraint('type'));
  124. $this->assertEquals('percent', $this->element->dijitParams['constraints']['type']);
  125. }
  126. /**
  127. * @expectedException Zend_Form_Element_Exception
  128. */
  129. public function testTypeMutatorShouldThrowExceptionWithInvalidType()
  130. {
  131. $this->element->setType('foobar');
  132. }
  133. public function testPlacesAccessorsShouldProxyToConstraints()
  134. {
  135. $this->assertNull($this->element->getPlaces());
  136. $this->assertFalse($this->element->hasConstraint('places'));
  137. $this->element->setPlaces(3);
  138. $this->assertEquals(3, $this->element->getPlaces());
  139. $this->assertTrue($this->element->hasConstraint('places'));
  140. $this->assertEquals(3, $this->element->dijitParams['constraints']['places']);
  141. }
  142. public function testStrictAccessorsShouldProxyToConstraints()
  143. {
  144. $this->assertFalse($this->element->getStrict());
  145. $this->assertFalse($this->element->hasConstraint('strict'));
  146. $this->element->setStrict(true);
  147. $this->assertTrue($this->element->getStrict());
  148. $this->assertTrue($this->element->hasConstraint('strict'));
  149. $this->assertEquals('true', $this->element->dijitParams['constraints']['strict']);
  150. }
  151. public function testShouldRenderNumberTextBoxDijit()
  152. {
  153. $html = $this->element->render();
  154. $this->assertContains('dojoType="dijit.form.NumberTextBox"', $html);
  155. }
  156. }
  157. // Call Zend_Dojo_Form_Element_NumberTextBoxTest::main() if this source file is executed directly.
  158. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_NumberTextBoxTest::main") {
  159. Zend_Dojo_Form_Element_NumberTextBoxTest::main();
  160. }