class ScheduledTransitionsLocalTaskUnitTest in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsLocalTaskUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsLocalTaskUnitTest
Tests local task.
@coversDefaultClass \Drupal\scheduled_transitions\Plugin\Menu\LocalTask\ScheduledTransitionsLocalTask @group scheduled_transitions
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsLocalTaskUnitTest
Expanded class hierarchy of ScheduledTransitionsLocalTaskUnitTest
File
- tests/
src/ Unit/ ScheduledTransitionsLocalTaskUnitTest.php, line 24
Namespace
Drupal\Tests\scheduled_transitions\UnitView source
class ScheduledTransitionsLocalTaskUnitTest extends UnitTestCase {
/**
* Tests operation not handled by hook.
*
* @covers ::getTitle
*/
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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ScheduledTransitionsLocalTaskUnitTest:: |
public | function | Tests operation not handled by hook. | |
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 | Mocks a block with a block plugin. | 1 |
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 | 340 |