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;
class PathProcessorFrontTest extends UnitTestCase {
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());
}
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',
],
],
];
}
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());
}
public function testProcessOutbound($path, $expected) {
$config_factory = $this
->prophesize(ConfigFactoryInterface::class);
$processor = new PathProcessorFront($config_factory
->reveal());
$this
->assertEquals($expected, $processor
->processOutbound($path));
}
public function providerProcessOutbound() {
return [
[
'/<front>',
'/',
],
[
'<front>',
'<front>',
],
[
'/user',
'/user',
],
];
}
}