You are here

public function ImportEntityManagerTest::testEntityPresaveCompareExcludeEntityFromComparison in Acquia Content Hub 8

Tests the entityPresave() method.

Exclude configuration entity from comparison.

@covers ::entityPresave

File

tests/src/Unit/ImportEntityManagerTest.php, line 789

Class

ImportEntityManagerTest
PHPUnit test for the ImportEntityManager class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testEntityPresaveCompareExcludeEntityFromComparison() {
  $node = $this
    ->createMock('\\Drupal\\node\\NodeInterface');
  $original_node = $this
    ->createMock('\\Drupal\\node\\NodeInterface');
  $node->original = $original_node;
  $node
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn(12);
  $node
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->willReturn('node');
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('loadImportedByDrupalEntity')
    ->with('node', 12)
    ->willReturn($this->contentHubEntitiesTracking);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('isPendingSync')
    ->willReturn(FALSE);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('hasLocalChange')
    ->willReturn(FALSE);
  $fieldDefinition = $this
    ->createMock('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
  $fieldDefinition
    ->expects($this
    ->any())
    ->method('getType')
    ->willReturn('text');
  $node
    ->expects($this
    ->any())
    ->method('getFieldDefinition')
    ->willReturn($fieldDefinition);
  $field_comparisons = [
    '12:node.same_field_2' => [
      '#data' => [
        '#left' => 'same_value_2',
        '#right' => 'same_value_2',
      ],
    ],
  ];
  $reference = $this
    ->createMock('\\Drupal\\node\\NodeInterface');
  $reference->original = $this
    ->createMock('\\Drupal\\node\\NodeInterface');
  $entity1 = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityInterface');
  $entity_type = $this
    ->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $entity1
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->will($this
    ->returnValue($entity_type));

  // Set uuid for entity reference 1.
  $entity1
    ->method('uuid')
    ->willReturn('test-uuid-reference-1');
  $entity_type
    ->expects($this
    ->any())
    ->method('entityClassImplements')
    ->willReturn(TRUE);
  $referenced_entities1[] = $entity1;
  $entity2 = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityInterface');
  $entity2
    ->expects($this
    ->any())
    ->method('getEntityType')
    ->will($this
    ->returnValue($entity_type));

  // Set uuid for entity reference 2.
  $entity2
    ->method('uuid')
    ->willReturn('test-uuid-reference-2');
  $entity_type
    ->expects($this
    ->any())
    ->method('entityClassImplements')
    ->willReturn(TRUE);
  $referenced_entities2[] = $entity2;

  // Set reference to node.
  $node
    ->expects($this
    ->once())
    ->method('referencedEntities')
    ->willReturn($referenced_entities1);

  // Set reference to origin node.
  $node->original
    ->expects($this
    ->once())
    ->method('referencedEntities')
    ->willReturn($referenced_entities2);
  $this->diffEntityComparison
    ->expects($this
    ->once())
    ->method('compareRevisions')
    ->with($original_node, $node)
    ->willReturn($field_comparisons);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->never())
    ->method('setLocalChange');
  $this->contentHubEntitiesTracking
    ->expects($this
    ->never())
    ->method('save');
  $this->importEntityManager
    ->entityPresave($node);
}