HeaderTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class HeaderTest extends TestCase
  5. {
  6. /**
  7. * test referrer.
  8. *
  9. * @group issue130
  10. */
  11. public function testIssue130()
  12. {
  13. $this->getSession()->visit($this->pathTo('/issue130.php?p=1'));
  14. $page = $this->getSession()->getPage();
  15. $page->clickLink('Go to 2');
  16. $this->assertEquals($this->pathTo('/issue130.php?p=1'), $page->getText());
  17. }
  18. public function testHeaders()
  19. {
  20. $this->getSession()->setRequestHeader('Accept-Language', 'fr');
  21. $this->getSession()->visit($this->pathTo('/headers.php'));
  22. $this->assertContains('[HTTP_ACCEPT_LANGUAGE] => fr', $this->getSession()->getPage()->getContent());
  23. }
  24. public function testSetUserAgent()
  25. {
  26. $session = $this->getSession();
  27. $session->setRequestHeader('user-agent', 'foo bar');
  28. $session->visit($this->pathTo('/headers.php'));
  29. $this->assertContains('[HTTP_USER_AGENT] => foo bar', $session->getPage()->getContent());
  30. }
  31. public function testResetHeaders()
  32. {
  33. $session = $this->getSession();
  34. $session->setRequestHeader('X-Mink-Test', 'test');
  35. $session->visit($this->pathTo('/headers.php'));
  36. $this->assertContains(
  37. '[HTTP_X_MINK_TEST] => test',
  38. $session->getPage()->getContent(),
  39. 'The custom header should be sent',
  40. true
  41. );
  42. $session->reset();
  43. $session->visit($this->pathTo('/headers.php'));
  44. $this->assertNotContains(
  45. '[HTTP_X_MINK_TEST] => test',
  46. $session->getPage()->getContent(),
  47. 'The custom header should not be sent after resetting',
  48. true
  49. );
  50. }
  51. public function testResponseHeaders()
  52. {
  53. $this->getSession()->visit($this->pathTo('/response_headers.php'));
  54. $headers = $this->getSession()->getResponseHeaders();
  55. $lowercasedHeaders = array();
  56. foreach ($headers as $name => $value) {
  57. $lowercasedHeaders[str_replace('_', '-', strtolower($name))] = $value;
  58. }
  59. $this->assertArrayHasKey('x-mink-test', $lowercasedHeaders);
  60. }
  61. }