public function MediaBrowserTest::testNewMediaReferenceField in Lightning Media 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/MediaBrowserTest.php \Drupal\Tests\lightning_media\Functional\MediaBrowserTest::testNewMediaReferenceField()
- 8.3 tests/src/Functional/MediaBrowserTest.php \Drupal\Tests\lightning_media\Functional\MediaBrowserTest::testNewMediaReferenceField()
Tests that the media browser is the default widget for a new media reference field.
File
- tests/
src/ Functional/ MediaBrowserTest.php, line 54
Class
- MediaBrowserTest
- @group lightning @group lightning_media
Namespace
Drupal\Tests\lightning_media\FunctionalCode
public function testNewMediaReferenceField() {
$account = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($account);
$this
->drupalGet("/admin/structure/types/manage/{$this->nodeType}/fields");
$this
->clickLink('Add field');
$values = [
'new_storage_type' => 'field_ui:entity_reference:media',
'label' => 'Foobar',
'field_name' => 'foobar',
];
$this
->drupalPostForm(NULL, $values, 'Save and continue');
$this
->drupalPostForm(NULL, [], 'Save field settings');
$values = [
"settings[handler_settings][target_bundles][{$this->mediaType}]" => $this->mediaType,
];
$this
->drupalPostForm(NULL, $values, 'Save settings');
$component = entity_get_form_display('node', $this->nodeType, 'default')
->getComponent('field_foobar');
$this
->assertInternalType('array', $component);
$this
->assertSame('entity_browser_entity_reference', $component['type']);
$this
->assertSame('media_browser', $component['settings']['entity_browser']);
}