FormatterDependenciesTest.php in Video Embed Field 8
File
tests/src/Kernel/FormatterDependenciesTest.php
View source
<?php
namespace Drupal\Tests\video_embed_field\Kernel;
use Drupal\image\Entity\ImageStyle;
class FormatterDependenciesTest extends KernelTestBase {
protected $style;
protected $replacementStyle;
protected $entityTypeManager;
protected function setUp() {
parent::setUp();
$this->style = ImageStyle::create([
'name' => 'style_foo',
'label' => $this
->randomString(),
]);
$this->style
->save();
$this->replacementStyle = ImageStyle::create([
'name' => 'style_bar',
'label' => $this
->randomString(),
]);
$this->replacementStyle
->save();
$this->entityTypeManager = \Drupal::entityTypeManager();
}
public function testThumbnailConfigDependencies() {
$this
->assertFormatterDependencyBehavior([
'type' => 'video_embed_field_thumbnail',
'settings' => [
'image_style' => $this->style
->id(),
],
]);
}
public function testColorboxConfigDependencies() {
$this
->assertFormatterDependencyBehavior([
'type' => 'video_embed_field_colorbox',
'settings' => [
'image_style' => $this->style
->id(),
],
]);
}
protected function assertFormatterDependencyBehavior($formatter_settings) {
$this
->loadEntityDisplay()
->setComponent($this->fieldName, $formatter_settings)
->save();
$this
->assertTrue(in_array('image.style.' . $this->style
->id(), $this
->loadEntityDisplay()
->getDependencies()['config']), 'The image style was correctly added as a dependency the entity display config object.');
$storage = $this->entityTypeManager
->getStorage('image_style');
$storage
->setReplacementId($this->style
->id(), $this->replacementStyle
->id());
$this->style
->delete();
$this
->assertTrue(in_array('image.style.' . $this->replacementStyle
->id(), $this
->loadEntityDisplay()
->getDependencies()['config']), 'The replacement style was added to the entity display.');
}
protected function loadEntityDisplay() {
return $this->entityTypeManager
->getStorage('entity_view_display')
->load('entity_test.entity_test.default');
}
}