You are here

public function AdminTest::testCompactMode in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testCompactMode()

Test compact mode.

File

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

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);
  $this
    ->assertUrl($frontpage_url, [], 'The user is redirected to the front page after turning on compact mode.');
  $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);
  $this
    ->assertUrl($frontpage_url, [], 'The user is redirected to the front page after turning off compact mode.');
  $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.');
}