function RouteProviderTest::testHtmlRoutes

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php \Drupal\KernelTests\Core\Entity\RouteProviderTest::testHtmlRoutes()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php \Drupal\KernelTests\Core\Entity\RouteProviderTest::testHtmlRoutes()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php \Drupal\KernelTests\Core\Entity\RouteProviderTest::testHtmlRoutes()

@covers \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getRoutes

File

core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php, line 60

Class

RouteProviderTest
Tests route providers for entity types.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testHtmlRoutes() {
    
    /** @var \Drupal\Core\Routing\RouteProviderInterface $route_provider */
    $route_provider = \Drupal::service('router.route_provider');
    $route = $route_provider->getRouteByName('entity.entity_test_mul.canonical');
    $this->assertEquals('entity_test_mul.full', $route->getDefault('_entity_view'));
    $this->assertEquals('\\Drupal\\Core\\Entity\\Controller\\EntityController::title', $route->getDefault('_title_callback'));
    $this->assertEquals('entity_test_mul.view', $route->getRequirement('_entity_access'));
    $this->assertFalse($route->hasOption('_admin_route'));
    $route = $route_provider->getRouteByName('entity.entity_test_mul.edit_form');
    $this->assertEquals('entity_test_mul.default', $route->getDefault('_entity_form'));
    $this->assertEquals('\\Drupal\\Core\\Entity\\Controller\\EntityController::editTitle', $route->getDefault('_title_callback'));
    $this->assertEquals('entity_test_mul.update', $route->getRequirement('_entity_access'));
    $this->assertFalse($route->hasOption('_admin_route'));
    $route = $route_provider->getRouteByName('entity.entity_test_mul.delete_form');
    $this->assertEquals('entity_test_mul.delete', $route->getDefault('_entity_form'));
    $this->assertEquals('\\Drupal\\Core\\Entity\\Controller\\EntityController::deleteTitle', $route->getDefault('_title_callback'));
    $this->assertEquals('entity_test_mul.delete', $route->getRequirement('_entity_access'));
    $this->assertFalse($route->hasOption('_admin_route'));
    $entity = EntityTestMul::create([
        'name' => 'Test title',
    ]);
    $entity->save();
    $this->setRawContent($this->httpKernelHandle($entity->toUrl()
        ->toString()));
    $this->assertTitle('Test title | ');
    $this->setRawContent($this->httpKernelHandle($entity->toUrl('edit-form')
        ->toString()));
    $this->assertTitle('Edit Test title | ');
    $this->setRawContent($this->httpKernelHandle($entity->toUrl('delete-form')
        ->toString()));
    $this->assertTitle('Are you sure you want to delete the test entity - data table Test title? | ');
}

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