BetweenTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_Validate
  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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * @see Zend_Validate_Between
  28. */
  29. require_once 'Zend/Validate/Between.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Validate
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Validate
  37. */
  38. class Zend_Validate_BetweenTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Ensures that the validator follows expected behavior
  42. *
  43. * @return void
  44. */
  45. public function testBasic()
  46. {
  47. /**
  48. * The elements of each array are, in order:
  49. * - minimum
  50. * - maximum
  51. * - inclusive
  52. * - expected validation result
  53. * - array of test input values
  54. */
  55. $valuesExpected = array(
  56. array(1, 100, true, true, array(1, 10, 100)),
  57. array(1, 100, true, false, array(0, 0.99, 100.01, 101)),
  58. array(1, 100, false, false, array(0, 1, 100, 101)),
  59. array('a', 'z', true, true, array('a', 'b', 'y', 'z')),
  60. array('a', 'z', false, false, array('!', 'a', 'z'))
  61. );
  62. foreach ($valuesExpected as $element) {
  63. $validator = new Zend_Validate_Between($element[0], $element[1], $element[2]);
  64. foreach ($element[4] as $input) {
  65. $this->assertEquals($element[3], $validator->isValid($input));
  66. }
  67. }
  68. }
  69. /**
  70. * Ensures that getMessages() returns expected default value
  71. *
  72. * @return void
  73. */
  74. public function testGetMessages()
  75. {
  76. $validator = new Zend_Validate_Between(1, 10);
  77. $this->assertEquals(array(), $validator->getMessages());
  78. }
  79. /**
  80. * Ensures that getMin() returns expected value
  81. *
  82. * @return void
  83. */
  84. public function testGetMin()
  85. {
  86. $validator = new Zend_Validate_Between(1, 10);
  87. $this->assertEquals(1, $validator->getMin());
  88. }
  89. /**
  90. * Ensures that getMax() returns expected value
  91. *
  92. * @return void
  93. */
  94. public function testGetMax()
  95. {
  96. $validator = new Zend_Validate_Between(1, 10);
  97. $this->assertEquals(10, $validator->getMax());
  98. }
  99. /**
  100. * Ensures that getInclusive() returns expected default value
  101. *
  102. * @return void
  103. */
  104. public function testGetInclusive()
  105. {
  106. $validator = new Zend_Validate_Between(1, 10);
  107. $this->assertEquals(true, $validator->getInclusive());
  108. }
  109. }