function CustomPageExceptionHtmlSubscriberTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::setUp()
  3. 11.x 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 84

Class

CustomPageExceptionHtmlSubscriberTest
@coversDefaultClass \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber @group EventSubscriber

Namespace

Drupal\Tests\Core\EventSubscriber

Code

protected function 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.