Skip to content
Snippets Groups Projects
Verified Commit ec1b6713 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3474640 by benjifisher, joachim:...

Issue #3474640 by benjifisher, joachim: Drupal\Tests\migrate\Unit\destination\EntityRevisionTest uses weird mocking pattern
parent 371e006e
No related branches found
No related tags found
13 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #318998 passed with warnings
Pipeline: drupal

#319034

    Pipeline: drupal

    #319029

      Pipeline: drupal

      #319025

        +4
        ...@@ -5,14 +5,19 @@ ...@@ -5,14 +5,19 @@
        namespace Drupal\Tests\migrate\Unit\destination; namespace Drupal\Tests\migrate\Unit\destination;
        use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
        use Drupal\Core\Entity\EntityFieldManagerInterface;
        use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
        use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
        use Drupal\Core\Entity\RevisionableInterface;
        use Drupal\Core\Entity\RevisionableStorageInterface;
        use Drupal\Core\Field\FieldTypePluginManagerInterface;
        use Drupal\Core\Session\AccountSwitcherInterface; use Drupal\Core\Session\AccountSwitcherInterface;
        use Drupal\migrate\Plugin\MigrationInterface;
        use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision; use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision;
        use Drupal\migrate\Plugin\MigrationInterface;
        use Drupal\migrate\Row; use Drupal\migrate\Row;
        use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
        use Prophecy\Argument; use Prophecy\Argument;
        use Prophecy\Prophecy\ObjectProphecy;
        /** /**
        * Tests entity revision destination. * Tests entity revision destination.
        ...@@ -25,29 +30,27 @@ class EntityRevisionTest extends UnitTestCase { ...@@ -25,29 +30,27 @@ class EntityRevisionTest extends UnitTestCase {
        /** /**
        * @var \Drupal\migrate\Plugin\MigrationInterface * @var \Drupal\migrate\Plugin\MigrationInterface
        */ */
        protected $migration; protected MigrationInterface $migration;
        /** /**
        * @var \Drupal\Core\Entity\RevisionableStorageInterface * @var \Prophecy\Prophecy\ObjectProphecy
        */ */
        protected $storage; protected ObjectProphecy $storage;
        /** /**
        * @var \Drupal\Core\Entity\EntityFieldManagerInterface * @var \Drupal\Core\Entity\EntityFieldManagerInterface
        */ */
        protected $entityFieldManager; protected EntityFieldManagerInterface $entityFieldManager;
        /** /**
        * @var \Drupal\Core\Field\FieldTypePluginManagerInterface * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
        */ */
        protected $fieldTypeManager; protected FieldTypePluginManagerInterface $fieldTypeManager;
        /** /**
        * A mock account switcher. * @var \Drupal\Core\Session\AccountSwitcherInterface
        *
        * @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\Core\Session\AccountSwitcherInterface
        */ */
        protected $accountSwitcher; protected AccountSwitcherInterface $accountSwitcher;
        /** /**
        * {@inheritdoc} * {@inheritdoc}
        ...@@ -56,17 +59,19 @@ protected function setUp(): void { ...@@ -56,17 +59,19 @@ protected function setUp(): void {
        parent::setUp(); parent::setUp();
        // Setup mocks to be used when creating a revision destination. // Setup mocks to be used when creating a revision destination.
        $this->migration = $this->prophesize(MigrationInterface::class); $this->migration = $this->prophesize(MigrationInterface::class)->reveal();
        $this->storage = $this->prophesize('\Drupal\Core\Entity\RevisionableStorageInterface'); $this->storage = $this->prophesize(RevisionableStorageInterface::class);
        $entity_type = $this->prophesize(EntityTypeInterface::class); $entity_type = $this->prophesize(EntityTypeInterface::class);
        $entity_type->getSingularLabel()->willReturn('crazy'); $entity_type->getSingularLabel()->willReturn('crazy');
        $entity_type->getPluralLabel()->willReturn('craziness'); $entity_type->getPluralLabel()->willReturn('craziness');
        $entity_type->getKey('id')->willReturn('nid');
        $entity_type->getKey('revision')->willReturn('vid');
        $this->storage->getEntityType()->willReturn($entity_type->reveal()); $this->storage->getEntityType()->willReturn($entity_type->reveal());
        $this->entityFieldManager = $this->prophesize('\Drupal\Core\Entity\EntityFieldManagerInterface'); $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class)->reveal();
        $this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface'); $this->fieldTypeManager = $this->prophesize(FieldTypePluginManagerInterface::class)->reveal();
        $this->accountSwitcher = $this->prophesize(AccountSwitcherInterface::class); $this->accountSwitcher = $this->prophesize(AccountSwitcherInterface::class)->reveal();
        } }
        /** /**
        ...@@ -77,7 +82,7 @@ protected function setUp(): void { ...@@ -77,7 +82,7 @@ protected function setUp(): void {
        public function testGetEntityDestinationValues(): void { public function testGetEntityDestinationValues(): void {
        $destination = $this->getEntityRevisionDestination([]); $destination = $this->getEntityRevisionDestination([]);
        // Return a dummy because we don't care what gets called. // Return a dummy because we don't care what gets called.
        $entity = $this->prophesize('\Drupal\Core\Entity\RevisionableInterface'); $entity = $this->prophesize(RevisionableInterface::class);
        // Assert that the first ID from the destination values is used to load the // Assert that the first ID from the destination values is used to load the
        // entity. // entity.
        $this->storage->loadRevision(12) $this->storage->loadRevision(12)
        ...@@ -94,12 +99,7 @@ public function testGetEntityDestinationValues(): void { ...@@ -94,12 +99,7 @@ public function testGetEntityDestinationValues(): void {
        */ */
        public function testGetEntityUpdateRevision(): void { public function testGetEntityUpdateRevision(): void {
        $destination = $this->getEntityRevisionDestination([]); $destination = $this->getEntityRevisionDestination([]);
        $entity = $this->prophesize('\Drupal\Core\Entity\RevisionableInterface'); $entity = $this->prophesize(RevisionableInterface::class);
        $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface');
        $entity_type->getKey('id')->willReturn('nid');
        $entity_type->getKey('revision')->willReturn('vid');
        $this->storage->getEntityType()->willReturn($entity_type->reveal());
        // Assert we load the correct revision. // Assert we load the correct revision.
        $this->storage->loadRevision(2) $this->storage->loadRevision(2)
        ...@@ -121,12 +121,7 @@ public function testGetEntityUpdateRevision(): void { ...@@ -121,12 +121,7 @@ public function testGetEntityUpdateRevision(): void {
        */ */
        public function testGetEntityNewRevision(): void { public function testGetEntityNewRevision(): void {
        $destination = $this->getEntityRevisionDestination([]); $destination = $this->getEntityRevisionDestination([]);
        $entity = $this->prophesize('\Drupal\Core\Entity\RevisionableInterface'); $entity = $this->prophesize(RevisionableInterface::class);
        $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface');
        $entity_type->getKey('id')->willReturn('nid');
        $entity_type->getKey('revision')->willReturn('vid');
        $this->storage->getEntityType()->willReturn($entity_type->reveal());
        // Enforce is new should be disabled. // Enforce is new should be disabled.
        $entity->enforceIsNew(FALSE)->shouldBeCalled(); $entity->enforceIsNew(FALSE)->shouldBeCalled();
        ...@@ -152,11 +147,6 @@ public function testGetEntityNewRevision(): void { ...@@ -152,11 +147,6 @@ public function testGetEntityNewRevision(): void {
        public function testGetEntityLoadFailure(): void { public function testGetEntityLoadFailure(): void {
        $destination = $this->getEntityRevisionDestination([]); $destination = $this->getEntityRevisionDestination([]);
        $entity_type = $this->prophesize('\Drupal\Core\Entity\EntityTypeInterface');
        $entity_type->getKey('id')->willReturn('nid');
        $entity_type->getKey('revision')->willReturn('vid');
        $this->storage->getEntityType()->willReturn($entity_type->reveal());
        // Return a failed load and make sure we don't fail and we return FALSE. // Return a failed load and make sure we don't fail and we return FALSE.
        $this->storage->load(1) $this->storage->load(1)
        ->shouldBeCalled() ->shouldBeCalled()
        ...@@ -173,7 +163,7 @@ public function testGetEntityLoadFailure(): void { ...@@ -173,7 +163,7 @@ public function testGetEntityLoadFailure(): void {
        * @covers ::save * @covers ::save
        */ */
        public function testSave(): void { public function testSave(): void {
        $entity = $this->prophesize('\Drupal\Core\Entity\ContentEntityInterface'); $entity = $this->prophesize(ContentEntityInterface::class);
        $entity->save() $entity->save()
        ->shouldBeCalled(); ->shouldBeCalled();
        // Syncing should be set once. // Syncing should be set once.
        ...@@ -203,12 +193,12 @@ public function testSave(): void { ...@@ -203,12 +193,12 @@ public function testSave(): void {
        */ */
        protected function getEntityRevisionDestination(array $configuration = [], $plugin_id = 'entity_revision', array $plugin_definition = []) { protected function getEntityRevisionDestination(array $configuration = [], $plugin_id = 'entity_revision', array $plugin_definition = []) {
        return new EntityRevision($configuration, $plugin_id, $plugin_definition, return new EntityRevision($configuration, $plugin_id, $plugin_definition,
        $this->migration->reveal(), $this->migration,
        $this->storage->reveal(), $this->storage->reveal(),
        [], [],
        $this->entityFieldManager->reveal(), $this->entityFieldManager,
        $this->fieldTypeManager->reveal(), $this->fieldTypeManager,
        $this->accountSwitcher->reveal() $this->accountSwitcher,
        ); );
        } }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment