You are here

public function FieldRedirectionResultBuilderLinkTest::testFieldRedirectionResultBuilderSuccess in Field Redirection 8.2

Tests the builder for redirect state.

File

tests/src/Kernel/FieldRedirectionResultBuilderLinkTest.php, line 195

Class

FieldRedirectionResultBuilderLinkTest
Defines a class for testing field redirection result builder for link fields.

Namespace

Drupal\Tests\field_redirection\Kernel

Code

public function testFieldRedirectionResultBuilderSuccess() {
  $entity = $this
    ->createTestEntity([
    'field_redirect_link' => [
      'uri' => 'http://example.com',
    ],
  ]);
  $builder = \Drupal::service('field_redirection.result_builder');
  $request = Request::create('/user');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_NAME, 'user.page');
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/user'));
  \Drupal::requestStack()
    ->push($request);
  $this
    ->assertEquals(FieldRedirectionResult::fromUrl(Url::fromUri('http://example.com')), $builder
    ->buildResult($entity
    ->get('field_redirect_link'), $request, $this
    ->createUser()));
}