diff --git a/core/modules/system/src/Tests/Path/MatchPathTest.php b/core/modules/system/src/Tests/Path/MatchPathTest.php deleted file mode 100644 index 4adb5cf..0000000 --- a/core/modules/system/src/Tests/Path/MatchPathTest.php +++ /dev/null @@ -1,131 +0,0 @@ - 'Drupal match path', - 'description' => 'Tests the drupal_match_path() function to make sure it works properly.', - 'group' => 'Path API', - ); - } - - function setUp() { - // Set up the database and testing environment. - parent::setUp(); - - // Set up a random site front page to test the '' placeholder. - $this->front = $this->randomName(); - \Drupal::config('system.site')->set('page.front', $this->front)->save(); - // Refresh our static variables from the database. - $this->refreshVariables(); - } - - /** - * Run through our test cases, making sure each one works as expected. - */ - function testDrupalMatchPath() { - // Set up our test cases. - $tests = $this->drupalMatchPathTests(); - foreach ($tests as $patterns => $cases) { - foreach ($cases as $path => $expected_result) { - $actual_result = drupal_match_path($path, $patterns); - $this->assertIdentical($actual_result, $expected_result, format_string('Tried matching the path @path to the pattern
@patterns
- expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE)))); - } - } - } - - /** - * Helper function for testDrupalMatchPath(): set up an array of test cases. - * - * @return - * An array of test cases to cycle through. - */ - private function drupalMatchPathTests() { - return array( - // Single absolute paths. - 'example/1' => array( - 'example/1' => TRUE, - 'example/2' => FALSE, - 'test' => FALSE, - ), - // Single paths with wildcards. - 'example/*' => array( - 'example/1' => TRUE, - 'example/2' => TRUE, - 'example/3/edit' => TRUE, - 'example/' => TRUE, - 'example' => FALSE, - 'test' => FALSE, - ), - // Single paths with multiple wildcards. - 'node/*/revisions/*' => array( - 'node/1/revisions/3' => TRUE, - 'node/345/revisions/test' => TRUE, - 'node/23/edit' => FALSE, - 'test' => FALSE, - ), - // Single paths with ''. - '' => array( - $this->front => TRUE, - "$this->front/" => FALSE, - "$this->front/edit" => FALSE, - 'node' => FALSE, - '' => FALSE, - ), - // Paths with both '' and wildcards (should not work). - '/*' => array( - $this->front => FALSE, - "$this->front/" => FALSE, - "$this->front/edit" => FALSE, - 'node/12' => FALSE, - '' => FALSE, - ), - // Multiple paths with the \n delimiter. - "node/*\nnode/*/edit" => array( - 'node/1' => TRUE, - 'node/view' => TRUE, - 'node/32/edit' => TRUE, - 'node/delete/edit' => TRUE, - 'node/50/delete' => TRUE, - 'test/example' => FALSE, - ), - // Multiple paths with the \r delimiter. - "user/*\rexample/*" => array( - 'user/1' => TRUE, - 'example/1' => TRUE, - 'user/1/example/1' => TRUE, - 'user/example' => TRUE, - 'test/example' => FALSE, - 'user' => FALSE, - 'example' => FALSE, - ), - // Multiple paths with the \r\n delimiter. - "test\r\n" => array( - 'test' => TRUE, - $this->front => TRUE, - 'example' => FALSE, - ), - // Test existing regular expressions (should be escaped). - '[^/]+?/[0-9]' => array( - 'test/1' => FALSE, - '[^/]+?/[0-9]' => TRUE, - ), - ); - } -} diff --git a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php index 9c36e2a..6c43478 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathMatcherTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core\Path; +use Drupal\Component\Utility\String; use Drupal\Core\Path\PathMatcher; use Drupal\Tests\UnitTestCase; @@ -24,11 +25,6 @@ class PathMatcherTest extends UnitTestCase { protected $pathMatcher; /** - * @var string - */ - protected $patterns; - - /** * {@inheritdoc} */ public static function getInfo() { @@ -48,33 +44,27 @@ public function setUp() { $config_factory_stub = $this->getConfigFactoryStub( array( 'system.site' => array( - 'page.front' => 'user', + 'page.front' => 'dummy', ), ) ); $this->pathMatcher = new PathMatcher($config_factory_stub); } - /** - * Test that paths matching works with multiple patterns. + * Test that standard paths works with multiple patterns. * * @dataProvider getMatchPathData */ public function testMatchPath($patterns, $paths) { - foreach ($paths as $path) { - $this->assertTrue($this->pathMatcher->matchPath($path, $patterns), "The path $path matches the patterns."); - } - } - - /** - * Test that standard paths works with multiple patterns. - * - * @dataProvider getNoMatchPathData - */ - public function testNoMatchPath($patterns, $paths) { - foreach ($paths as $path) { - $this->assertFalse($this->pathMatcher->matchPath($path, $patterns), "The path $path does not match the patterns."); + foreach ($paths as $path => $expected_result) { + $actual_result = $this->pathMatcher->matchPath($path, $patterns); + $this->assertEquals($actual_result, $expected_result, String::format('Tried matching the path @path to the pattern
@patterns
- expected @expected, got @actual.', array( + '@path' => $path, + '@patterns' => $patterns, + '@expected' => var_export($expected_result, TRUE), + '@actual' => var_export($actual_result, TRUE), + ))); } } @@ -86,30 +76,100 @@ public function testNoMatchPath($patterns, $paths) { */ public function getMatchPathData() { return array( - // Match explicit path pattern. array( - "my/pass/page\r\nmy/pass/page2\r\nfoo", - array('my/pass/page', 'my/pass/page2'), + // Single absolute paths. + 'example/1', + array( + 'example/1' => TRUE, + 'example/2' => FALSE, + 'test' => FALSE, + ), ), - // Match wildcard path pattern. array( - 'my/pass/*', - array('my/pass/page3'), + // Single paths with wildcards. + 'example/*', + array( + 'example/1' => TRUE, + 'example/2' => TRUE, + 'example/3/edit' => TRUE, + 'example/' => TRUE, + 'example' => FALSE, + 'test' => FALSE, + ), + ), + array( + // Single paths with multiple wildcards. + 'node/*/revisions/*', + array( + 'node/1/revisions/3' => TRUE, + 'node/345/revisions/test' => TRUE, + 'node/23/edit' => FALSE, + 'test' => FALSE, + ), + ), + array( + // Single paths with ''. + "", + array( + 'dummy' => TRUE, + "dummy/" => FALSE, + "dummy/edit" => FALSE, + 'node' => FALSE, + '' => FALSE, + ), + ), + array( + // Paths with both '' and wildcards (should not work). + "/*", + array( + 'dummy' => FALSE, + 'dummy/' => FALSE, + 'dummy/edit' => FALSE, + 'node/12' => FALSE, + '' => FALSE, + ), ), - ); - } - - /** - * Provides test path data for non-matches. - * - * @return array - * A nested array of pattern arrays and path arrays. - */ - public function getNoMatchPathData() { - return array( array( - "my/pass/page\r\nmy/pass/page2\r\nfoo", - array('my/pass/page4'), + // Multiple paths with the \n delimiter. + "node/*\nnode/*/edit", + array( + 'node/1' => TRUE, + 'node/view' => TRUE, + 'node/32/edit' => TRUE, + 'node/delete/edit' => TRUE, + 'node/50/delete' => TRUE, + 'test/example' => FALSE, + ), + ), + array( + // Multiple paths with the \r delimiter. + "user/*\rexample/*", + array( + 'user/1' => TRUE, + 'example/1' => TRUE, + 'user/1/example/1' => TRUE, + 'user/example' => TRUE, + 'test/example' => FALSE, + 'user' => FALSE, + 'example' => FALSE, + ), + ), + array( + // Multiple paths with the \r\n delimiter. + "test\r\n", + array( + 'test' => TRUE, + 'dummy' => TRUE, + 'example' => FALSE, + ), + ), + array( + // Test existing regular expressions (should be escaped). + '[^/]+?/[0-9]', + array( + 'test/1' => FALSE, + '[^/]+?/[0-9]' => TRUE, + ), ), ); }