3 namespace Drupal\Tests\Core\Path;
5 use Drupal\Core\Path\PathMatcher;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Path\PathMatcher
12 class PathMatcherTest extends UnitTestCase {
15 * The path matcher under test.
17 * @var \Drupal\Core\Path\PathMatcher
19 protected $pathMatcher;
24 protected function setUp() {
25 // Create a stub config factory with all config settings that will be
26 // checked during this test.
27 $config_factory_stub = $this->getConfigFactoryStub(
30 'page.front' => '/dummy',
34 $route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
35 $this->pathMatcher = new PathMatcher($config_factory_stub, $route_match);
39 * Test that standard paths works with multiple patterns.
41 * @dataProvider getMatchPathData
43 public function testMatchPath($patterns, $paths) {
44 foreach ($paths as $path => $expected_result) {
45 $actual_result = $this->pathMatcher->matchPath($path, $patterns);
46 $this->assertEquals($actual_result, $expected_result, "Tried matching the path '$path' to the pattern '$patterns'.");
51 * Provides test path data.
54 * A nested array of pattern arrays and path arrays.
56 public function getMatchPathData() {
59 // Single absolute paths.
63 '/example/2' => FALSE,
68 // Single paths with wildcards.
73 '/example/3/edit' => TRUE,
80 // Single paths with multiple wildcards.
81 '/node/*/revisions/*',
83 '/node/1/revisions/3' => TRUE,
84 '/node/345/revisions/test' => TRUE,
85 '/node/23/edit' => FALSE,
90 // Single paths with '<front>'.
95 "/dummy/edit" => FALSE,
101 // Paths with both '<front>' and wildcards (should not work).
106 '/dummy/edit' => FALSE,
112 // Multiple paths with the \n delimiter.
113 "/node/*\n/node/*/edit",
116 '/node/view' => TRUE,
117 '/node/32/edit' => TRUE,
118 '/node/delete/edit' => TRUE,
119 '/node/50/delete' => TRUE,
120 '/test/example' => FALSE,
124 // Multiple paths with the \r delimiter.
125 "/user/*\r/example/*",
128 '/example/1' => TRUE,
129 '/user/1/example/1' => TRUE,
130 '/user/example' => TRUE,
131 '/test/example' => FALSE,
137 // Multiple paths with the \r\n delimiter.
146 // Test existing regular expressions (should be escaped).
150 '[^/]+?/[0-9]' => TRUE,