public function CKEditorIntegrationTest::testConfigurationValidation in Drupal 8
Same name and namespace in other branches
- 9 core/modules/media_library/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest::testConfigurationValidation()
Tests validation that DrupalMediaLibrary requires media_embed filter.
File
- core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ CKEditorIntegrationTest.php, line 147
Class
- CKEditorIntegrationTest
- @coversDefaultClass \Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary @group media_library
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
public function testConfigurationValidation() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$admin_user = $this
->drupalCreateUser([
'access administration pages',
'administer site configuration',
'administer filters',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('/admin/config/content/formats/manage/test_format');
$page
->uncheckField('filters[media_embed][status]');
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The Embed media filter must be enabled to use the Insert from Media Library button.');
$page
->checkField('filters[media_embed][status]');
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The text format Test format has been updated.');
// Now test adding a new format.
$this
->drupalGet('/admin/config/content/formats/add');
$page
->fillField('name', 'Sulaco');
// Wait for machine name to be filled in.
$this
->assertNotEmpty($assert_session
->waitForText('sulaco'));
$page
->checkField('roles[authenticated]');
$page
->selectFieldOption('editor[editor]', 'ckeditor');
$targetSelector = 'ul.ckeditor-toolbar-group-buttons';
$buttonSelector = 'li[data-drupal-ckeditor-button-name="DrupalMediaLibrary"]';
$this
->assertNotEmpty($target = $assert_session
->waitForElementVisible('css', $targetSelector));
$this
->assertNotEmpty($button = $assert_session
->elementExists('css', $buttonSelector));
$this
->sortableTo($buttonSelector, 'ul.ckeditor-available-buttons', $targetSelector);
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The Embed media filter must be enabled to use the Insert from Media Library button.');
$page
->checkField('filters[media_embed][status]');
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('Added text format Sulaco.');
// Test that when adding the DrupalMediaLibrary button to the editor the
// correct attributes are added to the <drupal-media> tag in the Allowed
// HTML tags.
$this
->drupalGet('/admin/config/content/formats/manage/sulaco');
$page
->checkField('filters[filter_html][status]');
$expected = 'drupal-media data-entity-type data-entity-uuid data-view-mode data-align data-caption alt title';
$allowed_html = $assert_session
->fieldExists('filters[filter_html][settings][allowed_html]')
->getValue();
$this
->assertStringContainsString($expected, $allowed_html);
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The text format Sulaco has been updated.');
// Test that the config form allows removing non-required attributes from
// the <drupal-media> tag.
$this
->drupalGet('/admin/config/content/formats/manage/sulaco');
$allowed_html_field = $assert_session
->fieldExists('filters[filter_html][settings][allowed_html]');
$allowed_html = $allowed_html_field
->getValue();
$search = 'drupal-media data-entity-type data-entity-uuid data-view-mode data-align data-caption alt title';
$replace = 'drupal-media data-entity-type data-entity-uuid';
$allowed_html = str_replace($search, $replace, $allowed_html);
$page
->clickLink('Limit allowed HTML tags and correct faulty HTML');
$this
->assertTrue($allowed_html_field
->waitFor(10, function ($allowed_html_field) {
return $allowed_html_field
->isVisible();
}));
$allowed_html_field
->setValue($allowed_html);
$page
->pressButton('Save configuration');
$assert_session
->pageTextContains('The text format Sulaco has been updated.');
}