function MediaLibraryAddFormTest::testSelectedTypeValidation

Same name and namespace in other branches
  1. 8.9.x core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryAddFormTest::testSelectedTypeValidation()
  2. 10 core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryAddFormTest::testSelectedTypeValidation()
  3. 11.x core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryAddFormTest::testSelectedTypeValidation()

Tests the validation of the selected type in the media library add form.

File

core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php, line 132

Class

MediaLibraryAddFormTest
Tests the media library add form.

Namespace

Drupal\Tests\media_library\Kernel

Code

public function testSelectedTypeValidation() {
    $state = MediaLibraryState::create('test', [
        'image',
        'remote_video',
        'header_image',
    ], 'header_image', -1);
    $form_state = new FormState();
    $form_state->set('media_library_state', $state);
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage("The 'header_image' media type does not exist.");
    \Drupal::formBuilder()->buildForm(FileUploadForm::class, $form_state);
}

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