function MediaLibraryTest::setUp

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

Overrides BrowserTestBase::setUp

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php, line 64

Class

MediaLibraryTest
@coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

protected function setUp() : void {
    parent::setUp();
    FilterFormat::create([
        'format' => 'test_format',
        'name' => 'Test format',
        'filters' => [
            'media_embed' => [
                'status' => TRUE,
            ],
        ],
    ])->save();
    Editor::create([
        'editor' => 'ckeditor5',
        'format' => 'test_format',
        'image_upload' => [
            'status' => FALSE,
        ],
        'settings' => [
            'toolbar' => [
                'items' => [
                    'drupalMedia',
                    'sourceEditing',
                    'undo',
                    'redo',
                ],
            ],
            'plugins' => [
                'ckeditor5_sourceEditing' => [
                    'allowed_tags' => [],
                ],
                'media_media' => [
                    'allow_view_mode_override' => FALSE,
                ],
            ],
        ],
    ])->save();
    $this->assertSame([], array_map(function (ConstraintViolationInterface $v) {
        return (string) $v->getMessage();
    }, iterator_to_array(CKEditor5::validatePair(Editor::load('test_format'), FilterFormat::load('test_format')))));
    $this->drupalCreateContentType([
        'type' => 'blog',
    ]);
    // Note that media_install() grants 'view media' to all users by default.
    $this->user = $this->drupalCreateUser([
        'use text format test_format',
        'access media overview',
        'create blog content',
    ]);
    // Create a media type that starts with the letter a, to test tab order.
    $this->createMediaType('image', [
        'id' => 'arrakis',
        'label' => 'Arrakis',
    ]);
    // Create a sample media entity to be embedded.
    $this->createMediaType('image', [
        'id' => 'image',
        'label' => 'Image',
    ]);
    File::create([
        'uri' => $this->getTestFiles('image')[0]->uri,
    ])
        ->save();
    $this->media = Media::create([
        'bundle' => 'image',
        'name' => 'Fear is the mind-killer',
        'field_media_image' => [
            [
                'target_id' => 1,
                'alt' => 'default alt',
                'title' => 'default title',
            ],
        ],
    ]);
    $this->media
        ->save();
    $arrakis_media = Media::create([
        'bundle' => 'arrakis',
        'name' => 'Le baron Vladimir Harkonnen',
        'field_media_image' => [
            [
                'target_id' => 1,
                'alt' => 'Il complote pour détruire le duc Leto',
                'title' => 'Il complote pour détruire le duc Leto',
            ],
        ],
    ]);
    $arrakis_media->save();
    $this->drupalLogin($this->user);
}

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