EntityControllerTest.php
Same filename and directory in other branches
Namespace
Drupal\Tests\Core\Entity\ControllerFile
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ Controller/ EntityControllerTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\Core\Entity\Controller;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\Controller\EntityController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\TestWith;
/**
* Tests EntityController.
*/
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));
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| EntityControllerTest | Tests EntityController. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.