CookieUpdateTest.php in Style Switcher 8.2
File
tests/src/Functional/CookieUpdateTest.php
View source
<?php
namespace Drupal\Tests\styleswitcher\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
class CookieUpdateTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use AssertTrait;
use HelperTrait;
protected static $modules = [
'styleswitcher',
'styleswitcher_test_legacy_cookies',
'dynamic_page_cache',
'page_cache',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$this
->enablePageCaching();
}
public function testCookieUpdates(int $version, string $cookie_name) {
$styles['custom/default'] = $this
->composeStyleMockingPath('Default');
$styles['theme/active'] = $this
->composeStyleMockingPath('Active', 'theme');
$this
->config('styleswitcher.custom_styles')
->set('styles', $styles)
->save();
$settings = $this
->composeStylesSettings([
'custom/default',
'theme/active',
]);
$settings['custom/default']['is_default'] = TRUE;
$this
->config('styleswitcher.styles_settings')
->set("settings.{$this->defaultTheme}", $settings)
->save();
$this
->assertActiveStylePath('custom/default');
$this
->drupalGet('styleswitcher-test-legacy-cookies/' . $version);
$this
->assertActiveStylePath('theme/active');
$this
->assertSame('theme/active', $this
->getSession()
->getCookie("styleswitcher[{$this->defaultTheme}]"));
$this
->assertNull($this
->getSession()
->getCookie($cookie_name));
}
public function providerCookieUpdates() : array {
return [
[
1,
'styleSwitcher',
],
[
2,
'styleswitcher',
],
[
3,
'styleswitcher',
],
];
}
}