class ScheduledTransitionsUtilityUnitTest in Scheduled Transitions 2.x
Tests scheduled transactions utility.
@coversDefaultClass \Drupal\scheduled_transitions\ScheduledTransitionsUtility @group scheduled_transitions
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsUtilityUnitTest
Expanded class hierarchy of ScheduledTransitionsUtilityUnitTest
File
- tests/
src/ Unit/ ScheduledTransitionsUtilityUnitTest.php, line 27
Namespace
Drupal\Tests\scheduled_transitions\UnitView source
class ScheduledTransitionsUtilityUnitTest extends UnitTestCase {
/**
* Tests revision log generator.
*
* @param string $transitioningRevisionId
* Revision ID of the transitioning revision.
* @param string $latestRevisionId
* Revision ID of the latest revision of an entity..
* @param array $options
* Scheduled transitions entity options.
* @param string $expectedRevisionLog
* The expected revision log.
*
* @covers ::generateRevisionLog
* @dataProvider providerGenerateRevisionLog
*/
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));
}
/**
* Data provider for testGenerateRevisionLog.
*/
public function providerGenerateRevisionLog() : array {
$scenarios = [];
$scenarios['historical'] = [
// Transitioning different revisions.
'333',
'444',
[],
'template for historical revision',
];
$scenarios['latest'] = [
// Revision IDs are the same:
'444',
'444',
[],
'template for latest revision',
];
$scenarios['custom'] = [
// Revision IDs are irrelevant.
'444',
'444',
[
'revision_log_override' => TRUE,
'revision_log' => 'custom revision log',
],
'custom revision log',
];
return $scenarios;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
ScheduledTransitionsUtilityUnitTest:: |
public | function | Data provider for testGenerateRevisionLog. | |
ScheduledTransitionsUtilityUnitTest:: |
public | function | Tests revision log generator. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 308 | |
UnitTestCase:: |
public static | function |