Skip to content
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

WebAssert::addressEquals($page) should not remove query part #566

Closed
wants to merge 1 commit into from
Closed

WebAssert::addressEquals($page) should not remove query part #566

wants to merge 1 commit into from

Conversation

anton-siardziuk
Copy link

I think this is not right that I can not write something like that

I should be on "/login?return_url=/user"

in my feature context

Actually I can write, but under the hood MinkContext will remove query part from url. Interesting that it will not remove fragment part: https://github.com/Behat/Mink/blob/master/src/Behat/Mink/WebAssert.php#L647

This is copy from Behat/MinkExtension#144

@aik099
Copy link
Member

aik099 commented May 20, 2014

I guess this was some kind to normalize url to make sure that 2 urls with same file part and different url parameters are considered as same page.

@stof
Copy link
Member

stof commented May 20, 2014

@everzet could you give more info about the reason why it was implemented this way ?

@anton-siardziuk
Copy link
Author

I think the only normalization that should be applied there is remove "base_url" part of actual url. And ensure it starts from "/" after that.

@aik099
Copy link
Member

aik099 commented May 20, 2014

Maybe also sorting parameters alphabetically and the rebuilding query string with http_build_query.

@anton-siardziuk
Copy link
Author

In my opinion the less work will be done implicitly the best in this particular case.

@jurgenhaas
Copy link

I ran into a similar issue here which is even worse: for some reason I have to define the base_url in behat.yml as http://www.example.com/subsite/?language=en which seems to be working fine.

However, when I then do something like I should be on "/user"which then tries to go to http://www.example.com/subsite/?language=en/user which isn't working. The expected URL is that case is http://www.example.com/subsite/user?language=en

@aik099
Copy link
Member

aik099 commented Nov 10, 2014

@jurgenhaas , what you're describing is a bug, where URL is built by appending all stuff to the end. Please create separate ticket and PR for it. In my QA-Tools library I'm actually storing parsed version of Base URL (via https://github.com/qa-tools/qa-tools/blob/develop/library/QATools/QATools/PageObject/Url/Parser.php class) and merge it with user provided components to construct new url.

@aik099
Copy link
Member

aik099 commented Nov 10, 2014

@m00t , can you please provide a PR as well?

@anton-siardziuk
Copy link
Author

@aik099, I am not sure I can do it in the near future, but I will try.

@jurgenhaas
Copy link

@aik099 I have fixed this and provided a PR in MinkExtension, see Behat/MinkExtension#173

@anton-siardziuk
Copy link
Author

@jurgenhaas I believe this issue will not be fixed with Behat/MinkExtension#173

@jurgenhaas
Copy link

You're right, I was working on the issue mentioned 3 days ago where the base_url has a query but not the path. So, if this approach is going to be accepted, then the next step could be to address a potential query in the path as well.

@anton-siardziuk
Copy link
Author

@jurgenhaas I am not sure, but I think our issues does not have anything in common.
BTW I started working on this issue, hopefully PR will be provided soon.

@aik099
Copy link
Member

aik099 commented Nov 13, 2014

Good work. Don't forget to add tests to any code you write.

Given current url is "/login?return_url=/return1"

Actual behavior:
  WebAssert::addressEquals('/login?return_url=/return1') SUCCESS
  WebAssert::addressEquals('/login?return_url=/blabla') SUCCESS
  WebAssert::addressEquals('/login') SUCCESS
  WebAssert::addressEquals('/other/path') FAIL

Expected behavior:
  WebAssert::addressEquals('/login?return_url=/return1') SUCCESS
  WebAssert::addressEquals('/login?return_url=/blabla') FAIL
  WebAssert::addressEquals('/login') FAIL
  WebAssert::addressEquals('/other/path') FAIL
@anton-siardziuk
Copy link
Author

@aik099, any chances it will be merged? Any feedback?

@aik099
Copy link
Member

aik099 commented Dec 16, 2014

I've approved your work, but I was hoping @stof will agree with my assertion just to be on the safe side.

@everzet
Copy link
Contributor

everzet commented Dec 19, 2014

@stof I don't recall any meaningful reason. Feel free to change it.

@gquemener
Copy link

I guess it was because asserting that one is on /foo/bar while the url is actually /foo/bar?baz=1 is quite true, don't you think?

@gquemener
Copy link

Anyway, this is a BC break for people expecting the behaviour I described in my previous message IMO.

@everzet
Copy link
Contributor

everzet commented Dec 19, 2014

@gquemener thanks, Gildas. Yup, now I remember. It's because if you do compare with the query string, you'd get in very interesting situations. Like:

/foo/bar?bar=2&baz=1   !==   /foo/bar?baz=1&bar=2
/foo/bar               !==   /foo/bar?bar=1
/foo/bar?              !==   /foo/bar

With this in mind, I think you should keep addressEqual() and introduce another asserter for queries, that does include query string, but doesn't care about order of these.

@anton-siardziuk
Copy link
Author

@gquemener I am not sure why this should be true. Query is part of url, why it should be ignored? If so, then we should revert this commit as well: Behat@38928ce, because mink cannot ignore query, but do not ignore hash

@everzet
Copy link
Contributor

everzet commented Dec 19, 2014

@m00t my thinking was that query is part of URL, but it is not necessary a part of the address - that depends on how you design your routes. Hence addressEqual() does not check query.

@anton-siardziuk
Copy link
Author

@everzet so addressEqual() should ignore hashtag as well. I am fine with another asserter for queries, but current addressEquals() seems a little inconsistent to me.

@everzet
Copy link
Contributor

everzet commented Dec 19, 2014

@m00t from this point onwards for addressEquals() it's not about consistency, it's about backwards compatibility.

@anton-siardziuk
Copy link
Author

@everzet on the other hand hashtag is part of address for some single page applications.

@anton-siardziuk
Copy link
Author

@stof @everzet ok. Feel free to close this PR.

@anton-siardziuk
Copy link
Author

@everzet @gquemener I thought about it again and now I disagree with you. BC break introduced in this PR easy to understand and easy to fix. You just update, see that test failed with "failed assert that /login?return=1 === /login?return=2" and fix it. I think there are much more users now actually write

   Then I should be on "/login?return=1"

and do not realize actually that "?return=1" will be ignored, than users who know it and really want to ignore query part.

@aik099
Copy link
Member

aik099 commented Dec 20, 2014

Unfortunately if the url user will be redirected to will contain variable parameter (e.g. session_id), then you can't match it.

@anton-siardziuk
Copy link
Author

@aik099 yeah, this is the problem. As a workaround you can use regexps like "^/login" for this situation. I am not sure if it is acceptable solution, but I think there are not many cases with variable parameters in urls.

@indeyets
Copy link

The proper solution is to use terminology and comparison algorithms from IRI spec

@gquemener
Copy link

Wow @indeyets, I didn't know about that!
Indeed, this is a proper solution.
Are you aware of an existing php library implementing this rfc?

@indeyets
Copy link

@gquemener ml/iri is good. // cc @lanthaler

@anton-siardziuk anton-siardziuk deleted the 566_address_equals_query_fix branch February 9, 2015 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants