function MediaEntityMetadataApiTest::setUp

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::setUp()
  2. 10 core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php \Drupal\Tests\ckeditor5\Functional\MediaEntityMetadataApiTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php, line 89

Class

MediaEntityMetadataApiTest
Tests the media entity metadata API.

Namespace

Drupal\Tests\ckeditor5\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $this->uuidService = $this->container
        ->get('uuid');
    EntityViewMode::create([
        'id' => 'media.view_mode_1',
        'targetEntityType' => 'media',
        'status' => TRUE,
        'enabled' => TRUE,
        'label' => 'View Mode 1',
    ])->save();
    EntityViewMode::create([
        'id' => 'media.view_mode_2',
        'targetEntityType' => 'media',
        'status' => TRUE,
        'enabled' => TRUE,
        'label' => 'View Mode 2',
    ])->save();
    $filtered_html_format = FilterFormat::create([
        'format' => 'filtered_html',
        'name' => 'Filtered HTML',
        'weight' => 0,
        'filters' => [
            'filter_html' => [
                'id' => 'filter_html',
                'status' => TRUE,
                'weight' => -10,
                'settings' => [
                    'allowed_html' => "<p> <br> <drupal-media data-entity-type data-entity-uuid data-view-mode alt>",
                    'filter_html_help' => TRUE,
                    'filter_html_nofollow' => TRUE,
                ],
            ],
            'media_embed' => [
                'id' => 'media_embed',
                'status' => TRUE,
                'settings' => [
                    'default_view_mode' => 'view_mode_1',
                    'allowed_view_modes' => [
                        'view_mode_1' => 'view_mode_1',
                        'view_mode_2' => 'view_mode_2',
                    ],
                    'allowed_media_types' => [],
                ],
            ],
        ],
        'roles' => [
            RoleInterface::AUTHENTICATED_ID,
        ],
    ]);
    $filtered_html_format->save();
    $this->editor = Editor::create([
        'format' => 'filtered_html',
        'editor' => 'ckeditor5',
        'image_upload' => [
            'status' => FALSE,
        ],
        'settings' => [
            'toolbar' => [
                'items' => [],
            ],
            'plugins' => [
                'media_media' => [
                    'allow_view_mode_override' => TRUE,
                ],
            ],
        ],
    ]);
    $this->editor
        ->save();
    $filtered_html_format->setFilterConfig('media_embed', [
        'status' => TRUE,
        'settings' => [
            'default_view_mode' => 'view_mode_1',
            'allowed_media_types' => [],
            'allowed_view_modes' => [
                'view_mode_1' => 'view_mode_1',
                'view_mode_2' => 'view_mode_2',
            ],
        ],
    ])
        ->save();
    $this->assertSame([], array_map(function (ConstraintViolationInterface $v) {
        return (string) $v->getMessage();
    }, iterator_to_array(CKEditor5::validatePair($this->editor, $filtered_html_format))));
    // Create a sample media entity to be embedded.
    $this->createMediaType('image', [
        'id' => 'image',
    ]);
    File::create([
        'uri' => $this->getTestFiles('image')[0]->uri,
    ])
        ->save();
    $this->mediaImage = Media::create([
        'bundle' => 'image',
        'name' => 'Screaming hairy armadillo',
        'field_media_image' => [
            [
                'target_id' => 1,
                'alt' => 'default alt',
                'title' => 'default title',
            ],
        ],
    ]);
    $this->mediaImage
        ->save();
    $this->createMediaType('file', [
        'id' => 'file',
    ]);
    File::create([
        'uri' => $this->getTestFiles('text')[0]->uri,
    ])
        ->save();
    $this->mediaFile = Media::create([
        'bundle' => 'file',
        'name' => 'Information about screaming hairy armadillo',
        'field_media_file' => [
            [
                'target_id' => 2,
            ],
        ],
    ]);
    $this->mediaFile
        ->save();
    $this->adminUser = $this->drupalCreateUser([
        'use text format filtered_html',
    ]);
    $this->drupalLogin($this->adminUser);
}

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