<commit_before><?php
declare(ENCODING = 'utf-8');
namespace F3::FLOW3::Validation::Validator;

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */

/**
 * @package FLOW3
 * @subpackage Tests
 * @version $Id$
 */

/**
 * Testcase for the email address validator
 *
 * @package FLOW3
 * @subpackage Tests
 * @version $Id$
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */
class EmailAddressTest extends F3::Testing::BaseTestCase {

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddress1() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('<EMAIL>', $validationErrors));
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsFalseForAnEmailAddressWithIncompleteHostPart() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty('andreas.foerthner@netlogix', $validationErrors));
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsFalseForAnEmailAddressWithMissingHostPart() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty('andreas.foerthner@', $validationErrors));
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsFalseForAnEmailAddressWithMissingLocalPart() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty('@typo3.org', $validationErrors));
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailValidatorCreatesTheCorrectErrorObjectForAnInvalidEmailAddress() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$emailAddressValidator->isValidProperty('notAValidMail@Address', $validationErrors);

		$this->assertType('F3::FLOW3::Validation::Error', $validationErrors[0]);
		$this->assertEquals(1221559976, $validationErrors[0]->getErrorCode());
	}


	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddress2() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('user@localhost', $validationErrors), 'user@localhost was rejected.');
	}


	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddress3() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('<EMAIL>', $validationErrors), '<EMAIL> was rejected.');
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddress4() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('<EMAIL>', $validationErrors), '<EMAIL> was rejected.');
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddress5() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('<EMAIL>', $validationErrors), '<EMAIL> was rejected.');
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsTrueForACorrectEmailAddressUsingAnIPAddressForHost() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty('local@192.168.0.2', $validationErrors), 'local@192.168.0.2 was rejected.');
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsFalseForAnEmailAddressUsingAnIncorrectIPAddressForHost1() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty('local@192.168.2', $validationErrors), 'local@192.168.2 was accepted.');
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailAddressValidatorReturnsFalseForAnEmailAddressUsingAnIncorrectIPAddressForHost2() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty('local@192.168.270.1', $validationErrors), 'local@192.168.270.1 was accepted.');
	}

}

?><commit_msg>FLOW3: * streamlined the test for the email address validator Original-Commit-Hash: d20a7c7711e223de10b5d6ab77f8fea892452a43<commit_after><?php
declare(ENCODING = 'utf-8');
namespace F3::FLOW3::Validation::Validator;

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */

/**
 * @package FLOW3
 * @subpackage Tests
 * @version $Id$
 */

/**
 * Testcase for the email address validator
 *
 * @package FLOW3
 * @subpackage Tests
 * @version $Id$
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */
class EmailAddressTest extends F3::Testing::BaseTestCase {

	/**
	 * Data provider with valid email addresses
	 *
	 * @return array
	 * @author <NAME> <<EMAIL>>
	 */
	public function validAddresses() {
		return array(
			array('<EMAIL>'),
			array('user@localhost'),
			array('<EMAIL>'),
			array('<EMAIL>'),
			array('<EMAIL>'),
			array('<EMAIL>'),
			array('local@192.168.0.2')
		);
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @test
	 * @dataProvider validAddresses
	 */
	public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertTrue($emailAddressValidator->isValidProperty($address, $validationErrors));
	}

	/**
	 * Data provider with invalid email addresses
	 *
	 * @return array
	 * @author <NAME> <<EMAIL>>
	 */
	public function invalidAddresses() {
		return array(
			array('andreas.foerthner@'),
			array('@typo3.org'),
			array('someone@typo3.'),
			array('local@192.168.2'),
			array('local@192.168.270.1')
		);
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @test
	 * @dataProvider invalidAddresses
	 */
	public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$this->assertFalse($emailAddressValidator->isValidProperty($address, $validationErrors));
	}

	/**
	 * @test
	 * @author <NAME> <<EMAIL>>
	 */
	public function emailValidatorCreatesTheCorrectErrorObjectForAnInvalidEmailAddress() {
		$emailAddressValidator = new F3::FLOW3::Validation::Validator::EmailAddress();
		$emailAddressValidator->injectComponentFactory($this->componentFactory);
		$validationErrors = new F3::FLOW3::Validation::Errors();

		$emailAddressValidator->isValidProperty('notAValidMail@Address', $validationErrors);

		$this->assertType('F3::FLOW3::Validation::Error', $validationErrors[0]);
		$this->assertEquals(1221559976, $validationErrors[0]->getErrorCode());
	}

}

?>
{'fraction_non_alphanumeric': 0.13651877133105803, 'fraction_numerical': 0.020201088460474127, 'mean_word_length': 4.073467477772579, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651936', 'n_tokens_mistral': 3119, 'n_tokens_neox': 2889, 'n_words': 555}