InArrayTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_InArray
  28. */
  29. require_once 'Zend/Validate/InArray.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_InArrayTest 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. $validator = new Zend_Validate_InArray(array(1, 'a', 2.3));
  47. $this->assertTrue($validator->isValid(1));
  48. $this->assertTrue($validator->isValid(1.0));
  49. $this->assertTrue($validator->isValid('1'));
  50. $this->assertTrue($validator->isValid('a'));
  51. $this->assertFalse($validator->isValid('A'));
  52. $this->assertTrue($validator->isValid(2.3));
  53. $this->assertTrue($validator->isValid(2.3e0));
  54. }
  55. /**
  56. * Ensures that getMessages() returns expected default value
  57. *
  58. * @return void
  59. */
  60. public function testGetMessages()
  61. {
  62. $validator = new Zend_Validate_InArray(array(1, 2, 3));
  63. $this->assertEquals(array(), $validator->getMessages());
  64. }
  65. /**
  66. * Ensures that getHaystack() returns expected value
  67. *
  68. * @return void
  69. */
  70. public function testGetHaystack()
  71. {
  72. $validator = new Zend_Validate_InArray(array(1, 2, 3));
  73. $this->assertEquals(array(1, 2, 3), $validator->getHaystack());
  74. }
  75. /**
  76. * Ensures that getStrict() returns expected default value
  77. *
  78. * @return void
  79. */
  80. public function testGetStrict()
  81. {
  82. $validator = new Zend_Validate_InArray(array(1, 2, 3));
  83. $this->assertEquals(false, $validator->getStrict());
  84. }
  85. }