Skip to content

Commit

Permalink
Add case sensitive comparison option
Browse files Browse the repository at this point in the history
  • Loading branch information
MurzNN committed May 4, 2022
1 parent 19e5890 commit 4d2e562
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/WebAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,19 @@ public function elementTextNotContains($selectorType, $selector, $text)
/**
* Checks that specific element contains HTML.
*
* @param string $selectorType element selector type (css, xpath)
* @param string|array $selector element selector
* @param string $html expected text
* @param string $selectorType element selector type (css, xpath)
* @param string|array $selector element selector
* @param string $html expected text
* @param bool $caseSensitive use case sensitive comparison
*
* @throws ElementHtmlException
*/
public function elementContains($selectorType, $selector, $html)
public function elementContains($selectorType, $selector, $html, $caseSensitive = false)
{
$element = $this->elementExists($selectorType, $selector);
$actual = $element->getHtml();
$regex = '/'.preg_quote($html, '/').'/ui';
$regex = '/'.preg_quote($html, '/').'/u';
if ($caseSensitive === false) $regex .= 'i';

$message = sprintf(
'The string "%s" was not found in the HTML of the %s.',
Expand All @@ -518,17 +520,19 @@ public function elementContains($selectorType, $selector, $html)
/**
* Checks that specific element does not contains HTML.
*
* @param string $selectorType element selector type (css, xpath)
* @param string|array $selector element selector
* @param string $html expected text
* @param string $selectorType element selector type (css, xpath)
* @param string|array $selector element selector
* @param string $html expected text
* @param bool $caseSensitive use case sensitive comparison
*
* @throws ElementHtmlException
*/
public function elementNotContains($selectorType, $selector, $html)
public function elementNotContains($selectorType, $selector, $html, $caseSensitive = false)
{
$element = $this->elementExists($selectorType, $selector);
$actual = $element->getHtml();
$regex = '/'.preg_quote($html, '/').'/ui';
$regex = '/'.preg_quote($html, '/').'/u';
if ($caseSensitive === false) $regex .= 'i';

$message = sprintf(
'The string "%s" appears in the HTML of the %s, but it should not.',
Expand Down

0 comments on commit 4d2e562

Please sign in to comment.