function AdminTest::testCompactMode

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testCompactMode()
  2. 10 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testCompactMode()
  3. 11.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testCompactMode()

Tests compact mode.

File

core/modules/system/tests/src/Functional/System/AdminTest.php, line 154

Class

AdminTest
Tests output on administrative pages and compact mode functionality.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testCompactMode() {
    $session = $this->getSession();
    // The front page defaults to 'user/login', which redirects to 'user/{user}'
    // for authenticated users. We cannot use '<front>', since this does not
    // match the redirected url.
    $frontpage_url = 'user/' . $this->adminUser
        ->id();
    $this->drupalGet('admin/compact/on');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Verify that the user is redirected to the front page after turning on
    // compact mode.
    $this->assertSession()
        ->addressEquals($frontpage_url);
    $this->assertEquals('1', $session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode turns on.');
    $this->drupalGet('admin/compact/on');
    $this->assertEquals('1', $session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode remains on after a repeat call.');
    $this->drupalGet('');
    $this->assertEquals('1', $session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode persists on new requests.');
    $this->drupalGet('admin/compact/off');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Verify that the user is redirected to the front page after turning off
    // compact mode.
    $this->assertSession()
        ->addressEquals($frontpage_url);
    $this->assertNull($session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode turns off.');
    $this->drupalGet('admin/compact/off');
    $this->assertNull($session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode remains off after a repeat call.');
    $this->drupalGet('');
    $this->assertNull($session->getCookie('Drupal.visitor.admin_compact_mode'), 'Compact mode persists off new requests.');
}

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