<commit_before><?php
namespace TYPO3\Fluid\Tests\Functional\Form;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "TYPO3.Fluid".           *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License, either version 3   *
 * of the License, or (at your option) any later version.                 *
 *                                                                        *
 * The TYPO3 project - inspiring people to share!                         *
 *                                                                        */

use TYPO3\Flow\Http\Request;
use TYPO3\Flow\Http\Uri;
use TYPO3\Flow\Mvc\ActionRequest;

/**
 * Testcase for Standalone View
 *
 * @group large
 */
class FormObjectsTest extends \TYPO3\Flow\Tests\FunctionalTestCase {

	/**
	 * @var boolean
	 */
	static protected $testablePersistenceEnabled = TRUE;

	/**
	 * @var \TYPO3\Flow\Http\Client\Browser
	 */
	protected $browser;

	/**
	 * Initializer
	 */
	public function setUp() {
		parent::setUp();

		$route = new \TYPO3\Flow\Mvc\Routing\Route();
		$route->setUriPattern('test/fluid/formobjects(/{@action})');
		$route->setDefaults(array(
			'@package' => 'TYPO3.Fluid',
			'@subpackage' => 'Tests\Functional\Form\Fixtures',
			'@controller' => 'Form',
			'@action' => 'index',
			'@format' => 'html'
		));
		$route->setAppendExceedingArguments(TRUE);
		$this->router->addRoute($route);
	}

	/**
	 * @test
	 */
	public function objectIsCreatedCorrectly() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function formIsRedisplayedIfValidationErrorsOccur() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('test_noValidEmail');

		$this->browser->submit($form);
		$form = $this->browser->getForm();
		$this->assertSame('<NAME>', $form['post']['name']->getValue());
		$this->assertSame('test_noValidEmail', $form['post']['author']['emailAddress']->getValue());
		$this->assertSame('f3-form-error', $this->browser->getCrawler()->filterXPath('//*[@id="email"]')->attr('class'));

		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function formForPersistedObjectIsRedisplayedIfValidationErrorsOccur() {
		$postIdentifier = $this->setupDummyPost();

		$this->browser->request('http://localhost/test/fluid/formobjects/edit?fooPost=' . $postIdentifier);
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('test_noValidEmail');

		$this->browser->submit($form);
		$form = $this->browser->getForm();
		$this->assertSame('<NAME>', $form['post']['name']->getValue());
		$this->assertSame('test_noValidEmail', $form['post']['author']['emailAddress']->getValue());
		$this->assertSame('f3-form-error', $this->browser->getCrawler()->filterXPath('//*[@id="email"]')->attr('class'));

		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function objectIsNotCreatedAnymoreIfHmacHasBeenTampered() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['__trustedProperties']->setValue($form['__trustedProperties']->getValue() . 'a');
		$this->browser->submit($form);

		$this->assertSame('500 Internal Server Error', $this->browser->getLastResponse()->getStatus());
	}

	/**
	 * @test
	 */
	public function objectIsNotCreatedAnymoreIfIdentityFieldHasBeenAdded() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$identityFieldDom = dom_import_simplexml(simplexml_load_string('<input type="text" name="post[__identity]" value="someIdentity" />'));
		$form->set(new \Symfony\Component\DomCrawler\Field\InputFormField($identityFieldDom));
<commit_msg>[TASK] Fix failing functional FormObjectsTest<commit_after><?php
namespace TYPO3\Fluid\Tests\Functional\Form;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "TYPO3.Fluid".           *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License, either version 3   *
 * of the License, or (at your option) any later version.                 *
 *                                                                        *
 * The TYPO3 project - inspiring people to share!                         *
 *                                                                        */

use TYPO3\Flow\Http\Request;
use TYPO3\Flow\Http\Uri;
use TYPO3\Flow\Mvc\ActionRequest;

/**
 * Testcase for Standalone View
 *
 * @group large
 */
class FormObjectsTest extends \TYPO3\Flow\Tests\FunctionalTestCase {

	/**
	 * @var boolean
	 */
	static protected $testablePersistenceEnabled = TRUE;

	/**
	 * @var \TYPO3\Flow\Http\Client\Browser
	 */
	protected $browser;

	/**
	 * Initializer
	 */
	public function setUp() {
		parent::setUp();

		$route = new \TYPO3\Flow\Mvc\Routing\Route();
		$route->setUriPattern('test/fluid/formobjects(/{@action})');
		$route->setDefaults(array(
			'@package' => 'TYPO3.Fluid',
			'@subpackage' => 'Tests\Functional\Form\Fixtures',
			'@controller' => 'Form',
			'@action' => 'index',
			'@format' => 'html'
		));
		$route->setAppendExceedingArguments(TRUE);
		$this->router->addRoute($route);
	}

	/**
	 * @test
	 */
	public function objectIsCreatedCorrectly() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function formIsRedisplayedIfValidationErrorsOccur() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('test_noValidEmail');

		$this->browser->submit($form);
		$form = $this->browser->getForm();
		$this->assertSame('<NAME>', $form['post']['name']->getValue());
		$this->assertSame('test_noValidEmail', $form['post']['author']['emailAddress']->getValue());
		$this->assertSame('f3-form-error', $this->browser->getCrawler()->filterXPath('//*[@id="email"]')->attr('class'));

		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function formForPersistedObjectIsRedisplayedIfValidationErrorsOccur() {
		$postIdentifier = $this->setupDummyPost();

		$this->browser->request('http://localhost/test/fluid/formobjects/edit?fooPost=' . $postIdentifier);
		$form = $this->browser->getForm();

		$form['post']['name']->setValue('<NAME>');
		$form['post']['author']['emailAddress']->setValue('test_noValidEmail');

		$this->browser->submit($form);
		$form = $this->browser->getForm();
		$this->assertSame('<NAME>', $form['post']['name']->getValue());
		$this->assertSame('test_noValidEmail', $form['post']['author']['emailAddress']->getValue());
		$this->assertSame('f3-form-error', $this->browser->getCrawler()->filterXPath('//*[@id="email"]')->attr('class'));

		$form['post']['author']['emailAddress']->setValue('<EMAIL>');

		$response = $this->browser->submit($form);
		$this->assertSame('<NAME>|<EMAIL>', $response->getContent());
	}

	/**
	 * @test
	 */
	public function objectIsNotCreatedAnymoreIfHmacHasBeenTampered() {
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$form['__trustedProperties']->setValue($form['__trustedProperties']->getValue() . 'a');
		$this->browser->submit($form);

		$this->assertSame('500 Internal Server Error', $this->browser->getLastResponse()->getStatus());
	}

	/**
	 * @test
	 */
	public function objectIsNotCreatedAnymoreIfIdentityFieldHasBeenAdded() {
		$postIdentifier = $this->setupDummyPost();
		$this->browser->request('http://localhost/test/fluid/formobjects');
		$form = $this->browser->getForm();

		$identityFieldDom = dom_import_simplexml(simplexml_load_string('<input type="text" name="post[__identity]" value="' . $postIdentifier . '" />'));
		$form->set(new \Symfony\Component\DomCrawler\Field\InputFormField($identityFieldDom));

{'fraction_non_alphanumeric': 0.2055984555984556, 'fraction_numerical': 0.0036465036465036463, 'mean_word_length': 3.641612742658039, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 206, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5551180', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2795, 'n_words': 391}