public function ScheduledTransitionsLocalTaskUnitTest::testLocalTaskTitle in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsLocalTaskUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsLocalTaskUnitTest::testLocalTaskTitle()
Tests operation not handled by hook.
@covers ::getTitle
File
- tests/
src/ Unit/ ScheduledTransitionsLocalTaskUnitTest.php, line 31
Class
- ScheduledTransitionsLocalTaskUnitTest
- Tests local task.
Namespace
Drupal\Tests\scheduled_transitions\UnitCode
public function testLocalTaskTitle() : void {
$configuration = [];
$plugin_id = '';
$plugin_definition = [
'base_route' => 'entity.st_entity_test.canonical',
'title' => 'Scheduled transitions',
];
$assertCount = 42;
$currentUserLanguage = 'de';
$entityId = 64;
$entity = $this
->createMock(ContentEntityInterface::class);
$entity
->expects($this
->any())
->method('getEntityTypeId')
->willReturn('st_entity_test');
$entity
->expects($this
->any())
->method('id')
->willReturn($entityId);
$parameters = $this
->createMock(ParameterBag::class);
$parameters
->expects($this
->any())
->method('all')
->willReturn([
'st_entity_test' => $entity,
]);
$routeMatch = $this
->createMock(RouteMatchInterface::class);
$routeMatch
->expects($this
->any())
->method('getParameters')
->willReturn($parameters);
$query = $this
->createMock(QueryInterface::class);
$query
->expects($this
->at(0))
->method('condition')
->with('entity__target_type', 'st_entity_test')
->willReturnSelf();
$query
->expects($this
->at(1))
->method('condition')
->with('entity__target_id', $entityId)
->willReturnSelf();
$query
->expects($this
->any())
->method('count')
->willReturnSelf();
// Return the fake *count* here.
$query
->expects($this
->any())
->method('execute')
->willReturn($assertCount);
$query
->expects($this
->at(2))
->method('condition')
->with('entity_revision_langcode', $currentUserLanguage)
->willReturn($query);
$transitionStorage = $this
->createMock(EntityStorageInterface::class);
$transitionStorage
->expects($this
->any())
->method('getQuery')
->willReturn($query);
$entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$entityTypeManager
->expects($this
->any())
->method('getStorage')
->with('scheduled_transition')
->willReturn($transitionStorage);
$languageManager = $this
->createMock(LanguageManagerInterface::class);
$languageManager
->expects($this
->once())
->method('getCurrentLanguage')
->willReturn(new Language([
'id' => $currentUserLanguage,
]));
$stringTranslation = $this
->getStringTranslationStub();
$localTask = new ScheduledTransitionsLocalTask($configuration, $plugin_id, $plugin_definition, $routeMatch, $entityTypeManager, $languageManager, $stringTranslation);
$this
->assertEquals(sprintf('Scheduled transitions (%s)', $assertCount), (string) $localTask
->getTitle());
}