diff --git a/composer.json b/composer.json index 5b9c520d..b4575c17 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ }, "autoload-dev": { "psr-4": { - "Drupal\\Tests\\oe_webtools\\": "./tests/" + "Drupal\\Tests\\oe_webtools\\": "./tests/src/" } }, "extra": { diff --git a/modules/oe_webtools_media/tests/src/Kernel/WebtoolsSnippetFormatterTest.php b/tests/src/Kernel/WebtoolsSnippetFormatterTest.php similarity index 83% rename from modules/oe_webtools_media/tests/src/Kernel/WebtoolsSnippetFormatterTest.php rename to tests/src/Kernel/WebtoolsSnippetFormatterTest.php index e712c2a7..3f676033 100644 --- a/modules/oe_webtools_media/tests/src/Kernel/WebtoolsSnippetFormatterTest.php +++ b/tests/src/Kernel/WebtoolsSnippetFormatterTest.php @@ -2,11 +2,10 @@ declare(strict_types = 1); -namespace Drupal\Tests\oe_webtools_media\Kernel; +namespace Drupal\Tests\oe_webtools\Kernel; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Xss; -use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -16,18 +15,15 @@ /** * Test the webtools snippet formatter. * - * @coversDefaultClass \Drupal\oe_webtools_media\Plugin\Field\FieldFormatter\WebtoolsSnippetFormatter - * - * @group oe_webtools_media + * @coversDefaultClass \Drupal\oe_webtools\Plugin\Field\FieldFormatter\WebtoolsSnippetFormatter */ class WebtoolsSnippetFormatterTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'oe_webtools', - 'oe_webtools_media', 'json_field', 'field', 'user', @@ -56,6 +52,13 @@ class WebtoolsSnippetFormatterTest extends KernelTestBase { */ protected $display; + /** + * The field name. + * + * @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface + */ + protected $fieldName = 'test_field_media_webtools'; + /** * {@inheritdoc} */ @@ -71,7 +74,7 @@ protected function setUp(): void { $this->bundle = $this->entityType; $field_storage = FieldStorageConfig::create([ - 'field_name' => 'test_field_media_webtools', + 'field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'json', ]); @@ -83,25 +86,23 @@ protected function setUp(): void { ]); $field->save(); - // The display mode. - $this->display = EntityViewDisplay::create([ - 'targetEntityType' => $this->entityType, - 'bundle' => $this->bundle, - 'mode' => 'default', - ]); - $this->display->setComponent('test_field_media_webtools', [ + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + + // Create a display for the default view mode. + $this->display = $display_repository->getViewDisplay($this->entityType, $this->bundle); + $this->display->setComponent($this->fieldName, [ 'type' => 'webtools_snippet', - ]); - $this->display->save(); + ])->save(); } /** - * Tests that the formatter contains the necessary library. + * Assert presence of 'Smart loader' with formatter. */ public function testFormatterLibrary(): void { $data = '{"service":"map","map":{"background":["osmec"]},"version":"2.0"}'; $entity = EntityTest::create([ - 'test_field_media_webtools' => $data, + $this->fieldName => $data, ]); $entity->save(); @@ -122,7 +123,7 @@ public function testFormatterLibrary(): void { */ public function testFormatter(string $data): void { $entity = EntityTest::create([ - 'test_field_media_webtools' => $data, + $this->fieldName => $data, ]); $entity->save();