Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
— | — | @@ -877,6 +877,33 @@ |
878 | 878 | // are less consistent. |
879 | 879 | ); |
880 | 880 | } |
| 881 | + |
| 882 | + /** |
| 883 | + * @dataProvider provideWfMatchesDomainList |
| 884 | + */ |
| 885 | + function testWfMatchesDomainList( $url, $domains, $expected, $description ) { |
| 886 | + $actual = wfMatchesDomainList( $url, $domains ); |
| 887 | + $this->assertEquals( $expected, $actual, $description ); |
| 888 | + } |
| 889 | + |
| 890 | + function provideWfMatchesDomainList() { |
| 891 | + $a = array(); |
| 892 | + $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ); |
| 893 | + foreach ( $protocols as $pDesc => $p ) { |
| 894 | + $a = array_merge( $a, array( |
| 895 | + array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ), |
| 896 | + array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ), |
| 897 | + array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ), |
| 898 | + 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" ), |
| 899 | + array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ), |
| 900 | + array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ), |
| 901 | + |
| 902 | + // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case |
| 903 | + array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ), |
| 904 | + ) ); |
| 905 | + } |
| 906 | + return $a; |
| 907 | + } |
881 | 908 | |
882 | 909 | /* TODO: many more! */ |
883 | 910 | } |