public function MediaIefIntegrationTest::testMediaIefIntegration in Media entity 8
Tests inline_entity_form integration with media entities.
File
- tests/
src/ FunctionalJavascript/ MediaIefIntegrationTest.php, line 86
Class
- MediaIefIntegrationTest
- Tests the integration between Inline Entity Form and Media Entity.
Namespace
Drupal\Tests\media_entity\FunctionalJavascriptCode
public function testMediaIefIntegration() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
// Open up a node form and check the IEF widget.
$this
->drupalGet('/node/add/media_entity_ct');
$assert_session
->buttonExists('edit-ref-media-entities-actions-ief-add');
$page
->pressButton('edit-ref-media-entities-actions-ief-add');
$assert_session
->assertWaitOnAjaxRequest();
// Check the presence of the entity's label field.
$page
->findField('ref_media_entities[form][inline_entity_form][name][0][value]')
->isVisible();
// Submit the form to create a media entity and verify that it is correctly
// created.
$media_name = $this
->randomMachineName();
$page
->fillField('ref_media_entities[form][inline_entity_form][name][0][value]', $media_name);
$page
->fillField('ref_media_entities[form][inline_entity_form][uid][0][target_id]', $this->adminUser
->getDisplayName() . ' (' . $this->adminUser
->id() . ')');
$page
->pressButton('Create media');
$assert_session
->assertWaitOnAjaxRequest();
// We need to save the node in order for IEF to do its thing.
$page
->fillField('title[0][value]', $this
->randomString());
$page
->pressButton('Save');
$media_id = $this->container
->get('entity.query')
->get('media')
->execute();
$media_id = reset($media_id);
/** @var \Drupal\media_entity\MediaInterface $media */
$media = Media::load($media_id);
$this
->assertEquals($media_name, $media
->label(), 'A media inside IEF was correctly created.');
}