NotEmptyTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * @return void
  73. */
  74. public function testBasic()
  75. {
  76. $valuesExpected = array(
  77. array('word', true),
  78. array('', false),
  79. array(' ', false),
  80. array(' word ', true),
  81. array(1, true),
  82. array(0, false),
  83. array(true, true),
  84. array(false, false),
  85. array(null, false),
  86. array(array(), false),
  87. array(array(5), true),
  88. );
  89. foreach ($valuesExpected as $i => $element) {
  90. $this->assertEquals($element[1], $this->_validator->isValid($element[0]),
  91. "Failed test #$i");
  92. }
  93. }
  94. /**
  95. * @see ZF-3236
  96. */
  97. public function testStringWithZeroShouldNotBeTreatedAsEmpty()
  98. {
  99. $this->assertTrue($this->_validator->isValid('0'));
  100. }
  101. /**
  102. * Ensures that getMessages() returns expected default value
  103. *
  104. * @return void
  105. */
  106. public function testGetMessages()
  107. {
  108. $this->assertEquals(array(), $this->_validator->getMessages());
  109. }
  110. /**
  111. * @ZF-4352
  112. */
  113. public function testNonStringValidation()
  114. {
  115. $v2 = new Zend_Validate_NotEmpty();
  116. $this->assertFalse($this->_validator->isValid($v2));
  117. }
  118. }
  119. // Call Zend_Validate_NotEmptyTest::main() if this source file is executed directly.
  120. if (PHPUnit_MAIN_METHOD == "Zend_Validate_NotEmptyTest::main") {
  121. Zend_Validate_NotEmptyTest::main();
  122. }