Skip to content

Commit

Permalink
TASK: Add test to verify that query arguments are added to hidden fie…
Browse files Browse the repository at this point in the history
…lds for get methods
  • Loading branch information
mficzel committed Oct 30, 2021
1 parent b052260 commit 09d1e4c
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions Tests/Functional/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ public function calculateHiddenFieldsCreatesTrustedPropertiesForMultiSelects()
<select name="prefix[foo][]" multiple>
<optgroup label="foo">
<option>foo</option>
<option>bar</option>
<option>bar</option>
</optgroup>
<option>baz</option>
<option>bam</option>
<option>baz</option>
<option>bam</option>
</select>
CONTENT;

Expand All @@ -168,10 +168,10 @@ public function calculateHiddenFieldsCreatesTrustedPropertiesForSingleSelects()
<select name="prefix[foo]">
<optgroup label="foo">
<option>foo</option>
<option>bar</option>
<option>bar</option>
</optgroup>
<option>baz</option>
<option>bam</option>
<option>baz</option>
<option>bam</option>
</select>
CONTENT;

Expand Down Expand Up @@ -328,7 +328,7 @@ public function calculateHiddenFieldsAddsEmptyFieldsForCheckboxesAndMultipleSele
<select name="select[multiple][]" multiple></select>
<input name="input[checkbox]" type="checkbox" value="foo" />
<input name="input[checkbox]" type="checkbox" value="bar" />
<input name="input[checkbox]" type="checkbox" value="baz" />
<input name="input[checkbox]" type="checkbox" value="baz" />
<input name="input[checkboxMultiple][]" type="checkbox" value="foo" />
<input name="input[checkboxMultiple][]" type="checkbox" value="bar" />
<input name="input[checkboxMultiple][]" type="checkbox" value="baz" />
Expand All @@ -349,10 +349,10 @@ public function calculateHiddenFieldsDoesNotAddsEmptyFieldsForOtherFormControls(
{
$content = <<<CONTENT
<select name="select[single]"></select>
<input name="input[text]" type="text" />
<input name="input[text]" type="text" />
<input name="input[radio]" type="radio" value="foo" />
<input name="input[radio]" type="radio" value="bar" />
<input name="input[radio]" type="radio" value="baz" />
<input name="input[radio]" type="radio" value="baz" />
CONTENT;

$form = $this->createForm();
Expand Down Expand Up @@ -458,4 +458,32 @@ public function calculateHiddenFieldsAddsIdentityFieldsForNewObjectsInFormData()
$this->assertArrayNotHasKey('item1[__identity]', $hiddenFields);
$this->assertArrayNotHasKey('item2[__identity]', $hiddenFields);
}

/**
* @test
*/
public function calculateHiddenFieldsAddsQueryArgumentsForMethodGet()
{
$form = $this->createForm(null, null, null, 'example.com?argument1=Example+%F0%9F%A6%86&nested[argument2]=%3A%2F%3F%23%5B%5D%40%20&nested[argument3]=%21%24%26%27%22%28%29%2A%2B%2C%3B%3D', 'get');

$hiddenFields = $form->calculateHiddenFields(null);

$this->assertEquals("Example 🦆", $hiddenFields['argument1']);
$this->assertEquals(":/?#[]@ ", $hiddenFields['nested[argument2]']);
$this->assertEquals("!$&'\"()*+,;=", $hiddenFields['nested[argument3]']);
}

/**
* @test
*/
public function calculateHiddenFieldsDoesNotAddQueryArgumentsForMethodPost()
{
$form = $this->createForm(null, null, null, 'example.com?argument1=Example+%F0%9F%A6%86&nested[argument2]=%3A%2F%3F%23%5B%5D%40%20&nested[argument3]=%21%24%26%27%22%28%29%2A%2B%2C%3B%3D', 'post');

$hiddenFields = $form->calculateHiddenFields(null);

$this->assertArrayNotHasKey("argument1", $hiddenFields);
$this->assertArrayNotHasKey("nested[argument2]", $hiddenFields);
$this->assertArrayNotHasKey("nested[argument3]", $hiddenFields);
}
}

0 comments on commit 09d1e4c

Please sign in to comment.