public function CKEditorIntegrationTest::testEmbedPreviewAccess in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::testEmbedPreviewAccess()
Tests preview route access.
@dataProvider previewAccessProvider
Parameters
bool $media_embed_enabled: Whether to test with media_embed filter enabled on the text format.
bool $can_use_format: Whether the logged in user is allowed to use the text format.
File
- core/
modules/ media/ tests/ src/ FunctionalJavascript/ CKEditorIntegrationTest.php, line 1039
Class
- CKEditorIntegrationTest
- @coversDefaultClass \Drupal\media\Plugin\CKEditorPlugin\DrupalMedia @group media
Namespace
Drupal\Tests\media\FunctionalJavascriptCode
public function testEmbedPreviewAccess($media_embed_enabled, $can_use_format) {
$format = FilterFormat::create([
'format' => $this
->randomMachineName(),
'name' => $this
->randomString(),
'filters' => [
'filter_align' => [
'status' => TRUE,
],
'filter_caption' => [
'status' => TRUE,
],
'media_embed' => [
'status' => $media_embed_enabled,
],
],
]);
$format
->save();
$permissions = [
'bypass node access',
];
if ($can_use_format) {
$permissions[] = $format
->getPermissionName();
}
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$text = '<drupal-media data-caption="baz" data-entity-type="media" data-entity-uuid="' . $this->media
->uuid() . '"></drupal-media>';
$route_parameters = [
'filter_format' => $format
->id(),
];
$options = [
'query' => [
'text' => $text,
'uuid' => $this->media
->uuid(),
],
];
$this
->drupalGet(Url::fromRoute('media.filter.preview', $route_parameters, $options));
$assert_session = $this
->assertSession();
if ($media_embed_enabled && $can_use_format) {
$assert_session
->elementExists('css', 'img');
$assert_session
->responseContains('baz');
}
else {
$assert_session
->responseContains('You are not authorized to access this page.');
}
}