You are here

public function ReplicatorTest::testCloneForNonFieldableEntity in Replicate 8

Tests the cloneEntity method.

@covers ::cloneEntity

File

tests/src/Unit/ReplicatorTest.php, line 31

Class

ReplicatorTest
@coversDefaultClass \Drupal\replicate\Replicator @group replicate

Namespace

Drupal\Tests\replicate\Unit

Code

public function testCloneForNonFieldableEntity() {
  $entity = $this
    ->prophesize(EntityInterface::class);
  $entity
    ->getEntityTypeId()
    ->willReturn('entity_test');
  $clone = $this
    ->prophesize(EntityInterface::class);
  $clone
    ->getEntityTypeId()
    ->willReturn('entity_test');
  $clone = $clone
    ->reveal();
  $entity
    ->createDuplicate()
    ->willReturn($clone);
  $event_dispatcher = $this
    ->prophesize(EventDispatcherInterface::class);
  $event_dispatcher
    ->dispatch('replicate__entity__entity_test', Argument::type(ReplicateEntityEvent::class))
    ->shouldBeCalled();
  $event_dispatcher
    ->dispatch(ReplicatorEvents::REPLICATE_ALTER, Argument::type(ReplicateAlterEvent::class))
    ->shouldBeCalled();
  $event_dispatcher
    ->dispatch(ReplicatorEvents::AFTER_SAVE, Argument::type(AfterSaveEvent::class))
    ->shouldNotBeCalled();
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $replicator = new Replicator($entity_type_manager
    ->reveal(), $event_dispatcher
    ->reveal());
  $result = $replicator
    ->cloneEntity($entity
    ->reveal());
  $this
    ->assertSame($clone, $result);
}