You are here

public function CookieTest::testCookie in Style Switcher 3.0.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/CookieTest.php \Drupal\Tests\styleswitcher\Functional\CookieTest::testCookie()

Tests the cookie is set for the whole site.

File

tests/src/Functional/CookieTest.php, line 50

Class

CookieTest
Tests Style Switcher cookies.

Namespace

Drupal\Tests\styleswitcher\Functional

Code

public function testCookie() {
  $this
    ->config('styleswitcher.custom_styles')
    ->set('styles', $this
    ->composeStylesMockingPaths([
    'A',
    'B',
  ]))
    ->save();
  $settings = $this
    ->composeStylesSettings([
    'custom/a',
    'custom/b',
  ]);
  $settings['custom/a']['is_default'] = TRUE;
  $this
    ->config('styleswitcher.styles_settings')
    ->set("settings.{$this->defaultTheme}", $settings)
    ->save();

  // Check the default style is acting as active without a cookie.
  $this
    ->assertActiveStylePath('custom/a');

  // Click a style, and test the cookie.
  $this
    ->drupalGet('user/login');
  $this
    ->click('a.style-switcher.style-b');
  $this
    ->assertSame('custom/b', $this
    ->getSession()
    ->getCookie("styleswitcher[{$this->defaultTheme}]"));

  // Check the cookie on another page.
  $this
    ->drupalGet("styleswitcher-test-theme-per-page/{$this->defaultTheme}");
  $this
    ->assertSame('custom/b', $this
    ->getSession()
    ->getCookie("styleswitcher[{$this->defaultTheme}]"));
}