You are here

protected function CKEditorIntegrationTest::setUp in Drupal 9

Same name in this branch
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest::setUp()
  2. 9 core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest::setUp()
  3. 9 core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php, line 87

Class

CKEditorIntegrationTest
@coversDefaultClass \Drupal\media\Plugin\CKEditorPlugin\DrupalMedia @group media

Namespace

Drupal\Tests\media\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  FilterFormat::create([
    'format' => 'test_format',
    'name' => 'Test format',
    'filters' => [
      'filter_align' => [
        'status' => TRUE,
      ],
      'filter_caption' => [
        'status' => TRUE,
      ],
      'media_embed' => [
        'status' => TRUE,
      ],
    ],
  ])
    ->save();
  Editor::create([
    'editor' => 'ckeditor',
    'format' => 'test_format',
    'settings' => [
      'toolbar' => [
        'rows' => [
          [
            [
              'name' => 'All the things',
              'items' => [
                'Source',
                'Bold',
                'Italic',
                'DrupalLink',
                'DrupalUnlink',
                'DrupalImage',
              ],
            ],
          ],
        ],
      ],
    ],
  ])
    ->save();

  // Note that media_install() grants 'view media' to all users by default.
  $this->adminUser = $this
    ->drupalCreateUser([
    'use text format test_format',
    'bypass node access',
  ]);

  // Create a sample media entity to be embedded.
  $this
    ->createMediaType('image', [
    'id' => 'image',
  ]);
  File::create([
    'uri' => $this
      ->getTestFiles('image')[0]->uri,
  ])
    ->save();
  $this->media = Media::create([
    'bundle' => 'image',
    'name' => 'Screaming hairy armadillo',
    'field_media_image' => [
      [
        'target_id' => 1,
        'alt' => 'default alt',
        'title' => 'default title',
      ],
    ],
  ]);
  $this->media
    ->save();

  // Create a sample host entity to embed media in.
  $this
    ->drupalCreateContentType([
    'type' => 'blog',
  ]);
  $this->host = $this
    ->createNode([
    'type' => 'blog',
    'title' => 'Animals with strange names',
    'body' => [
      'value' => '<drupal-media data-caption="baz" data-entity-type="media" data-entity-uuid="' . $this->media
        ->uuid() . '"></drupal-media>',
      'format' => 'test_format',
    ],
  ]);
  $this->host
    ->save();
  $this
    ->drupalLogin($this->adminUser);
}