BetweenTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2010 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-2010 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(array('min' => $element[0], 'max' => $element[1], 'inclusive' => $element[2]));
  64. foreach ($element[4] as $input) {
  65. $this->assertEquals($element[3], $validator->isValid($input),
  66. 'Failed values: ' . $input . ":" . implode("\n", $validator->getMessages()));
  67. }
  68. }
  69. }
  70. /**
  71. * Ensures that getMessages() returns expected default value
  72. *
  73. * @return void
  74. */
  75. public function testGetMessages()
  76. {
  77. $validator = new Zend_Validate_Between(array('min' => 1, 'max' => 10));
  78. $this->assertEquals(array(), $validator->getMessages());
  79. }
  80. /**
  81. * Ensures that getMin() returns expected value
  82. *
  83. * @return void
  84. */
  85. public function testGetMin()
  86. {
  87. $validator = new Zend_Validate_Between(array('min' => 1, 'max' => 10));
  88. $this->assertEquals(1, $validator->getMin());
  89. }
  90. /**
  91. * Ensures that getMax() returns expected value
  92. *
  93. * @return void
  94. */
  95. public function testGetMax()
  96. {
  97. $validator = new Zend_Validate_Between(array('min' => 1, 'max' => 10));
  98. $this->assertEquals(10, $validator->getMax());
  99. }
  100. /**
  101. * Ensures that getInclusive() returns expected default value
  102. *
  103. * @return void
  104. */
  105. public function testGetInclusive()
  106. {
  107. $validator = new Zend_Validate_Between(array('min' => 1, 'max' => 10));
  108. $this->assertEquals(true, $validator->getInclusive());
  109. }
  110. }