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