<commit_before><?php
declare(ENCODING = 'utf-8');
namespace F3\FLOW3\MVC\Controller;

/*                                                                        *
 * 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.                                       *
 *                                                                        */

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

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyTakesTheDatatypeValidatorOfTheArgumentObjectIntoAccount() {
		$errors = $this->getMock('F3\FLOW3\Validation\Errors', array(), array(), '', FALSE);
		$datatypeValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$datatypeValidator->expects($this->once())->method('isValidProperty')->will($this->returnValue(FALSE));

		$customValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$customValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->any())->method('getValidator')->will($this->returnValue($customValidator));
		$argument->expects($this->atLeastOnce())->method('getDatatypeValidator')->will($this->returnValue($datatypeValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$this->assertFalse($argumentsValidator->validateProperty($arguments, 'someArgument', $errors));
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyTakesTheRegisteredCustomValidatorOfTheArgumentObjectIntoAccount() {
		$errors = $this->getMock('F3\FLOW3\Validation\Errors', array(), array(), '', FALSE);
		$datatypeValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$datatypeValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));

		$customValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$customValidator->expects($this->once())->method('isValidProperty')->will($this->returnValue(FALSE));

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($customValidator));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($datatypeValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$this->assertFalse($argumentsValidator->validateProperty($arguments, 'someArgument', $errors));
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyAddsTheErrorObjectsAddedByTheDatatypeValidatorToTheErrorsObject() {
		$validatorAddingAnError = new \F3\TestPackage\ValidatorThatAddsAnError($this->objectFactory);
		$mockValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$mockValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));
		$errors = new \F3\FLOW3\Validation\Errors();

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($mockValidator));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($validatorAddingAnError));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$argumentsValidator->validateProperty($arguments, 'someArgument', $errors);

		$expectedError = new \F3\FLOW3\Validation\Errors();
		$expectedError[] = new \F3\FLOW3\Validation\Error('The given subject was not valid.', 1221664636);
		$this->assertEquals($expectedError, $errors['someArgument'], 'The error was not stored for the given argument.');
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyAddsTheErrorObjectsAddedByTheCustomValidatorToTheErrorsObject() {
		$validatorAddingAnError = new \F3\TestPackage\ValidatorThatAddsAnError($this->objectFactory);
		$mockValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$mockValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));
		$errors = new \F3\FLOW3\Validation\Errors();

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($validatorAddingAnError));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($mockValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$argumentsValidator->validateProperty($arguments, 'someArgument', $errors);

		$expectedError = new \F3\FLOW3\Validation\Errors();
		$expectedError[] = new \F3\FLOW3\Validation\Error('The given subject was not valid.', 1221664636);
		$this->assertEquals($expectedError, $errors['someArgument'], 'The error was not stored for the given argument.');
	}
}

?><commit_msg>FLOW3: * (MVC): Fixed arguments, as it now needs another constructor argument. Original-Commit-Hash: 7f6f3486c7d03fe1de997bef51006aac2df167e1<commit_after><?php
declare(ENCODING = 'utf-8');
namespace F3\FLOW3\MVC\Controller;

/*                                                                        *
 * 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.                                       *
 *                                                                        */

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

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyTakesTheDatatypeValidatorOfTheArgumentObjectIntoAccount() {
		$errors = $this->getMock('F3\FLOW3\Validation\Errors', array(), array(), '', FALSE);
		$datatypeValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$datatypeValidator->expects($this->once())->method('isValidProperty')->will($this->returnValue(FALSE));

		$customValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$customValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->any())->method('getValidator')->will($this->returnValue($customValidator));
		$argument->expects($this->atLeastOnce())->method('getDatatypeValidator')->will($this->returnValue($datatypeValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory, $this->objectManager);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$this->assertFalse($argumentsValidator->validateProperty($arguments, 'someArgument', $errors));
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyTakesTheRegisteredCustomValidatorOfTheArgumentObjectIntoAccount() {
		$errors = $this->getMock('F3\FLOW3\Validation\Errors', array(), array(), '', FALSE);
		$datatypeValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$datatypeValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));

		$customValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$customValidator->expects($this->once())->method('isValidProperty')->will($this->returnValue(FALSE));

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($customValidator));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($datatypeValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory, $this->objectManager);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$this->assertFalse($argumentsValidator->validateProperty($arguments, 'someArgument', $errors));
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyAddsTheErrorObjectsAddedByTheDatatypeValidatorToTheErrorsObject() {
		$validatorAddingAnError = new \F3\TestPackage\ValidatorThatAddsAnError($this->objectFactory);
		$mockValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$mockValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));
		$errors = new \F3\FLOW3\Validation\Errors();

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($mockValidator));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($validatorAddingAnError));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory, $this->objectManager);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$argumentsValidator->validateProperty($arguments, 'someArgument', $errors);

		$expectedError = new \F3\FLOW3\Validation\Errors();
		$expectedError[] = new \F3\FLOW3\Validation\Error('The given subject was not valid.', 1221664636);
		$this->assertEquals($expectedError, $errors['someArgument'], 'The error was not stored for the given argument.');
	}

	/**
	 * @test
	 * @category unit
	 * @author <NAME> <<EMAIL>>
	 */
	public function validatePropertyAddsTheErrorObjectsAddedByTheCustomValidatorToTheErrorsObject() {
		$validatorAddingAnError = new \F3\TestPackage\ValidatorThatAddsAnError($this->objectFactory);
		$mockValidator = $this->getMock('F3\FLOW3\Validation\ValidatorInterface');
		$mockValidator->expects($this->any())->method('isValidProperty')->will($this->returnValue(TRUE));
		$errors = new \F3\FLOW3\Validation\Errors();

		$argument = $this->getMock('F3\FLOW3\MVC\Controller\Argument', array(), array(), '', FALSE);
		$argument->expects($this->any())->method('getName')->will($this->returnValue('someArgument'));
		$argument->expects($this->atLeastOnce())->method('getValidator')->will($this->returnValue($validatorAddingAnError));
		$argument->expects($this->any())->method('getDatatypeValidator')->will($this->returnValue($mockValidator));
		$arguments = new \F3\FLOW3\MVC\Controller\Arguments($this->objectFactory, $this->objectManager);
		$arguments->addArgument($argument);

		$argumentsValidator = new ArgumentsValidator($arguments, $this->objectFactory);
		$argumentsValidator->validateProperty($arguments, 'someArgument', $errors);

		$expectedError = new \F3\FLOW3\Validation\Errors();
		$expectedError[] = new \F3\FLOW3\Validation\Error('The given subject was not valid.', 1221664636);
		$this->assertEquals($expectedError, $errors['someArgument'], 'The error was not stored for the given argument.');
	}
}

?>
{'fraction_non_alphanumeric': 0.1697221426525351, 'fraction_numerical': 0.012317387568032082, 'mean_word_length': 4.6561360874848114, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 281, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1698152', 'n_tokens_mistral': 4043, 'n_tokens_neox': 3831, 'n_words': 624}