class EntityControllerTest

Tests EntityController.

Attributes

#[CoversClass(EntityController::class)] #[Group('Entity')]

Hierarchy

Expanded class hierarchy of EntityControllerTest

File

core/tests/Drupal/Tests/Core/Entity/Controller/EntityControllerTest.php, line 19

Namespace

Drupal\Tests\Core\Entity\Controller
View source
class EntityControllerTest extends UnitTestCase {
  
  /**
   * Tests edit and delete title callbacks.
   *
   * @param string $callback
   *   The controller title callback name.
   * @param string|null $entity_label
   *   The label of the entity being displayed by the controller.
   * @param string $expected_title
   *   The expected title return value.
   */
  public function testDeleteEditTitleCallbacks(string $callback, ?string $entity_label, string $expected_title) : void {
    $container = new ContainerBuilder();
    $container->set('string_translation', $this->getStringTranslationStub());
    \Drupal::setContainer($container);
    $route_match = $this->createStub(RouteMatchInterface::class);
    $entity = $this->createStub(EntityInterface::class);
    $entity->method('label')
      ->willReturn($entity_label);
    $controller = $this->createPartialMock(EntityController::class, [
      'doGetEntity',
    ]);
    $controller->expects($this->once())
      ->method('doGetEntity')
      ->willReturn($entity);
    $this->assertEquals($expected_title, (string) $controller->{$callback}($route_match, $entity));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.