drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); // Set up the filter formats used by this test. $basic_html_format = FilterFormat::create([ 'format' => 'basic_html', 'name' => 'Basic HTML', 'filters' => [ 'filter_html' => [ 'status' => 1, 'settings' => [ 'allowed_html' => '


', ], ], ], ]); $basic_html_format->save(); $restricted_html_format = FilterFormat::create([ 'format' => 'restricted_html', 'name' => 'Restricted HTML', 'filters' => [ 'filter_html' => [ 'status' => TRUE, 'weight' => -10, 'settings' => [ 'allowed_html' => '


', ], ], 'filter_autop' => [ 'status' => TRUE, 'weight' => 0, ], 'filter_url' => [ 'status' => TRUE, 'weight' => 0, ], 'filter_htmlcorrector' => [ 'status' => TRUE, 'weight' => 10, ], ], ]); $restricted_html_format->save(); $full_html_format = FilterFormat::create([ 'format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => [], ]); $full_html_format->save(); $this->adminUser = $this->drupalCreateUser([ 'administer filters', $basic_html_format->getPermissionName(), $restricted_html_format->getPermissionName(), $full_html_format->getPermissionName(), 'access site reports', ]); $this->webUser = $this->drupalCreateUser(['create page content', 'edit own page content']); user_role_grant_permissions('authenticated', [$basic_html_format->getPermissionName()]); user_role_grant_permissions('anonymous', [$restricted_html_format->getPermissionName()]); $this->drupalLogin($this->adminUser); $this->drupalPlaceBlock('local_actions_block'); } /** * Tests the format administration functionality. */ public function testFormatAdmin() { // Add text format. $this->drupalGet('admin/config/content/formats'); $this->clickLink('Add text format'); $format_id = Unicode::strtolower($this->randomMachineName()); $name = $this->randomMachineName(); $edit = [ 'format' => $format_id, 'name' => $name, ]; $this->drupalPostForm(NULL, $edit, t('Save configuration')); // Verify default weight of the text format. $this->drupalGet('admin/config/content/formats'); $this->assertFieldByName("formats[$format_id][weight]", 0, 'Text format weight was saved.'); // Change the weight of the text format. $edit = [ "formats[$format_id][weight]" => 5, ]; $this->drupalPostForm('admin/config/content/formats', $edit, t('Save')); $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was saved.'); // Edit text format. $this->drupalGet('admin/config/content/formats'); $destination = Url::fromRoute('filter.admin_overview')->toString(); $edit_href = Url::fromRoute('entity.filter_format.edit_form', ['filter_format' => $format_id], ['query' => ['destination' => $destination]])->toString(); $this->assertSession()->linkByHrefExists($edit_href); $this->drupalGet('admin/config/content/formats/manage/' . $format_id); $this->drupalPostForm(NULL, [], t('Save configuration')); // Verify that the custom weight of the text format has been retained. $this->drupalGet('admin/config/content/formats'); $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was retained.'); // Disable text format. $this->assertLinkByHref('admin/config/content/formats/manage/' . $format_id . '/disable'); $this->drupalGet('admin/config/content/formats/manage/' . $format_id . '/disable'); $this->drupalPostForm(NULL, [], t('Disable')); // Verify that disabled text format no longer exists. $this->drupalGet('admin/config/content/formats/manage/' . $format_id); $this->assertResponse(404, 'Disabled text format no longer exists.'); // Attempt to create a format of the same machine name as the disabled // format but with a different human readable name. $edit = [ 'format' => $format_id, 'name' => 'New format', ]; $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); $this->assertText('The machine-readable name is already in use. It must be unique.'); // Attempt to create a format of the same human readable name as the // disabled format but with a different machine name. $edit = [ 'format' => 'new_format', 'name' => $name, ]; $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', [ '%name' => $name, ])); } /** * Tests filter administration functionality. */ public function testFilterAdmin() { $first_filter = 'filter_autop'; $second_filter = 'filter_url'; $basic = 'basic_html'; $restricted = 'restricted_html'; $full = 'full_html'; $plain = 'plain_text'; // Check that the fallback format exists and cannot be disabled. $this->assertTrue($plain == filter_fallback_format(), 'The fallback format is set to plain text.'); $this->drupalGet('admin/config/content/formats'); $this->assertNoRaw('admin/config/content/formats/manage/' . $plain . '/disable', 'Disable link for the fallback format not found.'); $this->drupalGet('admin/config/content/formats/manage/' . $plain . '/disable'); $this->assertResponse(403, 'The fallback format cannot be disabled.'); // Verify access permissions to Full HTML format. $full_format = FilterFormat::load($full); $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.'); $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.'); // Add an additional tag and extra spaces and returns. $edit = []; $edit['filters[filter_html][settings][allowed_html]'] = "