@@ -53,6 +53,117 @@ public function test_assert_title_contains()
5353 }
5454 }
5555
56+ public function test_assert_attribute ()
57+ {
58+ $ driver = m::mock (stdClass::class);
59+ $ element = m::mock (stdClass::class);
60+ $ element ->shouldReceive ('getAttribute ' )->with ('bar ' )->andReturn (
61+ 'joe ' ,
62+ null ,
63+ 'sue '
64+ );
65+ $ resolver = m::mock (stdClass::class);
66+ $ resolver ->shouldReceive ('format ' )->with ('foo ' )->andReturn ('Foo ' );
67+ $ resolver ->shouldReceive ('findOrFail ' )->with ('foo ' )->andReturn ($ element );
68+ $ browser = new Browser ($ driver , $ resolver );
69+
70+ $ browser ->assertAttribute ('foo ' , 'bar ' , 'joe ' );
71+
72+ try {
73+ $ browser ->assertAttribute ('foo ' , 'bar ' , 'joe ' );
74+ $ this ->fail ();
75+ } catch (ExpectationFailedException $ e ) {
76+ $ this ->assertStringContainsString (
77+ "Did not see expected attribute [bar] within element [Foo]. " ,
78+ $ e ->getMessage ()
79+ );
80+ }
81+
82+ try {
83+ $ browser ->assertAttribute ('foo ' , 'bar ' , 'joe ' );
84+ $ this ->fail ();
85+ } catch (ExpectationFailedException $ e ) {
86+ $ this ->assertStringContainsString (
87+ "Expected 'bar' attribute [joe] does not equal actual value [sue]. " ,
88+ $ e ->getMessage ()
89+ );
90+ }
91+ }
92+
93+ public function test_assert_data_attribute ()
94+ {
95+ $ driver = m::mock (stdClass::class);
96+ $ element = m::mock (stdClass::class);
97+ $ element ->shouldReceive ('getAttribute ' )->with ('data-bar ' )->andReturn (
98+ 'joe ' ,
99+ null ,
100+ 'sue '
101+ );
102+ $ resolver = m::mock (stdClass::class);
103+ $ resolver ->shouldReceive ('format ' )->with ('foo ' )->andReturn ('Foo ' );
104+ $ resolver ->shouldReceive ('findOrFail ' )->with ('foo ' )->andReturn ($ element );
105+ $ browser = new Browser ($ driver , $ resolver );
106+
107+ $ browser ->assertDataAttribute ('foo ' , 'bar ' , 'joe ' );
108+
109+ try {
110+ $ browser ->assertDataAttribute ('foo ' , 'bar ' , 'joe ' );
111+ $ this ->fail ();
112+ } catch (ExpectationFailedException $ e ) {
113+ $ this ->assertStringContainsString (
114+ "Did not see expected attribute [data-bar] within element [Foo]. " ,
115+ $ e ->getMessage ()
116+ );
117+ }
118+
119+ try {
120+ $ browser ->assertDataAttribute ('foo ' , 'bar ' , 'joe ' );
121+ $ this ->fail ();
122+ } catch (ExpectationFailedException $ e ) {
123+ $ this ->assertStringContainsString (
124+ "Expected 'data-bar' attribute [joe] does not equal actual value [sue]. " ,
125+ $ e ->getMessage ()
126+ );
127+ }
128+ }
129+
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+
56167 public function test_assert_present ()
57168 {
58169 $ driver = m::mock (stdClass::class);
0 commit comments