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

Add case-sensitive comparison option to function WebAssert::elementContains #829

Open
MurzNN opened this issue May 4, 2022 · 5 comments · May be fixed by #830
Open

Add case-sensitive comparison option to function WebAssert::elementContains #829

MurzNN opened this issue May 4, 2022 · 5 comments · May be fixed by #830

Comments

@MurzNN
Copy link

MurzNN commented May 4, 2022

Now function WebAssert::responseContains does comparison in case-insensitive mode because of usage stripos php function:

Mink/src/WebAssert.php

Lines 319 to 325 in 34c0ae0

public function responseContains($text)
{
$actual = $this->session->getPage()->getContent();
$message = sprintf('The string "%s" was not found anywhere in the HTML response of the current page.', $text);
$this->assert(stripos($actual, (string) $text) !== false, $message);
}

And I see no ways to make case-sensitive comparison. So will be good to add option to enable case-sensitive comparison mode via some option. Or it is already exists, please point me out to the solution.

And will be good to explain that this function does case-sensitive comparison by default, because it is a surprise for many developers. For example, this nuance brings that issue in Drupal module: https://www.drupal.org/project/layout_builder_restrictions/issues/3278651

@aik099
Copy link
Member

aik099 commented May 4, 2022

@MurzNN , the WebAssert::responseContains is indeed case-insensitive and, as far as I can remember, it always was. Probably the DocBlock could be improved to reflect that behavior. The same goes for the \Behat\Mink\WebAssert::responseNotContains method.

As for the mentioned Drupal issue, you can use the \Behat\Mink\WebAssert::responseMatches method to do a case-sensitive comparison.


By the way, the Drupal issue uses the \Behat\Mink\WebAssert::elementContains method currently, which is also, as the majority of assertion methods, case-insensitive.

@MurzNN
Copy link
Author

MurzNN commented May 4, 2022

Yeah, sorry, I've mixed up elementContains and responseContains when creating issue!

So, for \Mink\WebAssert::responseContains we have \Behat\Mink\WebAssert::responseMatches alternative, that supports regexp and can do a case-sensitive comparison.

But seems we have no similar function \Behat\Mink\WebAssert::elementMatches, so what is the solution for \Behat\Mink\WebAssert::elementContains to make a case-sensitive comparison?

@MurzNN MurzNN changed the title Add case-sensitive comparison option to function WebAssert::responseContains Add case-sensitive comparison option to function WebAssert::elementContains May 4, 2022
@MurzNN
Copy link
Author

MurzNN commented May 4, 2022

What do you think about adding third non-required argument like this to enable case-sensitive comparison, like this https://github.com/minkphp/Mink/pull/830/files ?

If it's ok, I can expand it to all other *Contains() functions.

@aik099
Copy link
Member

aik099 commented May 5, 2022

Let's wait for @stof opinion on this.

Looking back at the source of all this case-sensitivity issue/PR (checking Restricted vs Unrestricted) I'm starting to think, that it's not worth it. As you've suggested altering the project code, that uses Mink, is enough to make the test pass.

@MurzNN
Copy link
Author

MurzNN commented Jul 20, 2022

@stof, can you please give a short message about your opinion on this?

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 a pull request may close this issue.

2 participants