public function ImportEntityManagerTest::testEntityPresaveCompareNoLocalChange in Acquia Content Hub 8
Tests the entityPresave() method, compare, and no setLocalChange.
@covers ::entityPresave
File
- tests/
src/ Unit/ ImportEntityManagerTest.php, line 380  
Class
- ImportEntityManagerTest
 - PHPUnit test for the ImportEntityManager class.
 
Namespace
Drupal\Tests\acquia_contenthub\UnitCode
public function testEntityPresaveCompareNoLocalChange() {
  $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');
  // Nodes do not have referenced entities.
  $node
    ->expects($this
    ->once())
    ->method('referencedEntities')
    ->willReturn([]);
  $node->original
    ->expects($this
    ->once())
    ->method('referencedEntities')
    ->willReturn([]);
  $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.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
    ->never())
    ->method('setLocalChange');
  $this->contentHubEntitiesTracking
    ->expects($this
    ->never())
    ->method('save');
  $this->importEntityManager
    ->entityPresave($node);
}