public function FormTest::testEmptyStyleOps in Style Switcher 8.2
Same name and namespace in other branches
- 3.0.x tests/src/Functional/FormTest.php \Drupal\Tests\styleswitcher\Functional\FormTest::testEmptyStyleOps()
Tests edit and delete operations with a default empty style.
File
- tests/
src/ Functional/ FormTest.php, line 116
Class
- FormTest
- Tests Style Switcher forms.
Namespace
Drupal\Tests\styleswitcher\FunctionalCode
public function testEmptyStyleOps() {
$assert = $this
->assertSession();
// Test the default empty style is in the table.
$this
->drupalGet($this->adminPath);
$assert
->elementTextContains('css', '#edit-styleswitcher-custom-styles tbody', 'Default');
// Test the style is in the theme config form, default.
$this
->drupalGet($this->adminPath . "/settings/{$this->defaultTheme}");
$assert
->fieldValueEquals('settings[default]', 'custom/default');
$assert
->fieldDisabled('settings[enabled][custom/default]');
// Test the style is editable and in the config after saving.
$this
->drupalGet($this->adminPath . '/custom/default');
$assert
->elementExists('css', 'form#styleswitcher-style-form');
$label = $this
->randomString();
$name = strtolower($this
->randomMachineName(10));
$edit = [
'label' => $label,
'name' => $name,
];
$this
->submitForm($edit, 'Save');
$assert
->pageTextContains('has been saved.');
$styles = [
'custom/' . $name => [
'label' => $label,
'name' => 'custom/' . $name,
'path' => NULL,
],
];
$this
->assertSame($styles, $this
->config('styleswitcher.custom_styles')
->get('styles'));
$this
->assertArrayNotHasKey('custom/default', $this
->config('styleswitcher.custom_styles')
->get('styles'));
// Test the style is not deletable.
$assert
->linkByHrefNotExists($this->adminPath . '/custom/' . $name . '/delete');
$this
->drupalGet($this->adminPath . '/custom/' . $name);
$assert
->linkByHrefNotExists($this->adminPath . '/custom/' . $name . '/delete');
$this
->drupalGet($this->adminPath . '/custom/' . $name . '/delete');
$assert
->elementExists('css', 'form#styleswitcher-style-delete-form');
$this
->submitForm([], 'Confirm');
$assert
->pageTextContains('The blank style cannot be deleted.');
$assert
->elementTextContains('css', '#edit-styleswitcher-custom-styles tbody', $label);
$this
->assertArrayHasKey('custom/' . $name, $this
->config('styleswitcher.custom_styles')
->get('styles'));
}