NavigationTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class NavigationTest extends TestCase
  5. {
  6. public function testRedirect()
  7. {
  8. $this->getSession()->visit($this->pathTo('/redirector.php'));
  9. $this->assertEquals($this->pathTo('/redirect_destination.html'), $this->getSession()->getCurrentUrl());
  10. }
  11. public function testPageControls()
  12. {
  13. $this->getSession()->visit($this->pathTo('/randomizer.php'));
  14. $number1 = $this->getAssertSession()->elementExists('css', '#number')->getText();
  15. $this->getSession()->reload();
  16. $number2 = $this->getAssertSession()->elementExists('css', '#number')->getText();
  17. $this->assertNotEquals($number1, $number2);
  18. $this->getSession()->visit($this->pathTo('/links.html'));
  19. $this->getSession()->getPage()->clickLink('Random number page');
  20. $this->assertEquals($this->pathTo('/randomizer.php'), $this->getSession()->getCurrentUrl());
  21. $this->getSession()->back();
  22. $this->assertEquals($this->pathTo('/links.html'), $this->getSession()->getCurrentUrl());
  23. $this->getSession()->forward();
  24. $this->assertEquals($this->pathTo('/randomizer.php'), $this->getSession()->getCurrentUrl());
  25. }
  26. public function testLinks()
  27. {
  28. $this->getSession()->visit($this->pathTo('/links.html'));
  29. $page = $this->getSession()->getPage();
  30. $link = $page->findLink('Redirect me to');
  31. $this->assertNotNull($link);
  32. $this->assertRegExp('/redirector\.php$/', $link->getAttribute('href'));
  33. $link->click();
  34. $this->assertEquals($this->pathTo('/redirect_destination.html'), $this->getSession()->getCurrentUrl());
  35. $this->getSession()->visit($this->pathTo('/links.html'));
  36. $page = $this->getSession()->getPage();
  37. $link = $page->findLink('basic form image');
  38. $this->assertNotNull($link);
  39. $this->assertRegExp('/basic_form\.html$/', $link->getAttribute('href'));
  40. $link->click();
  41. $this->assertEquals($this->pathTo('/basic_form.html'), $this->getSession()->getCurrentUrl());
  42. $this->getSession()->visit($this->pathTo('/links.html'));
  43. $page = $this->getSession()->getPage();
  44. $link = $page->findLink('Link with a ');
  45. $this->assertNotNull($link);
  46. $this->assertRegExp('/links\.html\?quoted$/', $link->getAttribute('href'));
  47. $link->click();
  48. $this->assertEquals($this->pathTo('/links.html?quoted'), $this->getSession()->getCurrentUrl());
  49. }
  50. }