AlphaTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-2015 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. * @see Zend_Validate_Alpha
  24. */
  25. require_once 'Zend/Validate/Alpha.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Validate
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Validate
  33. */
  34. class Zend_Validate_AlphaTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Zend_Validate_Alpha object
  38. *
  39. * @var Zend_Validate_Alpha
  40. */
  41. protected $_validator;
  42. /**
  43. * Creates a new Zend_Validate_Alpha object for each test method
  44. *
  45. * @return void
  46. */
  47. public function setUp()
  48. {
  49. $this->_validator = new Zend_Validate_Alpha();
  50. }
  51. /**
  52. * Ensures that the validator follows expected behavior
  53. *
  54. * @return void
  55. */
  56. public function testBasic()
  57. {
  58. $valuesExpected = array(
  59. 'abc123' => false,
  60. 'abc 123' => false,
  61. 'abcxyz' => true,
  62. 'AZ@#4.3' => false,
  63. 'aBc123' => false,
  64. 'aBcDeF' => true,
  65. '' => false,
  66. ' ' => false,
  67. "\n" => false
  68. );
  69. foreach ($valuesExpected as $input => $result) {
  70. $this->assertEquals($result, $this->_validator->isValid($input));
  71. }
  72. }
  73. /**
  74. * Ensures that getMessages() returns expected default value
  75. *
  76. * @return void
  77. */
  78. public function testGetMessages()
  79. {
  80. $this->assertEquals(array(), $this->_validator->getMessages());
  81. }
  82. /**
  83. * Ensures that the allowWhiteSpace option works as expected
  84. *
  85. * @return void
  86. */
  87. public function testAllowWhiteSpace()
  88. {
  89. $this->_validator->setAllowWhiteSpace(true);
  90. $valuesExpected = array(
  91. 'abc123' => false,
  92. 'abc 123' => false,
  93. 'abcxyz' => true,
  94. 'AZ@#4.3' => false,
  95. 'aBc123' => false,
  96. 'aBcDeF' => true,
  97. '' => false,
  98. ' ' => true,
  99. "\n" => true,
  100. " \t " => true,
  101. "a\tb c" => true
  102. );
  103. foreach ($valuesExpected as $input => $result) {
  104. $this->assertEquals(
  105. $result,
  106. $this->_validator->isValid($input),
  107. "Expected '$input' to be considered " . ($result ? '' : 'in') . "valid"
  108. );
  109. }
  110. }
  111. /**
  112. * @ZF-4352
  113. */
  114. public function testNonStringValidation()
  115. {
  116. $this->assertFalse($this->_validator->isValid(array(1 => 1)));
  117. }
  118. }