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

Conversation

ghost
Copy link

@ghost ghost commented Apr 4, 2018

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

We tried to do some Browsertesting with Mink and Behat, something like:

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 	|
  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.

@@ -231,11 +231,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

ghost pushed a commit to CrowdfoxGmbH/MinkBrowserKitDriver that referenced this pull request Apr 5, 2018
@ghost
Copy link
Author

ghost commented Apr 5, 2018

Is there something i can to about the failed test AppVeyor?

@fabpot
Copy link
Member

fabpot commented Apr 6, 2018

As this is a new feature, this pull request should be rebased on master.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Apr 6, 2018
This enables browser Testingtools like mink to pass headerfiles while doing a form submmit
@ghost ghost force-pushed the headers_on_submit branch from 45148fa to fa2063e Compare April 6, 2018 10:54
@ghost
Copy link
Author

ghost commented Apr 6, 2018

We rebased but the master test is still failing.

@fabpot fabpot changed the base branch from 2.7 to master April 20, 2018 04:37
@fabpot fabpot closed this Apr 22, 2018
@fabpot fabpot reopened this Apr 22, 2018
@fabpot
Copy link
Member

fabpot commented Apr 22, 2018

Thank you @CFJulien.

@fabpot fabpot merged commit fa2063e into symfony:master Apr 22, 2018
fabpot added a commit that referenced this pull request Apr 22, 2018
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
@fabpot fabpot mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants