You are here

public function ScheduledTransitionsUtilityUnitTest::testGenerateRevisionLog in Scheduled Transitions 2.x

Tests revision log generator.

@covers ::generateRevisionLog @dataProvider providerGenerateRevisionLog

Parameters

string $transitioningRevisionId: Revision ID of the transitioning revision.

string $latestRevisionId: Revision ID of the latest revision of an entity..

array $options: Scheduled transitions entity options.

string $expectedRevisionLog: The expected revision log.

File

tests/src/Unit/ScheduledTransitionsUtilityUnitTest.php, line 44

Class

ScheduledTransitionsUtilityUnitTest
Tests scheduled transactions utility.

Namespace

Drupal\Tests\scheduled_transitions\Unit

Code

public function testGenerateRevisionLog(string $transitioningRevisionId, string $latestRevisionId, array $options, string $expectedRevisionLog) : void {
  $configFactory = $this
    ->createMock(ConfigFactoryInterface::class);
  $settings = $this
    ->createMock(ImmutableConfig::class);
  $settings
    ->expects($this
    ->any())
    ->method('get')
    ->willReturnMap([
    [
      'message_transition_latest',
      'template for latest revision',
    ],
    [
      'message_transition_historical',
      'template for historical revision',
    ],
  ]);
  $configFactory
    ->expects($this
    ->any())
    ->method('get')
    ->with('scheduled_transitions.settings')
    ->willReturn($settings);
  $cache = $this
    ->createMock(CacheBackendInterface::class);
  $entityTypeManager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $entityStorage = $this
    ->createMock(RevisionableStorageInterface::class);
  $latest = $this
    ->createMock(RevisionLogInterface::class);
  $latest
    ->expects($this
    ->any())
    ->method('getRevisionId')
    ->willReturn($latestRevisionId);
  $entityStorage
    ->expects($this
    ->once())
    ->method('getLatestRevisionId')
    ->with('1337')
    ->willReturn('2000');
  $entityStorage
    ->expects($this
    ->once())
    ->method('loadRevision')
    ->with('2000')
    ->willReturn($latest);
  $entityTypeManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('test_entity_type')
    ->willReturn($entityStorage);
  $bundleInfo = $this
    ->createMock(EntityTypeBundleInfoInterface::class);
  $moderationInformation = $this
    ->createMock(ModerationInformationInterface::class);
  $token = $this
    ->createMock(Token::class);
  $token
    ->expects($this
    ->once())
    ->method('replace')
    ->willReturnArgument(0);
  $translation = $this
    ->createMock(TranslationInterface::class);
  $utility = new ScheduledTransitionsUtility($configFactory, $cache, $entityTypeManager, $bundleInfo, $moderationInformation, $token, $translation);
  $scheduledTransition = $this
    ->createMock(ScheduledTransitionInterface::class);
  $scheduledTransition
    ->expects($this
    ->once())
    ->method('getOptions')
    ->willReturn($options);
  $newRevision = $this
    ->createMock(RevisionLogInterface::class);
  $newRevision
    ->expects($this
    ->once())
    ->method('id')
    ->willReturn(1337);
  $newRevision
    ->expects($this
    ->once())
    ->method('getEntityTypeId')
    ->willReturn('test_entity_type');
  $newRevision
    ->expects($this
    ->any())
    ->method('getRevisionId')
    ->willReturn($transitioningRevisionId);
  $this
    ->assertEquals($expectedRevisionLog, $utility
    ->generateRevisionLog($scheduledTransition, $newRevision));
}