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

Skip to content

[BrowserKit] Bypass Header Informations #26791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of allowing to pass any server parameters, I think we should restrict to only HTTP headers. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that's not consistent with the request API, which expects to get things in the $_SERVER format. I think consistency is better for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand consistency here. Changing anything besides HTTP headers when submitting a form should not be allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, consistency between the different APIs of BrowserKit (namely request and submit here)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the Pull Request to Mink BrowserKit to show the exakt usage for my usecase. Therefor I might leave it as it is. If you would prefer to filter parameters i can implement that as well

{
$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
Original file line number Diff line number Diff line change
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