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 new assertion assertValueIsNot() #929

Merged
merged 2 commits into from
Oct 11, 2021
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
26 changes: 24 additions & 2 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function assertTitleContains($title)
/**
* Assert that the given encrypted cookie is present.
*
* @param string $name
* @param string $name
* @param bool $decrypt
* @return $this
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ public function assertHasPlainCookie($name)
/**
* Assert that the given encrypted cookie is not present.
*
* @param string $name
* @param string $name
* @param bool $decrypt
* @return $this
*/
Expand Down Expand Up @@ -630,6 +630,28 @@ public function assertValue($selector, $value)
return $this;
}

/**
* Assert that the element matching the given selector does not have the given value.
*
* @param string $selector
* @param string $value
* @return $this
*/
public function assertValueIsNot($selector, $value)
{
$fullSelector = $this->resolver->format($selector);

$actual = $this->resolver->findOrFail($selector)->getAttribute('value');

PHPUnit::assertNotEquals(
$value,
$actual,
"Saw unexpected value [{$value}] within element [{$fullSelector}]."
);

return $this;
}

/**
* Assert that the element matching the given selector has the given value in the provided attribute.
*
Expand Down
28 changes: 26 additions & 2 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ public function test_assert_value()
$driver = m::mock(stdClass::class);

$element = m::mock(RemoteWebElement::class);
$element->shouldReceive('getAttribute')
->andReturn('bar');
$element->shouldReceive('getAttribute')->andReturn('bar');

$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('format')->with('foo')->andReturn('body foo');
Expand All @@ -483,6 +482,31 @@ public function test_assert_value()
}
}

public function test_assert_value_is_not()
{
$driver = m::mock(stdClass::class);

$element = m::mock(RemoteWebElement::class);
$element->shouldReceive('getAttribute')->andReturn('bar');

$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('format')->with('foo')->andReturn('body foo');
$resolver->shouldReceive('findOrFail')->with('foo')->andReturn($element);

$browser = new Browser($driver, $resolver);

$browser->assertValueIsNot('foo', 'foo');

try {
$browser->assertValueIsNot('foo', 'bar');
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString(
'Saw unexpected value [bar] within element [body foo].',
$e->getMessage()
);
}
}

public function test_assert_attribute()
{
$driver = m::mock(stdClass::class);
Expand Down