function CustomPageExceptionHtmlSubscriberTest::setUp

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

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php, line 86

Class

CustomPageExceptionHtmlSubscriberTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21EventSubscriber%21CustomPageExceptionHtmlSubscriber.php/class/CustomPageExceptionHtmlSubscriber/11.x" title="Exception subscriber for handling core custom HTML error pages." class="local">\Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber</a> @group EventSubscriber

Namespace

Drupal\Tests\Core\EventSubscriber

Code

protected function setUp() : void {
    parent::setUp();
    $this->configFactory = $this->getConfigFactoryStub([
        'system.site' => [
            'page.403' => '/access-denied-page',
            'page.404' => '/not-found-page',
        ],
    ]);
    $this->kernel = $this->createMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
    $this->logger = $this->createMock('Psr\\Log\\LoggerInterface');
    $this->redirectDestination = $this->createMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
    $this->redirectDestination
        ->expects($this->any())
        ->method('getAsArray')
        ->willReturn([
        'destination' => 'test',
    ]);
    $this->accessUnawareRouter = $this->createMock('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface');
    $this->accessUnawareRouter
        ->expects($this->any())
        ->method('match')
        ->willReturn([
        '_controller' => 'mocked',
    ]);
    $this->accessManager = $this->createMock('Drupal\\Core\\Access\\AccessManagerInterface');
    $this->accessManager
        ->expects($this->any())
        ->method('checkNamedRoute')
        ->willReturn(AccessResult::allowed()->addCacheTags([
        'foo',
        'bar',
    ]));
    $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->kernel, $this->logger, $this->redirectDestination, $this->accessUnawareRouter, $this->accessManager);
    $path_validator = $this->createMock('Drupal\\Core\\Path\\PathValidatorInterface');
    $path_validator->expects($this->any())
        ->method('getUrlIfValidWithoutAccessCheck')
        ->willReturn(Url::fromRoute('foo', [
        'foo' => 'bar',
    ]));
    $container = new ContainerBuilder();
    $container->set('path.validator', $path_validator);
    \Drupal::setContainer($container);
    // You can't create an exception in PHP without throwing it. Store the
    // current error_log, and disable it temporarily.
    $this->errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
}

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