public function XBBCodeAdminTest::testTagSet in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Functional/XBBCodeAdminTest.php \Drupal\Tests\xbbcode\Functional\XBBCodeAdminTest::testTagSet()
Create and edit a tag set.
Throws
\Behat\Mink\Exception\ResponseTextException
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ XBBCodeAdminTest.php, line 273
Class
- XBBCodeAdminTest
- Test the administrative interface.
Namespace
Drupal\Tests\xbbcode\FunctionalCode
public function testTagSet() : void {
$tag = $this
->createCustomTag();
$tags = [
'test_plugin_id' => 'test_plugin',
'xbbcode_tag:test_tag_id' => 'test_tag',
'xbbcode_tag:test_tag_external' => 'test_template',
"xbbcode_tag:{$tag['id']}" => $tag['name'],
];
$this
->drupalGet('admin/config/content/xbbcode/sets');
$this
->assertSession()
->pageTextContains('There are no tag sets yet.');
$this
->clickLink('Create tag set');
// There is a checkbox for the format.
$this
->assertSession()
->checkboxNotChecked('formats[xbbcode]');
foreach ($tags as $id => $name) {
$this
->assertSession()
->checkboxNotChecked("_tags[available:{$id}]");
$this
->assertSession()
->fieldValueEquals("_settings[available:{$id}][name]", $name);
}
$tag_set = [
'label' => $this
->randomString(),
'id' => mb_strtolower($this
->randomMachineName()),
'formats[xbbcode]' => 1,
];
$this
->submitForm($tag_set, 'Save');
$this
->assertSession()
->responseContains((string) new FormattableMarkup('The BBCode tag set %set has been created.', [
'%set' => $tag_set['label'],
]));
$this
->assertSession()
->pageTextContains('None');
// The empty tag set is now selected in the format.
$this
->drupalGet('filter/tips');
$this
->assertSession()
->pageTextContains('BBCode is active, but no tags are available.');
$this
->drupalGet('admin/config/content/xbbcode/sets');
$this
->clickLink('Edit');
// The format is checked now.
$this
->assertSession()
->checkboxChecked('formats[xbbcode]');
$invalid_edit = [
'_settings[available:test_plugin_id][name]' => mb_strtolower($this
->randomMachineName()) . 'A',
];
$this
->submitForm($invalid_edit, 'Save');
$this
->assertSession()
->responseContains((string) new FormattableMarkup('%name field is not in the right format.', [
'%name' => 'Tag name',
]));
// Give the four available plugins two names, and enable the first three.
$invalid_edit = [];
foreach (array_keys($tags) as $i => $id) {
$invalid_edit["_settings[available:{$id}][name]"] = $i >= 2 ? 'def' : 'abc';
$invalid_edit["_tags[available:{$id}]"] = $i <= 2;
}
$this
->submitForm($invalid_edit, 'Save');
// Only enabled plugins need unique names.
$this
->assertSession()
->responseContains('The name [abc] is used by multiple tags.');
$this
->assertSession()
->responseNotContains('The name [def] is used by multiple tags.');
$this
->drupalGet('admin/config/content/xbbcode/sets');
$this
->clickLink('Edit');
// Enable only our custom tag.
$edit = [
"_tags[available:xbbcode_tag:{$tag['id']}]" => 1,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->responseContains((string) new FormattableMarkup('The BBCode tag set %set has been updated.', [
'%set' => $tag_set['label'],
]));
$this
->assertSession()
->pageTextContains("[{$tag['name']}]");
$this
->assertSession()
->pageTextNotContains('[test_tag]');
$this
->assertSession()
->pageTextNotContains('[test_template]');
$this
->assertSession()
->pageTextNotContains('[test_plugin]');
// The filter tips are updated; only the custom tag is enabled.
$this
->drupalGet('filter/tips');
$this
->assertSession()
->responseContains("<strong>[{$tag['name']}]</strong>");
$this
->assertSession()
->pageTextContains($tag['sample']);
$this
->assertSession()
->pageTextContains($tag['description']);
$this
->assertSession()
->pageTextNotContains('[test_tag]');
$this
->assertSession()
->pageTextNotContains('[test_template]');
$this
->assertSession()
->pageTextNotContains('[test_plugin]');
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/add/page');
// BBCode is the only format available:
$this
->assertSession()
->pageTextContains('You may use the following BBCode tags:');
$this
->assertSession()
->responseContains((string) new FormattableMarkup('<abbr title="@desc">[@name]</abbr>', [
'@desc' => $tag['description'],
'@name' => $tag['name'],
]));
// Delete the tag set.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/content/xbbcode/sets');
$this
->clickLink('Delete');
$this
->submitForm([], 'Delete');
$this
->assertSession()
->responseContains((string) new FormattableMarkup('The tag set %name has been deleted.', [
'%name' => $tag_set['label'],
]));
// Without a tag set, all tags are enabled again.
$this
->drupalGet('filter/tips');
$this
->assertSession()
->responseContains("<strong>[{$tag['name']}]</strong>");
$this
->assertSession()
->pageTextContains($tag['sample']);
$this
->assertSession()
->pageTextContains($tag['description']);
$this
->assertSession()
->pageTextContains('[test_tag]');
$this
->assertSession()
->pageTextContains('[test_template]');
$this
->assertSession()
->pageTextContains('[test_plugin]');
}