public function MediaBrowserTest::testFileBasedMediaCreation in Lightning Media 8.3
Tests creating file-based media in the media browser.
File
- tests/
src/ Functional/ MediaBrowserTest.php, line 170
Class
- MediaBrowserTest
- Tests the functionality of the media browser.
Namespace
Drupal\Tests\lightning_media\FunctionalCode
public function testFileBasedMediaCreation() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$account = $this
->drupalCreateUser([
'access media_browser entity browser pages',
'access media overview',
'create media',
]);
$this
->drupalLogin($account);
// This could be done with the data provider pattern, but it's not really
// needed, and this is significantly faster.
$files = [
'test.jpg' => TRUE,
'test.mp4' => FALSE,
'test.mp3' => FALSE,
'test.pdf' => FALSE,
];
foreach ($files as $file => $is_image) {
$this
->drupalGet('/entity-browser/modal/media_browser');
$title = $this
->randomString();
$page
->attachFileToField('File', __DIR__ . '/../../files/' . $file);
$assert_session
->elementExists('css', '.js-form-managed-file')
->pressButton('Upload');
if ($is_image) {
$summary = $assert_session
->elementExists('css', 'details > summary:contains(Crop image)');
$this
->assertTrue($summary
->getParent()
->hasAttribute('open'));
$assert_session
->elementExists('css', 'details > summary:contains(Freeform)');
}
$page
->fillField('Name', $title);
$page
->pressButton('Place');
$this
->drupalGet('/admin/content/media');
$page
->clickLink('Table');
$assert_session
->linkExists($title);
}
}