From 2aa5f42df76eeac53362705459037c50e1974466 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 20 Aug 2011 10:41:44 +0000 Subject: [PATCH] Followup r95072: add tests for wfMatchesDomainList --- .../includes/GlobalFunctions/GlobalTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index bfd0ac1986..f55ab9ea06 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -877,6 +877,33 @@ class GlobalTest extends MediaWikiTestCase { // are less consistent. ); } + + /** + * @dataProvider provideWfMatchesDomainList + */ + function testWfMatchesDomainList( $url, $domains, $expected, $description ) { + $actual = wfMatchesDomainList( $url, $domains ); + $this->assertEquals( $expected, $actual, $description ); + } + + function provideWfMatchesDomainList() { + $a = array(); + $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ); + foreach ( $protocols as $pDesc => $p ) { + $a = array_merge( $a, array( + array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ), + array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ), + array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ), + array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ), + array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ), + array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ), + + // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case + array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ), + ) ); + } + return $a; + } /* TODO: many more! */ } -- 2.20.1