2
0

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