You are here

public function ConfigTest::testConfigCustomStyles in Style Switcher 8.2

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

Tests the custom styles config.

File

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

Class

ConfigTest
Tests Style Switcher configs.

Namespace

Drupal\Tests\styleswitcher\Functional

Code

public function testConfigCustomStyles() {
  $config = $this
    ->config('styleswitcher.custom_styles');
  $expected = array_column($config
    ->get('styles'), 'label');
  $this
    ->assertStylesList($expected, '#block-styleswitcher');

  // Add a style.
  $config
    ->set('styles.custom/z', $this
    ->composeStyleMockingPath('Z'))
    ->save();
  $expected[] = 'Z';
  $this
    ->assertStylesList($expected, '#block-styleswitcher');

  // Remove a style.
  $i = array_rand($expected);
  $name = 'custom/' . strtolower($expected[$i]);
  $config
    ->clear("styles.{$name}")
    ->save();
  unset($expected[$i]);
  $this
    ->assertStylesList($expected, '#block-styleswitcher');

  // Relabel a style.
  $i = array_rand($expected);
  $name = 'custom/' . strtolower($expected[$i]);
  $new_label = $this
    ->randomString();
  $config
    ->set("styles.{$name}.label", $new_label)
    ->save();
  $expected[$i] = $new_label;
  $this
    ->assertStylesList($expected, '#block-styleswitcher');
}