function MediaTest::testEmbedPreviewAccess

Same name in this branch
  1. 9 core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\MediaTest::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/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php, line 1117

Class

MediaTest
@coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Media @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testEmbedPreviewAccess($media_embed_enabled, $can_use_format) {
    // Reconfigure the host entity's text format to suit our needs.
    
    /** @var \Drupal\filter\FilterFormatInterface $format */
    $format = FilterFormat::load($this->host->body->format);
    $format->set('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));
    $this->drupalGet($this->host
        ->toUrl('edit-form'));
    $assert_session = $this->assertSession();
    if ($can_use_format) {
        $this->waitForEditor();
        if ($media_embed_enabled) {
            // The preview rendering, which in this test will use Starterkit theme's
            // media.html.twig template, will fail without the CSRF token/header.
            // @see ::testEmbeddedMediaPreviewWithCsrfToken()
            $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'article.media'));
        }
        else {
            // If the filter isn't enabled, there won't be an error, but the
            // preview shouldn't be rendered.
            $assert_session->assertWaitOnAjaxRequest();
            $assert_session->elementNotExists('css', 'article.media');
        }
    }
    else {
        $assert_session->pageTextContains('This field has been disabled because you do not have sufficient permissions to edit it.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.