diff --git a/src/Normalizer/EntityReferenceRevisionItemNormalizer.php b/src/Normalizer/EntityReferenceRevisionItemNormalizer.php index a00824d..5bf2473 100644 --- a/src/Normalizer/EntityReferenceRevisionItemNormalizer.php +++ b/src/Normalizer/EntityReferenceRevisionItemNormalizer.php @@ -2,7 +2,6 @@ namespace Drupal\entity_reference_revisions\Normalizer; -use Drupal\Core\Entity\Entity; use Drupal\entity_reference_revisions\EntityNeedsSaveInterface; use Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem; use Drupal\hal\Normalizer\EntityReferenceItemNormalizer; diff --git a/tests/src/Kernel/EntityReferenceRevisionsNormalizerTest.php b/tests/src/Kernel/EntityReferenceRevisionsNormalizerTest.php index 05bf521..bf9bcf9 100644 --- a/tests/src/Kernel/EntityReferenceRevisionsNormalizerTest.php +++ b/tests/src/Kernel/EntityReferenceRevisionsNormalizerTest.php @@ -9,8 +9,6 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; -use Drupal\paragraphs\Entity\Paragraph; -use Drupal\paragraphs\Entity\ParagraphsType; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; @@ -18,7 +16,6 @@ use Drupal\simpletest\NodeCreationTrait; * Tests the entity_reference_revisions normalizer. * * @group entity_reference_revisions - * @requires module paragraphs */ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { @@ -42,21 +39,6 @@ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { ); /** - * The current database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $database; - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - * - */ - protected $entityTypeManager; - - /** * SerializerInterface which is used for serialization. * * @var \Symfony\Component\Serializer\Normalizer\NormalizerInterface $serializer @@ -129,10 +111,6 @@ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { // Inject serializer. $this->serializer = $this->container->get('serializer'); - - // Inject database connection and entity type manager for the tests. - $this->database = \Drupal::database(); - $this->entityTypeManager = \Drupal::entityTypeManager(); } /** @@ -140,17 +118,17 @@ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { */ public function testEmbedEntityReference() { // Create the test composite entity. - $composite = EntityTestCompositeRelationship::create([ - 'name' => $composite_name = $this->randomMachineName(), - ]); - $composite->save(); - $nested_composite = EntityTestCompositeRelationship::create([ - 'name' => $nested_composite_name = $this->randomMachineName(), - 'composite_nested_reference' => $composite + 'name' => $nested_composite_name = $this->randomMachineName(), ]); $nested_composite->save(); + $composite = EntityTestCompositeRelationship::create([ + 'name' => $composite_name = $this->randomMachineName(), + 'composite_nested_reference' => $nested_composite + ]); + $composite->save(); + // Add 2 nodes for referencing. $node_reference = Node::create([ 'type' => 'article', @@ -168,7 +146,7 @@ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { 'type' => 'article', 'title' => 'Normalizing paragraph test', 'node_reference' => [$node_reference, $node_reference2], - 'composite_reference' => $nested_composite, + 'composite_reference' => $composite, ]); $node->save(); @@ -180,21 +158,25 @@ class EntityReferenceRevisionsNormalizerTest extends EntityKernelTestBase { $this->assertEquals($revision_id, $normalized['_embedded']['http://localhost/rest/relation/node/article/composite_reference'][0]['id'][0]['value']); // Check the id of the nested composite reference in the entity test composite. - $nested_revision_id = $nested_composite->get('composite_nested_reference')->target_revision_id; + $nested_revision_id = $composite->get('composite_nested_reference')->target_revision_id; $this->assertEquals($nested_revision_id, $normalized['_embedded']['http://localhost/rest/relation/node/article/composite_reference'][0]['_embedded']['http://localhost/rest/relation/entity_test_composite/entity_test_composite/composite_nested_reference'][0]['id'][0]['value']); // Check the denormalization of the embedded composite field. $nested_composite->delete(); + $composite->delete(); $node->delete(); $node = $this->serializer->denormalize($normalized, Node::class, 'hal_json'); + $node->save(); + + $node = Node::load($node->id()); // Check the id of the composite reference in the node. $this->assertEquals($revision_id, $node->get('composite_reference')->target_revision_id); - $this->assertEquals($nested_composite_name, $node->get('composite_reference')->entity->label()); + $this->assertEquals($composite_name, $node->get('composite_reference')->entity->label()); // Check the id of the nested composite reference in the entity test composite. $this->assertEquals($nested_revision_id, $node->get('composite_reference')->entity->get('composite_nested_reference')->target_revision_id); - $this->assertEquals($composite_name, $node->get('composite_reference')->entity->get('composite_nested_reference')->entity->label()); + $this->assertEquals($nested_composite_name, $node->get('composite_reference')->entity->get('composite_nested_reference')->entity->label()); } }