You are here

class ScheduledTransitionsLocalTaskUnitTest in Scheduled Transitions 8

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of ScheduledTransitionsLocalTaskUnitTest

File

tests/src/Unit/ScheduledTransitionsLocalTaskUnitTest.php, line 24

Namespace

Drupal\Tests\scheduled_transitions\Unit
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ScheduledTransitionsLocalTaskUnitTest::testLocalTaskTitle public function Tests operation not handled by hook.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340