Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cb1f14

Browse files
committed
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 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
2 parents 2ceef59 + fa2063e commit 9cb1f14

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ public function click(Link $link)
289289
*
290290
* @return Crawler
291291
*/
292-
public function submit(Form $form, array $values = array())
292+
public function submit(Form $form, array $values = array(), $serverParameters = array())
293293
{
294294
$form->setValues($values);
295295

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

299299
/**

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ public function testSubmitPreserveAuth()
367367
$this->assertEquals('bar', $server['PHP_AUTH_PW']);
368368
}
369369

370+
public function testSubmitPassthrewHeaders()
371+
{
372+
$client = new TestClient();
373+
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
374+
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
375+
$headers = array('Accept-Language' => 'de');
376+
377+
$client->submit($crawler->filter('input')->form(), array(), $headers);
378+
379+
$server = $client->getRequest()->getServer();
380+
$this->assertArrayHasKey('Accept-Language', $server);
381+
$this->assertEquals('de', $server['Accept-Language']);
382+
}
383+
370384
public function testFollowRedirect()
371385
{
372386
$client = new TestClient();

0 commit comments

Comments
 (0)