NotEmptyTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // Call Zend_Validate_NotEmptyTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Validate_NotEmptyTest::main");
  25. }
  26. /**
  27. * Test helper
  28. */
  29. require_once dirname(__FILE__) . '/../../TestHelper.php';
  30. /**
  31. * @see Zend_Validate_NotEmpty
  32. */
  33. require_once 'Zend/Validate/NotEmpty.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Validate
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Validate_NotEmptyTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_Validate_NotEmptyTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Zend_Validate_NotEmpty object
  55. *
  56. * @var Zend_Validate_NotEmpty
  57. */
  58. protected $_validator;
  59. /**
  60. * Creates a new Zend_Validate_NotEmpty object for each test method
  61. *
  62. * @return void
  63. */
  64. public function setUp()
  65. {
  66. $this->_validator = new Zend_Validate_NotEmpty();
  67. }
  68. /**
  69. * Ensures that the validator follows expected behavior
  70. *
  71. * @return void
  72. */
  73. public function testBasic()
  74. {
  75. $valuesExpected = array(
  76. array('word', true),
  77. array('', false),
  78. array(' ', false),
  79. array(' word ', true),
  80. array(1, true),
  81. array(0, false),
  82. array(true, true),
  83. array(false, false),
  84. array(null, false),
  85. );
  86. foreach ($valuesExpected as $i => $element) {
  87. $this->assertEquals($element[1], $this->_validator->isValid($element[0]),
  88. "Failed test #$i");
  89. }
  90. }
  91. /**
  92. * @see ZF-3236
  93. */
  94. public function testStringWithZeroShouldNotBeTreatedAsEmpty()
  95. {
  96. $this->assertTrue($this->_validator->isValid('0'));
  97. }
  98. /**
  99. * Ensures that getMessages() returns expected default value
  100. *
  101. * @return void
  102. */
  103. public function testGetMessages()
  104. {
  105. $this->assertEquals(array(), $this->_validator->getMessages());
  106. }
  107. /**
  108. * @ZF-4352
  109. */
  110. public function testNonStringValidation()
  111. {
  112. $this->assertFalse($this->_validator->isValid(array(1 => 1)));
  113. }
  114. }
  115. // Call Zend_Validate_NotEmptyTest::main() if this source file is executed directly.
  116. if (PHPUnit_MAIN_METHOD == "Zend_Validate_NotEmptyTest::main") {
  117. Zend_Validate_NotEmptyTest::main();
  118. }