File tree 2 files changed +76
-0
lines changed
2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,42 @@ public function assertPathBeginsWith($path)
168
168
return $ this ;
169
169
}
170
170
171
+ /**
172
+ * Assert that the current URL path ends with the given path.
173
+ *
174
+ * @param string $path
175
+ * @return $this
176
+ */
177
+ public function assertPathEndsWith ($ path )
178
+ {
179
+ $ actualPath = parse_url ($ this ->driver ->getCurrentURL (), PHP_URL_PATH ) ?? '' ;
180
+
181
+ PHPUnit::assertStringEndsWith (
182
+ $ path , $ actualPath ,
183
+ "Actual path [ {$ actualPath }] does not end with expected path [ {$ path }]. "
184
+ );
185
+
186
+ return $ this ;
187
+ }
188
+
189
+ /**
190
+ * Assert that the current URL path contains the given path.
191
+ *
192
+ * @param string $path
193
+ * @return $this
194
+ */
195
+ public function assertPathContains ($ path )
196
+ {
197
+ $ actualPath = parse_url ($ this ->driver ->getCurrentURL (), PHP_URL_PATH ) ?? '' ;
198
+
199
+ PHPUnit::assertStringContainsString (
200
+ $ path , $ actualPath ,
201
+ "Actual path [ {$ actualPath }] does not contain the expected string [ {$ path }]. "
202
+ );
203
+
204
+ return $ this ;
205
+ }
206
+
171
207
/**
172
208
* Assert that the current path matches the given path.
173
209
*
Original file line number Diff line number Diff line change @@ -219,6 +219,46 @@ public function test_assert_path_begins_with()
219
219
}
220
220
}
221
221
222
+ public function test_assert_path_ends_with (): void
223
+ {
224
+ $ driver = m::mock (stdClass::class);
225
+ $ driver ->shouldReceive ('getCurrentURL ' )->andReturn (
226
+ 'http://www.google.com/test/ending '
227
+ );
228
+ $ browser = new Browser ($ driver );
229
+
230
+ $ browser ->assertPathEndsWith ('ending ' );
231
+
232
+ try {
233
+ $ browser ->assertPathEndsWith ('/not-the-ending-expected ' );
234
+ } catch (ExpectationFailedException $ e ) {
235
+ $ this ->assertStringContainsString (
236
+ 'Actual path [/test/ending] does not end with expected path [/not-the-ending-expected]. ' ,
237
+ $ e ->getMessage ()
238
+ );
239
+ }
240
+ }
241
+
242
+ public function test_assert_path_contains (): void
243
+ {
244
+ $ driver = m::mock (stdClass::class);
245
+ $ driver ->shouldReceive ('getCurrentURL ' )->andReturn (
246
+ 'http://www.google.com/admin/test/1/details '
247
+ );
248
+ $ browser = new Browser ($ driver );
249
+
250
+ $ browser ->assertPathContains ('/test/1/ ' );
251
+
252
+ try {
253
+ $ browser ->assertPathContains ('/test/2/ ' );
254
+ } catch (ExpectationFailedException $ e ) {
255
+ $ this ->assertStringContainsString (
256
+ 'Actual path [/admin/test/1/details] does not contain the expected string [/test/2/]. ' ,
257
+ $ e ->getMessage ()
258
+ );
259
+ }
260
+ }
261
+
222
262
public function test_assert_path_is ()
223
263
{
224
264
$ driver = m::mock (stdClass::class);
You can’t perform that action at this time.
0 commit comments