You are here

public function ImportEntityManagerTest::testEntityPresaveCompareYesLocalChange in Acquia Content Hub 8

Tests the entityPresave() method, compare, and yes setLocalChange.

@covers ::entityPresave

File

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

Class

ImportEntityManagerTest
PHPUnit test for the ImportEntityManager class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testEntityPresaveCompareYesLocalChange() {
  $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_1' => [
      '#data' => [
        '#left' => 'same_value_1',
        '#right' => 'same_value_1',
      ],
    ],
    '12:node.difference_field_2' => [
      '#data' => [
        '#left' => 'a_value',
        '#right' => 'a_different_value',
      ],
    ],
    '12:node.same_field_2' => [
      '#data' => [
        '#left' => 'same_value_2',
        '#right' => 'same_value_2',
      ],
    ],
  ];
  $this->diffEntityComparison
    ->expects($this
    ->once())
    ->method('compareRevisions')
    ->with($original_node, $node)
    ->willReturn($field_comparisons);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('setLocalChange');
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('save');
  $this->importEntityManager
    ->entityPresave($node);
}