PathProcessorFrontTest.php

Same filename and directory in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
  2. 10 core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
  3. 11.x core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php

Namespace

Drupal\Tests\Core\PathProcessor

File

core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php

View source
<?php

namespace Drupal\Tests\Core\PathProcessor;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\PathProcessor\PathProcessorFront;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Test front page path processing.
 *
 * @group PathProcessor
 * @coversDefaultClass \Drupal\Core\PathProcessor\PathProcessorFront
 */
class PathProcessorFrontTest extends UnitTestCase {
    
    /**
     * Tests basic inbound processing functionality.
     *
     * @covers ::processInbound
     * @dataProvider providerProcessInbound
     */
    public function testProcessInbound($frontpage_path, $path, $expected, array $expected_query = []) {
        $config_factory = $this->prophesize(ConfigFactoryInterface::class);
        $config = $this->prophesize(ImmutableConfig::class);
        $config_factory->get('system.site')
            ->willReturn($config->reveal());
        $config->get('page.front')
            ->willReturn($frontpage_path);
        $processor = new PathProcessorFront($config_factory->reveal());
        $request = new Request();
        $this->assertEquals($expected, $processor->processInbound($path, $request));
        $this->assertEquals($expected_query, $request->query
            ->all());
    }
    
    /**
     * Inbound paths and expected results.
     */
    public function providerProcessInbound() {
        return [
            'accessing frontpage' => [
                '/node',
                '/',
                '/node',
            ],
            'accessing non frontpage' => [
                '/node',
                '/user',
                '/user',
            ],
            'accessing frontpage with query parameters' => [
                '/node?example=muh',
                '/',
                '/node',
                [
                    'example' => 'muh',
                ],
            ],
        ];
    }
    
    /**
     * Tests inbound failure with broken config.
     *
     * @covers ::processInbound
     */
    public function testProcessInboundBadConfig() {
        $config_factory = $this->prophesize(ConfigFactoryInterface::class);
        $config = $this->prophesize(ImmutableConfig::class);
        $config_factory->get('system.site')
            ->willReturn($config->reveal());
        $config->get('page.front')
            ->willReturn('');
        $processor = new PathProcessorFront($config_factory->reveal());
        $this->expectException(NotFoundHttpException::class);
        $processor->processInbound('/', new Request());
    }

}

Classes

Title Deprecated Summary
PathProcessorFrontTest Test front page path processing.

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