You are here

public function ConfigTest::testActiveStyleOnStyleDelete in Style Switcher 3.0.x

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

Tests active style is replaced with default one when deleted.

File

tests/src/Functional/ConfigTest.php, line 166

Class

ConfigTest
Tests Style Switcher configs.

Namespace

Drupal\Tests\styleswitcher\Functional

Code

public function testActiveStyleOnStyleDelete() {
  $config_styles = $this
    ->config('styleswitcher.custom_styles');
  $config_settings = $this
    ->config('styleswitcher.styles_settings');
  list($default, $active) = array_rand($config_styles
    ->get('styles'), 2);
  $settings = $this
    ->composeStylesSettings(array_keys($config_styles
    ->get('styles')));
  $settings[$default]['is_default'] = TRUE;
  $config_settings
    ->set("settings.{$this->defaultTheme}", $settings)
    ->save();

  // Click a style, and confirm it's active.
  $this
    ->drupalGet('');
  $this
    ->click('a.style-switcher.style-' . substr($active, 7));
  $this
    ->assertActiveStylePath($active);

  // Remove an active style.
  $config_styles
    ->clear("styles.{$active}")
    ->save();
  $this
    ->assertActiveStylePath($default);
}