| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Validate
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @see Zend_Validate_Alnum
- */
- require_once 'Zend/Validate/Alnum.php';
- /**
- * @category Zend
- * @package Zend_Validate
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Validate
- */
- class Zend_Validate_AlnumTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Zend_Validate_Alnum object
- *
- * @var Zend_Validate_Alnum
- */
- protected $_validator;
- /**
- * Creates a new Zend_Validate_Alnum object for each test method
- *
- * @return void
- */
- public function setUp()
- {
- $this->_validator = new Zend_Validate_Alnum();
- }
- /**
- * Ensures that the validator follows expected behavior for basic input values
- *
- * @return void
- */
- public function testExpectedResultsWithBasicInputValues()
- {
- $valuesExpected = array(
- 'abc123' => true,
- 'abc 123' => false,
- 'abcxyz' => true,
- 'AZ@#4.3' => false,
- 'aBc123' => true,
- '' => false,
- ' ' => false,
- "\n" => false,
- 'foobar1' => true
- );
- foreach ($valuesExpected as $input => $result) {
- $this->assertEquals($result, $this->_validator->isValid($input));
- }
- }
- /**
- * Ensures that getMessages() returns expected initial value
- *
- * @return void
- */
- public function testMessagesEmptyInitially()
- {
- $this->assertEquals(array(), $this->_validator->getMessages());
- }
- /**
- * Ensures that the allowWhiteSpace option works as expected
- *
- * @return void
- */
- public function testOptionToAllowWhiteSpaceWithBasicInputValues()
- {
- $this->_validator->setAllowWhiteSpace(true);
- $valuesExpected = array(
- 'abc123' => true,
- 'abc 123' => true,
- 'abcxyz' => true,
- 'AZ@#4.3' => false,
- 'aBc123' => true,
- '' => false,
- ' ' => true,
- "\n" => true,
- " \t " => true,
- 'foobar1' => true
- );
- foreach ($valuesExpected as $input => $result) {
- $this->assertEquals(
- $result,
- $this->_validator->isValid($input),
- "Expected '$input' to be considered " . ($result ? '' : 'in') . "valid"
- );
- }
- }
- /**
- * @return void
- */
- public function testEmptyStringValueResultsInProperValidationFailureMessages()
- {
- $this->assertFalse($this->_validator->isValid(''));
- $messages = $this->_validator->getMessages();
- $arrayExpected = array(
- Zend_Validate_Alnum::STRING_EMPTY => '\'\' is an empty string'
- );
- $this->assertThat($messages, $this->identicalTo($arrayExpected));
- }
- /**
- * @return void
- * @deprecated Since 1.5.0
- */
- public function testEmptyStringValueResultsInProperValidationFailureErrors()
- {
- $this->assertFalse($this->_validator->isValid(''));
- $errors = $this->_validator->getErrors();
- $arrayExpected = array(
- Zend_Validate_Alnum::STRING_EMPTY
- );
- $this->assertThat($errors, $this->identicalTo($arrayExpected));
- }
- /**
- * @return void
- */
- public function testInvalidValueResultsInProperValidationFailureMessages()
- {
- $this->assertFalse($this->_validator->isValid('#'));
- $messages = $this->_validator->getMessages();
- $arrayExpected = array(
- Zend_Validate_Alnum::NOT_ALNUM => '\'#\' contains characters which are non alphabetic and no digits'
- );
- $this->assertThat($messages, $this->identicalTo($arrayExpected));
- }
- /**
- * @return void
- * @deprecated Since 1.5.0
- */
- public function testInvalidValueResultsInProperValidationFailureErrors()
- {
- $this->assertFalse($this->_validator->isValid('#'));
- $errors = $this->_validator->getErrors();
- $arrayExpected = array(
- Zend_Validate_Alnum::NOT_ALNUM
- );
- $this->assertThat($errors, $this->identicalTo($arrayExpected));
- }
- /**
- * @ZF-4352
- */
- public function testNonStringValidation()
- {
- $this->assertFalse($this->_validator->isValid(array(1 => 1)));
- }
- /**
- * @ZF-7475
- */
- public function testIntegerValidation()
- {
- $this->assertTrue($this->_validator->isValid(1));
- }
- }
|