CookieTest.php in Style Switcher 8.2
File
tests/src/Functional/CookieTest.php
View source
<?php
namespace Drupal\Tests\styleswitcher\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
class CookieTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use AssertTrait;
use HelperTrait;
protected static $modules = [
'styleswitcher',
'styleswitcher_test_theme_per_page',
'block',
'dynamic_page_cache',
'page_cache',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$this
->enablePageCaching();
$this
->drupalPlaceBlock('styleswitcher_styleswitcher', [
'id' => 'styleswitcher',
]);
}
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();
$this
->assertActiveStylePath('custom/a');
$this
->drupalGet('user/login');
$this
->click('a.style-switcher.style-b');
$this
->assertSame('custom/b', $this
->getSession()
->getCookie("styleswitcher[{$this->defaultTheme}]"));
$this
->drupalGet("styleswitcher-test-theme-per-page/{$this->defaultTheme}");
$this
->assertSame('custom/b', $this
->getSession()
->getCookie("styleswitcher[{$this->defaultTheme}]"));
}
}