2
0

NotEmptyTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // 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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Validate
  41. */
  42. class Zend_Validate_NotEmptyTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_Validate_NotEmptyTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Zend_Validate_NotEmpty object
  56. *
  57. * @var Zend_Validate_NotEmpty
  58. */
  59. protected $_validator;
  60. /**
  61. * Creates a new Zend_Validate_NotEmpty object for each test method
  62. *
  63. * @return void
  64. */
  65. public function setUp()
  66. {
  67. $this->_validator = new Zend_Validate_NotEmpty();
  68. }
  69. /**
  70. * Ensures that the validator follows expected behavior
  71. *
  72. * ZF-6708 introduces a change for validating integer 0; it is a valid
  73. * integer value. '0' is also valid.
  74. *
  75. * @group ZF-6708
  76. * @return void
  77. */
  78. public function testBasic()
  79. {
  80. $valuesExpected = array(
  81. array('word', true),
  82. array('', false),
  83. array(' ', false),
  84. array(' word ', true),
  85. array('0', true),
  86. array(1, true),
  87. array(0, true),
  88. array(true, true),
  89. array(false, false),
  90. array(null, false),
  91. array(array(), false),
  92. array(array(5), true),
  93. );
  94. foreach ($valuesExpected as $i => $element) {
  95. $this->assertEquals($element[1], $this->_validator->isValid($element[0]),
  96. "Failed test #$i");
  97. }
  98. }
  99. /**
  100. * @see ZF-3236
  101. */
  102. public function testStringWithZeroShouldNotBeTreatedAsEmpty()
  103. {
  104. $this->assertTrue($this->_validator->isValid('0'));
  105. }
  106. /**
  107. * Ensures that getMessages() returns expected default value
  108. *
  109. * @return void
  110. */
  111. public function testGetMessages()
  112. {
  113. $this->assertEquals(array(), $this->_validator->getMessages());
  114. }
  115. /**
  116. * @ZF-4352
  117. */
  118. public function testNonStringValidation()
  119. {
  120. $v2 = new Zend_Validate_NotEmpty();
  121. $this->assertFalse($this->_validator->isValid($v2));
  122. }
  123. }
  124. // Call Zend_Validate_NotEmptyTest::main() if this source file is executed directly.
  125. if (PHPUnit_MAIN_METHOD == "Zend_Validate_NotEmptyTest::main") {
  126. Zend_Validate_NotEmptyTest::main();
  127. }