You are here

public function AdminTest::testCompactMode in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest::testCompactMode()
  2. 9 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 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);

  // 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.');
}