Skip to content

Commit

Permalink
EWPP-428: Update and move test for snippet formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle committed Jan 7, 2021
1 parent 296d109 commit 4dba66d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"autoload-dev": {
"psr-4": {
"Drupal\\Tests\\oe_webtools\\": "./tests/"
"Drupal\\Tests\\oe_webtools\\": "./tests/src/"
}
},
"extra": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -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}
*/
Expand All @@ -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',
]);
Expand All @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit 4dba66d

Please sign in to comment.