You are here

public function EntityBrowserTest::testDynamicRoutes in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Extension/EntityBrowserTest.php \Drupal\Tests\entity_browser\Kernel\Extension\EntityBrowserTest::testDynamicRoutes()

Tests dynamic routes.

File

tests/src/Kernel/Extension/EntityBrowserTest.php, line 247

Class

EntityBrowserTest
Tests the entity_browser config entity.

Namespace

Drupal\Tests\entity_browser\Kernel\Extension

Code

public function testDynamicRoutes() {
  $this
    ->installConfig([
    'entity_browser_test',
  ]);
  $this->container
    ->get('router.builder')
    ->rebuild();

  /** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
  $entity = $this->controller
    ->load('test');
  $route = $entity
    ->route();
  $this
    ->assertEquals($route
    ->getPath(), '/entity-browser/test', 'Dynamic path matches.');
  $this
    ->assertEquals($route
    ->getDefault('entity_browser_id'), $entity
    ->id(), 'Entity browser ID matches.');
  $this
    ->assertEquals($route
    ->getDefault('_controller'), 'Drupal\\entity_browser\\Controllers\\EntityBrowserFormController::getContentResult', 'Controller matches.');
  $this
    ->assertEquals($route
    ->getDefault('_title_callback'), 'Drupal\\entity_browser\\Controllers\\EntityBrowserFormController::title', 'Title callback matches.');
  $this
    ->assertEquals($route
    ->getRequirement('_permission'), 'access ' . $entity
    ->id() . ' entity browser pages', 'Permission matches.');
  try {
    $registered_route = $this->routeProvider
      ->getRouteByName('entity_browser.' . $entity
      ->id());
  } catch (\Exception $e) {
    $this
      ->fail(t('Expected route not found: @message', [
      '@message' => $e
        ->getMessage(),
    ]));
    return;
  }
  $this
    ->assertEquals($registered_route
    ->getPath(), '/entity-browser/test', 'Dynamic path matches.');
  $this
    ->assertEquals($registered_route
    ->getDefault('entity_browser_id'), $entity
    ->id(), 'Entity browser ID matches.');
  $this
    ->assertEquals($registered_route
    ->getDefault('_controller'), 'Drupal\\entity_browser\\Controllers\\EntityBrowserFormController::getContentResult', 'Controller matches.');
  $this
    ->assertEquals($registered_route
    ->getDefault('_title_callback'), 'Drupal\\entity_browser\\Controllers\\EntityBrowserFormController::title', 'Title callback matches.');
  $this
    ->assertEquals($registered_route
    ->getRequirement('_permission'), 'access ' . $entity
    ->id() . ' entity browser pages', 'Permission matches.');
}