public function ConfigTest::testConfigStylesSettings in Style Switcher 8.2
Same name and namespace in other branches
- 3.0.x tests/src/Functional/ConfigTest.php \Drupal\Tests\styleswitcher\Functional\ConfigTest::testConfigStylesSettings()
Tests the styles settings config.
File
- tests/
src/ Functional/ ConfigTest.php, line 103
Class
- ConfigTest
- Tests Style Switcher configs.
Namespace
Drupal\Tests\styleswitcher\FunctionalCode
public function testConfigStylesSettings() {
$config_styles = $this
->config('styleswitcher.custom_styles');
$config_settings = $this
->config('styleswitcher.styles_settings');
$styles = $config_styles
->get('styles');
$names = array_keys($styles);
$settings = $this
->composeStylesSettings($names);
// Set weights by a random order.
shuffle($names);
foreach ($names as $i => $name) {
$settings[$name]['weight'] = $i;
}
// Set a random default.
$default = array_rand($settings);
$settings[$default]['is_default'] = TRUE;
$config_settings
->set("settings.{$this->defaultTheme}", $settings)
->save();
$expected = array_column(array_merge(array_flip($names), $styles), 'label');
$this
->assertStylesList($expected, '#block-styleswitcher');
// Check the default style by testing an active style's CSS URL.
$this
->assertActiveStylePath($default);
// Change order.
shuffle($names);
foreach ($names as $i => $name) {
$config_settings
->set("settings.{$this->defaultTheme}.{$name}.weight", $i);
}
$config_settings
->save();
$expected = array_column(array_merge(array_flip($names), $styles), 'label');
$this
->assertStylesList($expected, '#block-styleswitcher');
// Disable random styles.
foreach (array_rand($names, 5) as $i) {
$name = $names[$i];
$config_settings
->set("settings.{$this->defaultTheme}.{$name}.status", FALSE);
unset($names[$i], $expected[$i]);
}
$config_settings
->save();
$this
->assertStylesList($expected, '#block-styleswitcher');
// Set a new default.
$config_settings
->set("settings.{$this->defaultTheme}.{$default}.is_default", FALSE);
$enabled = array_flip($names);
unset($enabled[$default]);
$default = array_rand($enabled);
$config_settings
->set("settings.{$this->defaultTheme}.{$default}.is_default", TRUE)
->save();
$this
->assertActiveStylePath($default);
// Remove a custom style, but not from styles settings.
$config_styles
->clear("styles.{$default}")
->save();
unset($expected[array_search($default, $names)]);
$this
->assertStylesList($expected, '#block-styleswitcher');
}