You are here

public function MediaBrowserUploadWidgetTest::testFieldAllowedTypesSettingIsRespected in Lightning Media 8.3

Overrides MediaBrowserWidgetTestBase::testFieldAllowedTypesSettingIsRespected

File

tests/src/Functional/MediaBrowserUploadWidgetTest.php, line 63

Class

MediaBrowserUploadWidgetTest
@group lightning_media

Namespace

Drupal\Tests\lightning_media\Functional

Code

public function testFieldAllowedTypesSettingIsRespected() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $field = FieldConfig::loadByName('node', 'page', 'field_media');
  $handler_settings = $field
    ->getSetting('handler_settings');
  $handler_settings['target_bundles'] = [
    'image' => 'image',
  ];
  $field
    ->setSetting('handler_settings', $handler_settings)
    ->save();
  $this
    ->visitMediaBrowserFromNodeForm();
  $this
    ->uploadFile(__DIR__ . '/../../files/test.jpg');

  // The field only allows Image media items, so there should be no need to
  // disambiguate.
  $assert_session
    ->fieldNotExists('Bundle');
  $page
    ->fillField('Name', $this
    ->randomString());
  $page
    ->fillField('Alternative text', $this
    ->randomString());
  $page
    ->pressButton('Place');
  $assert_session
    ->statusCodeEquals(200);
  $this
    ->assertMediaCount(1, [
    'bundle' => 'image',
  ]);
}