@@ -322,6 +322,30 @@ public function testClick()
322
322
$ this ->assertEquals ('http://www.example.com/foo ' , $ client ->getRequest ()->getUri (), '->click() clicks on links ' );
323
323
}
324
324
325
+ public function testClickLink ()
326
+ {
327
+ $ client = new TestClient ();
328
+ $ client ->setNextResponse (new Response ('<html><a href="/foo">foo</a></html> ' ));
329
+ $ client ->request ('GET ' , 'http://www.example.com/foo/foobar ' );
330
+ $ client ->clickLink ('foo ' );
331
+
332
+ $ this ->assertEquals ('http://www.example.com/foo ' , $ client ->getRequest ()->getUri (), '->click() clicks on links ' );
333
+ }
334
+
335
+ public function testClickLinkNotFound ()
336
+ {
337
+ $ client = new TestClient ();
338
+ $ client ->setNextResponse (new Response ('<html><a href="/foo">foobar</a></html> ' ));
339
+ $ client ->request ('GET ' , 'http://www.example.com/foo/foobar ' );
340
+
341
+ try {
342
+ $ client ->clickLink ('foo ' );
343
+ $ this ->fail ('->clickLink() throws a \InvalidArgumentException if the link could not be found ' );
344
+ } catch (\Exception $ e ) {
345
+ $ this ->assertInstanceOf ('InvalidArgumentException ' , $ e , '->clickLink() throws a \InvalidArgumentException if the link could not be found ' );
346
+ }
347
+ }
348
+
325
349
public function testClickForm ()
326
350
{
327
351
$ client = new TestClient ();
@@ -344,6 +368,37 @@ public function testSubmit()
344
368
$ this ->assertEquals ('http://www.example.com/foo ' , $ client ->getRequest ()->getUri (), '->submit() submit forms ' );
345
369
}
346
370
371
+ public function testSubmitForm ()
372
+ {
373
+ $ client = new TestClient ();
374
+ $ client ->setNextResponse (new Response ('<html><form name="signup" action="/foo"><input type="text" name="username" /><input type="password" name="password" /><input type="submit" value="Register" /></form></html> ' ));
375
+ $ client ->request ('GET ' , 'http://www.example.com/foo/foobar ' );
376
+
377
+ $ client ->submitForm ('Register ' , array (
378
+ 'username ' => 'username ' ,
379
+ 'password ' => 'password ' ,
380
+ ), 'POST ' );
381
+
382
+ $ this ->assertEquals ('http://www.example.com/foo ' , $ client ->getRequest ()->getUri (), '->submit() submit forms ' );
383
+ }
384
+
385
+ public function testSubmitFormNotFound ()
386
+ {
387
+ $ client = new TestClient ();
388
+ $ client ->setNextResponse (new Response ('<html><form action="/foo"><input type="submit" /></form></html> ' ));
389
+ $ client ->request ('GET ' , 'http://www.example.com/foo/foobar ' );
390
+
391
+ try {
392
+ $ client ->submitForm ('Register ' , array (
393
+ 'username ' => 'username ' ,
394
+ 'password ' => 'password ' ,
395
+ ), 'POST ' );
396
+ $ this ->fail ('->submitForm() throws a \InvalidArgumentException if the form could not be found ' );
397
+ } catch (\Exception $ e ) {
398
+ $ this ->assertInstanceOf ('InvalidArgumentException ' , $ e , '->submitForm() throws a \InvalidArgumentException if the form could not be found ' );
399
+ }
400
+ }
401
+
347
402
public function testSubmitPreserveAuth ()
348
403
{
349
404
$ client = new TestClient (array ('PHP_AUTH_USER ' => 'foo ' , 'PHP_AUTH_PW ' => 'bar ' ));
0 commit comments