EntityFormDisplayPresaveTest.php in Lightning Media 8.3
File
tests/src/Kernel/EntityFormDisplayPresaveTest.php
View source
<?php
namespace Drupal\Tests\lightning_media\Kernel;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
class EntityFormDisplayPresaveTest extends KernelTestBase {
protected static $modules = [
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this->container
->get('module_installer')
->install([
'lightning_media_image',
'lightning_page',
]);
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_media',
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'media',
],
]);
$field_storage
->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => 'Media',
'settings' => [
'handler_settings' => [
'target_bundles' => [
'image' => 'image',
],
],
],
])
->save();
}
public function testNoOverride() {
$this
->config('lightning_media.settings')
->set('entity_browser.override_widget', FALSE)
->save();
$display = EntityFormDisplay::load('node.page.default');
$display
->setComponent('field_media', [
'type' => 'options_select',
]);
$display
->save();
$display = EntityFormDisplay::load('node.page.default');
$component = $display
->getComponent('field_media');
$this
->assertSame('array', gettype($component));
$this
->assertSame('options_select', $component['type']);
}
public function testOverride() {
$display = EntityFormDisplay::load('node.page.default');
$display
->setComponent('field_media', [
'type' => 'options_select',
]);
$display
->save();
$display = EntityFormDisplay::load('node.page.default');
$component = $display
->getComponent('field_media');
$this
->assertSame('array', gettype($component));
$this
->assertSame('entity_browser_entity_reference', $component['type']);
}
}