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

[6.x] Add new assertions assertSeeEmptyTextIn() and assertDontSeeEmptyTextIn() #843

Merged
merged 2 commits into from
Dec 15, 2020
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
40 changes: 40 additions & 0 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,46 @@ public function assertDontSeeIn($selector, $text)
return $this;
}

/**
* Assert that the given selector has no text.
*
* @param string $selector
* @return $this
*/
public function assertSeeEmptyTextIn($selector)
{
$fullSelector = $this->resolver->format($selector);

$element = $this->resolver->findOrFail($selector);

PHPUnit::assertTrue(
$element->getText() === '',
"Did not see expected text [''] within element [{$fullSelector}]."
);

return $this;
}

/**
* Assert that the given selector has some text.
*
* @param string $selector
* @return $this
*/
public function assertDontSeeEmptyTextIn($selector)
{
$fullSelector = $this->resolver->format($selector);

$element = $this->resolver->findOrFail($selector);

PHPUnit::assertTrue(
$element->getText() !== '',
"Saw unexpected text [''] within element [{$fullSelector}]."
);

return $this;
}

/**
* Assert that the given JavaScript expression evaluates to the given value.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/Concerns/InteractsWithElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ protected function tearDown(): void
/**
* @covers ::value
* @dataProvider dataProviderValueWithValue
* @param mixed $selector
* @param mixed $value
* @param string $js
* @param mixed $selector
* @param mixed $value
* @param string $js
*/
public function testValueWithValue($selector, $value, string $js)
{
Expand Down
78 changes: 78 additions & 0 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,84 @@ public function test_assert_dont_see_in()
}
}

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

$element = m::mock(stdClass::class);
$element->shouldReceive('getText')->andReturn('');

$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->assertSeeEmptyTextIn('foo');
}

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

$element = m::mock(stdClass::class);
$element->shouldReceive('getText')->andReturn('foo');

$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);

try {
$browser->assertSeeEmptyTextIn('foo');
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString(
'Did not see expected text [\'\'] within element [body foo].',
$e->getMessage()
);
}
}

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

$element = m::mock(stdClass::class);
$element->shouldReceive('getText')->andReturn('');

$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);

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

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

$element = m::mock(stdClass::class);
$element->shouldReceive('getText')->andReturn('foo');

$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->assertDontSeeEmptyTextIn('foo');
}

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