BetweenTest.php 3.4 KB

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