function NavigationEntityRouteHelperTest::testContentEntityFromRouteWithNonExistentRoute

Same name and namespace in other branches
  1. 11.x core/modules/navigation/tests/src/Kernel/NavigationEntityRouteHelperTest.php \Drupal\Tests\navigation\Kernel\NavigationEntityRouteHelperTest::testContentEntityFromRouteWithNonExistentRoute()

Tests entity route helper when the route does not exist.

See also

\Drupal\navigation\EntityRouteHelper::getContentEntityFromRoute

\Drupal\navigation\EntityRouteHelper::isContentEntityFromRoute

File

core/modules/navigation/tests/src/Kernel/NavigationEntityRouteHelperTest.php, line 37

Class

NavigationEntityRouteHelperTest
Tests \Drupal\navigation\EntityRouteHelper.

Namespace

Drupal\Tests\navigation\Kernel

Code

public function testContentEntityFromRouteWithNonExistentRoute() : void {
  $request = Request::create('/does-not-exist');
  $response = $this->container
    ->get('http_kernel')
    ->handle($request);
  $this->assertEquals(404, $response->getStatusCode());
  $this->assertNull($this->container
    ->get('navigation.entity_route_helper')
    ->getContentEntityFromRoute());
  $this->assertFalse($this->container
    ->get('navigation.entity_route_helper')
    ->isContentEntityRoute());
}

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