BasicAuthTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class BasicAuthTest extends TestCase
  5. {
  6. /**
  7. * @dataProvider setBasicAuthDataProvider
  8. */
  9. public function testSetBasicAuth($user, $pass, $pageText)
  10. {
  11. $session = $this->getSession();
  12. $session->setBasicAuth($user, $pass);
  13. $session->visit($this->pathTo('/basic_auth.php'));
  14. $this->assertContains($pageText, $session->getPage()->getContent());
  15. }
  16. public function setBasicAuthDataProvider()
  17. {
  18. return array(
  19. array('mink-user', 'mink-password', 'is authenticated'),
  20. array('', '', 'is not authenticated'),
  21. );
  22. }
  23. public function testResetBasicAuth()
  24. {
  25. $session = $this->getSession();
  26. $session->setBasicAuth('mink-user', 'mink-password');
  27. $session->visit($this->pathTo('/basic_auth.php'));
  28. $this->assertContains('is authenticated', $session->getPage()->getContent());
  29. $session->setBasicAuth(false);
  30. $session->visit($this->pathTo('/headers.php'));
  31. $this->assertNotContains('PHP_AUTH_USER', $session->getPage()->getContent());
  32. }
  33. public function testResetWithBasicAuth()
  34. {
  35. $session = $this->getSession();
  36. $session->setBasicAuth('mink-user', 'mink-password');
  37. $session->visit($this->pathTo('/basic_auth.php'));
  38. $this->assertContains('is authenticated', $session->getPage()->getContent());
  39. $session->reset();
  40. $session->visit($this->pathTo('/headers.php'));
  41. $this->assertNotContains('PHP_AUTH_USER', $session->getPage()->getContent());
  42. }
  43. }