function EditorMediaDialogTest::testBuildForm

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Kernel/EditorMediaDialogTest.php \Drupal\Tests\media\Kernel\EditorMediaDialogTest::testBuildForm()
  2. 10 core/modules/media/tests/src/Kernel/EditorMediaDialogTest.php \Drupal\Tests\media\Kernel\EditorMediaDialogTest::testBuildForm()

Tests that the form builds successfully.

@covers ::buildForm

File

core/modules/media/tests/src/Kernel/EditorMediaDialogTest.php, line 52

Class

EditorMediaDialogTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21media%21src%21Form%21EditorMediaDialog.php/class/EditorMediaDialog/8.9.x" title="Provides a media embed dialog for text editors." class="local">\Drupal\media\Form\EditorMediaDialog</a> @group media

Namespace

Drupal\Tests\media\Kernel

Code

public function testBuildForm() {
    $format = FilterFormat::create([
        'filters' => [
            'media_embed' => [
                'status' => TRUE,
            ],
        ],
    ]);
    $editor = $this->prophesize(EditorInterface::class);
    $editor->getFilterFormat()
        ->willReturn($format);
    // Create a sample media entity to be embedded.
    $media = Media::create([
        'bundle' => $this->createMediaType('test')
            ->id(),
        'name' => 'Screaming hairy armadillo',
        'field_media_test' => $this->randomString(),
    ]);
    $media->save();
    $form_state = new FormState();
    $form_state->setUserInput([
        'editor_object' => [
            'attributes' => [
                'data-entity-type' => 'media',
                'data-entity-uuid' => $media->uuid(),
                'data-align' => 'center',
            ],
            'hasCaption' => 'false',
            'label' => $media->label(),
            'link' => '',
            'hostEntityLangcode' => $media->language()
                ->getId(),
            'classes' => '',
        ],
    ]);
    $form_state->setRequestMethod('POST');
    $form = EditorMediaDialog::create($this->container)
        ->buildForm([], $form_state, $editor->reveal());
    $this->assertNotNull($form, 'Form should have been built without errors.');
}

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