function ToolbarTestCase::testToolbarCollapsedCookie

Tests toggling the toolbar collapsed cookie.

File

modules/toolbar/toolbar.test, line 26

Class

ToolbarTestCase

Code

function testToolbarCollapsedCookie() {
    $this->drupalGet('toolbar/toggle');
    $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
    $this->assertTrue(strpos('Drupal.toolbar.collapsed=1; path=/; SameSite=Lax', $set_cookie) !== FALSE, 'Toolbar cookie set to collapsed by default.');
    // The next request should toggle the toolbar.collapsed cookie to off.
    $this->drupalGet('toolbar/toggle');
    $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
    $this->assertTrue((bool) preg_match('#Drupal.toolbar.collapsed=deleted; expires=Thu, 01.Jan.1970 00:00:01 GMT;( Max-Age=0;)? path=\\/; SameSite=Lax#', $set_cookie), 'Toolbar cookie toggled to off (deleted).');
    // The next request should toggle the toolbar.collapsed cookie back to 1.
    $this->drupalGet('toolbar/toggle');
    $set_cookie = $this->drupalGetHeader('set-cookie', TRUE);
    $this->assertTrue(strpos('Drupal.toolbar.collapsed=1; path=/; SameSite=Lax', $set_cookie) !== FALSE, 'Toolbar cookie toggled to 1.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.