_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 => '\'#\' has not only alphabetic and digit characters' ); $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)); } }