Skip to content

Commit aed4cbb

Browse files
author
Giulio Troccoli-Allard
committed
Add assertAriaAttribute method
1 parent d456cf2 commit aed4cbb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Concerns/MakesAssertions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,19 @@ public function assertDataAttribute($selector, $attribute, $value)
588588
return $this->assertAttribute($selector, 'data-' . $attribute, $value);
589589
}
590590

591+
/**
592+
* Assert that the element at the given selector has the given aria attribute value.
593+
*
594+
* @param string $selector
595+
* @param string $attribute
596+
* @param string $value
597+
* @return $this
598+
*/
599+
public function assertAriaAttribute($selector, $attribute, $value)
600+
{
601+
return $this->assertAttribute($selector, 'aria-' . $attribute, $value);
602+
}
603+
591604
/**
592605
* Assert that the element with the given selector is visible.
593606
*

tests/MakesAssertionsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,43 @@ public function test_assert_data_attribute()
127127
}
128128
}
129129

130+
public function test_assert_aria_attribute()
131+
{
132+
$driver = m::mock(stdClass::class);
133+
$element = m::mock(stdClass::class);
134+
$element->shouldReceive('getAttribute')->with('aria-bar')->andReturn(
135+
'joe',
136+
null,
137+
'sue'
138+
);
139+
$resolver = m::mock(stdClass::class);
140+
$resolver->shouldReceive('format')->with('foo')->andReturn('Foo');
141+
$resolver->shouldReceive('findOrFail')->with('foo')->andReturn($element);
142+
$browser = new Browser($driver, $resolver);
143+
144+
$browser->assertAriaAttribute('foo', 'bar', 'joe');
145+
146+
try {
147+
$browser->assertAriaAttribute('foo', 'bar', 'joe');
148+
$this->fail();
149+
} catch (ExpectationFailedException $e) {
150+
$this->assertStringContainsString(
151+
"Did not see expected attribute [aria-bar] within element [Foo].",
152+
$e->getMessage()
153+
);
154+
}
155+
156+
try {
157+
$browser->assertAriaAttribute('foo', 'bar', 'joe');
158+
$this->fail();
159+
} catch (ExpectationFailedException $e) {
160+
$this->assertStringContainsString(
161+
"Expected 'aria-bar' attribute [joe] does not equal actual value [sue].",
162+
$e->getMessage()
163+
);
164+
}
165+
}
166+
130167
public function test_assert_present()
131168
{
132169
$driver = m::mock(stdClass::class);

0 commit comments

Comments
 (0)