public function ImportEntityManagerTest::testEntityPresaveCompareExcludeFieldReference in Acquia Content Hub 8
Tests the entityPresave() method.
Exclude configuration entities from comparison.
@covers ::entityPresave
File
- tests/
src/ Unit/ ImportEntityManagerTest.php, line 694
Class
- ImportEntityManagerTest
- PHPUnit test for the ImportEntityManager class.
Namespace
Drupal\Tests\acquia_contenthub\UnitCode
public function testEntityPresaveCompareExcludeFieldReference() {
$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);
$node
->expects($this
->any())
->method('referencedEntities')
->willReturn([]);
$node->original
->expects($this
->any())
->method('referencedEntities')
->willReturn([]);
$this->contentHubEntitiesTracking
->expects($this
->once())
->method('isPendingSync')
->willReturn(FALSE);
$this->contentHubEntitiesTracking
->expects($this
->once())
->method('hasLocalChange')
->willReturn(FALSE);
// Get reference entity.
$referenced_entities = [];
$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));
$entity_type
->expects($this
->once())
->method('entityClassImplements')
->willReturn(TRUE);
$referenced_entities[] = $entity1;
// Set reference field.
$fieldReferenceInterface = $this
->createMock('Drupal\\Core\\Field\\EntityReferenceFieldItemListInterface');
$fieldReferenceInterface
->expects($this
->any())
->method('referencedEntities')
->willReturn($referenced_entities);
$fieldDefinition = $this
->createMock('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
$fieldDefinition
->expects($this
->at(0))
->method('getType')
->willReturn('entity_reference');
$fieldDefinition
->expects($this
->at(1))
->method('getType')
->willReturn('text');
$node
->expects($this
->any())
->method('getFieldDefinition')
->willReturn($fieldDefinition);
$node
->expects($this
->any())
->method('get')
->with('same_field_1')
->willReturn($fieldReferenceInterface);
$field_comparisons = [
'12:node.same_field_1' => [
'#data' => [
'#left' => 'same_value_1',
'#right' => 'same_value_2',
],
],
'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);
}