Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / PathProcessor / PathProcessorFrontTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\PathProcessor;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Config\ImmutableConfig;
7 use Drupal\Core\PathProcessor\PathProcessorFront;
8 use Drupal\Tests\UnitTestCase;
9 use Symfony\Component\HttpFoundation\Request;
10 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
12 /**
13  * Test front page path processing.
14  *
15  * @group PathProcessor
16  * @coversDefaultClass \Drupal\Core\PathProcessor\PathProcessorFront
17  */
18 class PathProcessorFrontTest extends UnitTestCase {
19
20   /**
21    * Test basic inbound processing functionality.
22    *
23    * @covers ::processInbound
24    * @dataProvider providerProcessInbound
25    */
26   public function testProcessInbound($path, $expected) {
27     $config_factory = $this->prophesize(ConfigFactoryInterface::class);
28     $config = $this->prophesize(ImmutableConfig::class);
29     $config_factory->get('system.site')
30       ->willReturn($config->reveal());
31     $config->get('page.front')
32       ->willReturn('/node');
33     $processor = new PathProcessorFront($config_factory->reveal());
34     $this->assertEquals($expected, $processor->processInbound($path, new Request()));
35   }
36
37   /**
38    * Inbound paths and expected results.
39    */
40   public function providerProcessInbound() {
41     return [
42       ['/', '/node'],
43       ['/user', '/user'],
44     ];
45   }
46
47   /**
48    * Test inbound failure with broken config.
49    *
50    * @covers ::processInbound
51    */
52   public function testProcessInboundBadConfig() {
53     $config_factory = $this->prophesize(ConfigFactoryInterface::class);
54     $config = $this->prophesize(ImmutableConfig::class);
55     $config_factory->get('system.site')
56       ->willReturn($config->reveal());
57     $config->get('page.front')
58       ->willReturn('');
59     $processor = new PathProcessorFront($config_factory->reveal());
60     $this->setExpectedException(NotFoundHttpException::class);
61     $processor->processInbound('/', new Request());
62   }
63
64   /**
65    * Test basic outbound processing functionality.
66    *
67    * @covers ::processOutbound
68    * @dataProvider providerProcessOutbound
69    */
70   public function testProcessOutbound($path, $expected) {
71     $config_factory = $this->prophesize(ConfigFactoryInterface::class);
72     $processor = new PathProcessorFront($config_factory->reveal());
73     $this->assertEquals($expected, $processor->processOutbound($path));
74   }
75
76   /**
77    * Outbound paths and expected results.
78    */
79   public function providerProcessOutbound() {
80     return [
81       ['/<front>', '/'],
82       ['<front>', '<front>'],
83       ['/user', '/user'],
84     ];
85   }
86
87 }