View source
<?php
namespace Drupal\Tests\lightning_media\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class MediaImageFieldTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'lightning_media_image',
'lightning_media_video',
];
protected function setUp() {
parent::setUp();
$settings = $this
->config('media.settings');
if ($settings
->get('standalone_url') === FALSE) {
$settings
->set('standalone_url', TRUE)
->save();
drupal_flush_all_caches();
}
}
public function test() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$field_name = 'field_test' . mb_strtolower($this
->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'media',
'type' => 'image',
]);
$field_storage
->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'remote_video',
'label' => 'Image',
])
->save();
$this
->drupalPlaceBlock('local_tasks_block');
$form_display = $this->container
->get('entity_display.repository')
->getFormDisplay('media', 'remote_video');
$form_display
->setComponent($field_name, [
'type' => 'image_image',
])
->save();
$form_display
->setComponent($field_name, [
'type' => 'image_image',
'weight' => 4,
'settings' => [
'preview_image_style' => 'thumbnail',
'progress_indicator' => 'throbber',
],
'region' => 'content',
])
->save();
$account = $this
->createUser([
'create media',
'update media',
]);
$this
->drupalLogin($account);
$name = $this
->randomString();
$this
->drupalGet('/media/add/remote_video');
$page
->fillField('Name', $name);
$page
->fillField('Video URL', 'https://www.youtube.com/watch?v=z9qY4VUZzcY');
$this
->assertNotEmpty($assert_session
->waitForField('Image'));
$path = realpath(__DIR__ . '/../../files/test.jpg');
$this
->assertNotEmpty($path);
$page
->attachFileToField('Image', $path);
$this
->assertNotEmpty($assert_session
->waitForField('Alternative text'));
$page
->fillField('Alternative text', 'This is a beauty.');
$page
->pressButton('Save');
$page
->clickLink('Edit');
$page
->pressButton("{$field_name}_0_remove_button");
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->buttonNotExists("{$field_name}_0_remove_button");
}
}