Skip to content

Commit

Permalink
feature #26791 [BrowserKit] Bypass Header Informations (cfjulien)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1-dev branch.

Discussion
----------

[BrowserKit] Bypass Header Informations

This enables browser Testingtools like mink to pass headerfiles while doing a form submit

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->
We tried to do some Browsertesting with Mink and Behat, something like:

```gherkin
Scenario Outline: greet in native language

Given the browser language is "<lang>"
And I called the website
When I fill in "PHP" for "username"
And I submit the form
Then I should see "<greeting>"

	Examples:
		| lang 	| greeting 	|
		| en 	| Hello 	|
		| de 	| Hallo 	|
		| fr 	| Bonjour 	|
		| zh 	| 你好 		|
		| ru 	| привет	|
		| be 	| Bonjour 	|
```

```php
  public function theBrowserLanguageIs($arg1)
    {
        $this->getSession()->setRequestHeader('Accept', '*/*');
        $this->getSession()->setRequestHeader('Accept-Language', $arg1);
    }

```

While everything works fine with visit form submit didn't send the headers. At Mink theres also an open issue for that
minkphp/MinkBrowserKitDriver#79

but actually the problem was between the mink browserkit and the symfony client.

Commits
-------

fa2063e [BroserKit] Enable passthrew header information on submit
  • Loading branch information
fabpot committed Apr 22, 2018
2 parents 2ceef59 + fa2063e commit 9cb1f14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -289,11 +289,11 @@ public function click(Link $link)
*
* @return Crawler
*/
public function submit(Form $form, array $values = array())
public function submit(Form $form, array $values = array(), $serverParameters = array())
{
$form->setValues($values);

return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles());
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), $serverParameters);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -367,6 +367,20 @@ public function testSubmitPreserveAuth()
$this->assertEquals('bar', $server['PHP_AUTH_PW']);
}

public function testSubmitPassthrewHeaders()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
$headers = array('Accept-Language' => 'de');

$client->submit($crawler->filter('input')->form(), array(), $headers);

$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('Accept-Language', $server);
$this->assertEquals('de', $server['Accept-Language']);
}

public function testFollowRedirect()
{
$client = new TestClient();
Expand Down

0 comments on commit 9cb1f14

Please sign in to comment.