public function MediaBrowserWidgetDisambiguationTest::testUpload in Lightning Media 8.3
Tests that select is shown when media bundle is ambiguous.
File
- tests/
src/ FunctionalJavascript/ MediaBrowserWidgetDisambiguationTest.php, line 113
Class
- MediaBrowserWidgetDisambiguationTest
- Tests media type disambiguation in the media browser.
Namespace
Drupal\Tests\lightning_media\FunctionalJavascriptCode
public function testUpload() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
// This is necessary, it seems, in order for automatic file uploads to work
// correctly.
$assert_session
->assertWaitOnAjaxRequest();
// This helps stabilize the next couple of calls; without it, the
// upload is more likely to randomly fail. It's not clear why this
// is the case, but repeated testing on Travis CI seems to support
// it.
$assert_session
->assertWaitOnAjaxRequest();
$path = realpath(__DIR__ . '/../../files/test.jpg');
$this
->assertNotEmpty($path);
$assert_session
->waitForField('input_file')
->attachFile($path);
$assert_session
->waitForField('Bundle')
->selectOption('Picture');
$assert_session
->waitForField('Name')
->setValue('Bar');
$page
->fillField('Alternative text', 'Baz');
$page
->pressButton('Place');
$this
->waitForEntityBrowserToClose();
$assert_session
->waitForButton('Remove');
$page
->pressButton('Save');
// Assert the correct entities are created.
$node = Node::load(1);
$this
->assertInstanceOf(Node::class, $node);
/** @var \Drupal\node\NodeInterface $node */
$this
->assertSame('Foo', $node
->getTitle());
$this
->assertFalse($node
->get('field_media')
->isEmpty());
$this
->assertSame('picture', $node->field_media->entity
->bundle());
$this
->assertSame('Bar', $node->field_media->entity
->getName());
$this
->assertSame('Baz', $node->field_media->entity->field_media_image->alt);
$this
->assertSame('test.jpg', $node->field_media->entity->field_media_image->entity
->getFilename());
}