feature #26791 [BrowserKit] Bypass Header Informations (cfjulien)
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
https://github.com/minkphp/MinkBrowserKitDriver/issues/79
but actually the problem was between the mink browserkit and the symfony client.
Commits
-------
fa2063efe4
[BroserKit] Enable passthrew header information on submit
This commit is contained in:
commit
9cb1f14ac3
@ -289,11 +289,11 @@ abstract class Client
|
|||||||
*
|
*
|
||||||
* @return Crawler
|
* @return Crawler
|
||||||
*/
|
*/
|
||||||
public function submit(Form $form, array $values = array())
|
public function submit(Form $form, array $values = array(), $serverParameters = array())
|
||||||
{
|
{
|
||||||
$form->setValues($values);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,6 +367,20 @@ class ClientTest extends TestCase
|
|||||||
$this->assertEquals('bar', $server['PHP_AUTH_PW']);
|
$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()
|
public function testFollowRedirect()
|
||||||
{
|
{
|
||||||
$client = new TestClient();
|
$client = new TestClient();
|
||||||
|
Reference in New Issue
Block a user