1 simpletest.test | public SimpleTestBrowserTestCase::testCookies() |
Tests that cookies set during a request are available for testing.
File
- core/
modules/ simpletest/ tests/ simpletest.test, line 414 - Tests for simpletest.module.
Class
- SimpleTestBrowserTestCase
- Test internal testing framework browser.
Code
public function testCookies() {
// Check that the $this->cookies property is populated when a user logs in.
$user = $this->backdropCreateUser();
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
$this->backdropPost('user/login', $edit, t('Log in'));
$this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');
// Check that the name and value of the cookie match the request data.
$cookie_header = $this->backdropGetHeader('set-cookie', TRUE);
// The name and value are located at the start of the string, separated by
// an equals sign and ending in a semicolon.
preg_match('/^([^=]+)=([^;]+)/', $cookie_header, $matches);
$name = $matches[1];
$value = $matches[2];
$this->assertTrue(array_key_exists($name, $this->cookies), 'The cookie name is correct.');
$this->assertEqual($value, $this->cookies[$name]['value'], 'The cookie value is correct.');
// Set a flag indicating that a cookie has been set in this test.
// @see SimpleTestBrowserTestCase::testCookieDoesNotBleed().
self::$cookieSet = TRUE;
}