public function AllowedFormatsTest::testBaseFields in Allowed Formats 8
Test limiting allowed formats on base fields.
File
- tests/
src/ Functional/ AllowedFormatsTest.php, line 113
Class
- AllowedFormatsTest
- Tests the basic functionality of Allowed Formats.
Namespace
Drupal\Tests\allowed_formats\FunctionalCode
public function testBaseFields() {
// Create a vocabulary.
$vocabulary = $this
->createVocabulary();
// Create the text formats as configured for the taxonomy term description
// field.
$roles = [
$this->webUser
->getRoles()[0],
];
$format1 = FilterFormat::create([
'format' => 'basic_html',
'name' => 'basic_html',
'roles' => $roles,
]);
$format1
->save();
$format2 = FilterFormat::create([
'format' => 'restricted_html',
'name' => 'restricted_html',
'roles' => $roles,
]);
$format2
->save();
$format3 = FilterFormat::create([
'format' => 'full_html',
'name' => 'full_html',
'roles' => $roles,
]);
$format3
->save();
// Display the term creation form, we expect the widget to be displayed,
// and the formats 'basic_html', 'restricted_html' and 'full_html' to be
// available.
$this
->drupalLogin($this->webUser);
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertFieldByName("description[0][value]", NULL, 'Widget is displayed');
$this
->assertFieldByName("description[0][format]", NULL, 'Format selector is displayed');
$this
->assertOption('edit-description-0-format--2', 'basic_html');
$this
->assertOption('edit-description-0-format--2', 'restricted_html');
$this
->assertOption('edit-description-0-format--2', 'full_html');
// Enable our test module, which disallows using the 'full_html' format
// using the allowed_formats functionality.
\Drupal::service('module_installer')
->install([
'allowed_formats_base_fields_test',
]);
// Display the term creation form again and check that 'full_html' is
// not available as expected.
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertFieldByName("description[0][value]", NULL, 'Widget is displayed');
$this
->assertFieldByName("description[0][format]", NULL, 'Format selector is displayed');
$this
->assertOption('edit-description-0-format--2', 'basic_html');
$this
->assertOption('edit-description-0-format--2', 'restricted_html');
$this
->assertNoOption('edit-description-0-format--2', 'full_html');
}