function RedirectResponseSubscriberTest::setUp

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::setUp()
  3. 11.x core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\RedirectResponseSubscriberTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php, line 40

Class

RedirectResponseSubscriberTest
@coversDefaultClass \Drupal\Core\EventSubscriber\RedirectResponseSubscriber @group EventSubscriber

Namespace

Drupal\Tests\Core\EventSubscriber

Code

protected function setUp() : void {
    parent::setUp();
    $this->requestContext = $this->getMockBuilder('Drupal\\Core\\Routing\\RequestContext')
        ->disableOriginalConstructor()
        ->getMock();
    $this->requestContext
        ->expects($this->any())
        ->method('getCompleteBaseUrl')
        ->willReturn('http://example.com/drupal');
    $this->urlAssembler = $this->createMock(UnroutedUrlAssemblerInterface::class);
    $this->urlAssembler
        ->expects($this->any())
        ->method('assemble')
        ->willReturnMap([
        [
            'base:test',
            [
                'query' => [],
                'fragment' => '',
                'absolute' => TRUE,
            ],
            FALSE,
            'http://example.com/drupal/test',
        ],
        [
            'base:example.com',
            [
                'query' => [],
                'fragment' => '',
                'absolute' => TRUE,
            ],
            FALSE,
            'http://example.com/drupal/example.com',
        ],
        [
            'base:example:com',
            [
                'query' => [],
                'fragment' => '',
                'absolute' => TRUE,
            ],
            FALSE,
            'http://example.com/drupal/example:com',
        ],
        [
            'base:javascript:alert(0)',
            [
                'query' => [],
                'fragment' => '',
                'absolute' => TRUE,
            ],
            FALSE,
            'http://example.com/drupal/javascript:alert(0)',
        ],
    ]);
    $container = new Container();
    $container->set('router.request_context', $this->requestContext);
    \Drupal::setContainer($container);
}

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