You are here

class CookieTest in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-foundation/Tests/CookieTest.php \Symfony\Component\HttpFoundation\Tests\CookieTest
  2. 8 vendor/symfony/browser-kit/Tests/CookieTest.php \Symfony\Component\BrowserKit\Tests\CookieTest
  3. 8 vendor/behat/mink/driver-testsuite/tests/Basic/CookieTest.php \Behat\Mink\Tests\Driver\Basic\CookieTest
Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/driver-testsuite/tests/Basic/CookieTest.php \Behat\Mink\Tests\Driver\Basic\CookieTest

Hierarchy

  • class \Behat\Mink\Tests\Driver\TestCase extends \Behat\Mink\Tests\Driver\PHPUnit_Framework_TestCase

Expanded class hierarchy of CookieTest

File

vendor/behat/mink/driver-testsuite/tests/Basic/CookieTest.php, line 7

Namespace

Behat\Mink\Tests\Driver\Basic
View source
class CookieTest extends TestCase {

  /**
   * test cookie decoding.
   *
   * @group issue140
   */
  public function testIssue140() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/issue140.php'));
    $this
      ->getSession()
      ->getPage()
      ->fillField('cookie_value', 'some:value;');
    $this
      ->getSession()
      ->getPage()
      ->pressButton('Set cookie');
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/issue140.php?show_value'));
    $this
      ->assertEquals('some:value;', $this
      ->getSession()
      ->getCookie('tc'));
    $this
      ->assertEquals('some:value;', $this
      ->getSession()
      ->getPage()
      ->getText());
  }
  public function testCookie() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: NO', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->assertNull($this
      ->getSession()
      ->getCookie('srvr_cookie'));
    $this
      ->getSession()
      ->setCookie('srvr_cookie', 'client cookie set');
    $this
      ->getSession()
      ->reload();
    $this
      ->assertContains('Previous cookie: client cookie set', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->assertEquals('client cookie set', $this
      ->getSession()
      ->getCookie('srvr_cookie'));
    $this
      ->getSession()
      ->setCookie('srvr_cookie', null);
    $this
      ->getSession()
      ->reload();
    $this
      ->assertContains('Previous cookie: NO', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page1.php'));
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: srv_var_is_set', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->setCookie('srvr_cookie', null);
    $this
      ->getSession()
      ->reload();
    $this
      ->assertContains('Previous cookie: NO', $this
      ->getSession()
      ->getPage()
      ->getText());
  }

  /**
   * @dataProvider cookieWithPathsDataProvider
   */
  public function testCookieWithPaths($cookieRemovalMode) {

    // start clean
    $session = $this
      ->getSession();
    $session
      ->visit($this
      ->pathTo('/sub-folder/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: NO', $session
      ->getPage()
      ->getText());

    // cookie from root path is accessible in sub-folder
    $session
      ->visit($this
      ->pathTo('/cookie_page1.php'));
    $session
      ->visit($this
      ->pathTo('/sub-folder/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: srv_var_is_set', $session
      ->getPage()
      ->getText());

    // cookie from sub-folder overrides cookie from root path
    $session
      ->visit($this
      ->pathTo('/sub-folder/cookie_page1.php'));
    $session
      ->visit($this
      ->pathTo('/sub-folder/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: srv_var_is_set_sub_folder', $session
      ->getPage()
      ->getText());
    if ($cookieRemovalMode == 'session_reset') {
      $session
        ->reset();
    }
    elseif ($cookieRemovalMode == 'cookie_delete') {
      $session
        ->setCookie('srvr_cookie', null);
    }

    // cookie is removed from all paths
    $session
      ->visit($this
      ->pathTo('/sub-folder/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: NO', $session
      ->getPage()
      ->getText());
  }
  public function cookieWithPathsDataProvider() {
    return array(
      array(
        'session_reset',
      ),
      array(
        'cookie_delete',
      ),
    );
  }
  public function testReset() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page1.php'));
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: srv_var_is_set', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->reset();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: NO', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->setCookie('srvr_cookie', 'test_cookie');
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: test_cookie', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->reset();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page2.php'));
    $this
      ->assertContains('Previous cookie: NO', $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->setCookie('client_cookie1', 'some_val');
    $this
      ->getSession()
      ->setCookie('client_cookie2', 123);
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/session_test.php'));
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page1.php'));
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/print_cookies.php'));
    $this
      ->assertContains("'client_cookie1' = 'some_val'", $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->assertContains("'client_cookie2' = '123'", $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->assertContains("_SESS' = ", $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->assertContains(" 'srvr_cookie' = 'srv_var_is_set'", $this
      ->getSession()
      ->getPage()
      ->getText());
    $this
      ->getSession()
      ->reset();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/print_cookies.php'));
    $this
      ->assertContains('array ( )', $this
      ->getSession()
      ->getPage()
      ->getText());
  }
  public function testHttpOnlyCookieIsDeleted() {
    $this
      ->getSession()
      ->restart();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page3.php'));
    $this
      ->assertEquals('Has Cookie: false', $this
      ->findById('cookie-status')
      ->getText());
    $this
      ->getSession()
      ->reload();
    $this
      ->assertEquals('Has Cookie: true', $this
      ->findById('cookie-status')
      ->getText());
    $this
      ->getSession()
      ->restart();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/cookie_page3.php'));
    $this
      ->assertEquals('Has Cookie: false', $this
      ->findById('cookie-status')
      ->getText());
  }
  public function testSessionPersistsBetweenRequests() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/session_test.php'));
    $webAssert = $this
      ->getAssertSession();
    $node = $webAssert
      ->elementExists('css', '#session-id');
    $sessionId = $node
      ->getText();
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/session_test.php'));
    $node = $webAssert
      ->elementExists('css', '#session-id');
    $this
      ->assertEquals($sessionId, $node
      ->getText());
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/session_test.php?login'));
    $node = $webAssert
      ->elementExists('css', '#session-id');
    $this
      ->assertNotEquals($sessionId, $newSessionId = $node
      ->getText());
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/session_test.php'));
    $node = $webAssert
      ->elementExists('css', '#session-id');
    $this
      ->assertEquals($newSessionId, $node
      ->getText());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CookieTest::cookieWithPathsDataProvider public function
CookieTest::testCookie public function
CookieTest::testCookieWithPaths public function @dataProvider cookieWithPathsDataProvider
CookieTest::testHttpOnlyCookieIsDeleted public function
CookieTest::testIssue140 public function test cookie decoding.
CookieTest::testReset public function
CookieTest::testSessionPersistsBetweenRequests public function
TestCase::$config private static property
TestCase::$mink private static property Mink session manager.
TestCase::checkRequirements protected function
TestCase::createDriver protected function Creates a new driver instance.
TestCase::findById protected function
TestCase::getAssertSession protected function Returns assert session.
TestCase::getConfig private static function
TestCase::getSession protected function Returns session.
TestCase::mapRemoteFilePath protected function Map remote file path.
TestCase::onNotSuccessfulTest protected function
TestCase::pathTo protected function
TestCase::safePageWait protected function Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
TestCase::setUpBeforeClass public static function Initializes the test case.
TestCase::tearDown protected function