Merge "rc_old/new_len null for CategoryMembership RC change"
[lhc/web/wiklou.git] / tests / phpunit / includes / site / MediaWikiPageNameNormalizerTest.php
1 <?php
2
3 use MediaWiki\Site\MediaWikiPageNameNormalizer;
4
5 /**
6 * @covers MediaWiki\Site\MediaWikiPageNameNormalizer
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @since 1.27
24 *
25 * @group Site
26 * @group medium
27 *
28 * @author Marius Hoch
29 */
30 class MediaWikiPageNameNormalizerTest extends PHPUnit_Framework_TestCase {
31
32 protected function setUp() {
33 parent::setUp();
34
35 static $connectivity = null;
36
37 if ( $connectivity === null ) {
38 // Check whether we have (reasonable fast) connectivity
39 $res = Http::get(
40 'https://www.wikidata.org/w/api.php?action=query&meta=siteinfo&format=json',
41 [ 'timeout' => 3 ],
42 __METHOD__
43 );
44
45 if ( $res === false || strpos( $res, '"sitename":"Wikidata"' ) === false ) {
46 $connectivity = false;
47 } else {
48 $connectivity = true;
49 }
50 }
51
52 if ( !$connectivity ) {
53 $this->markTestSkipped( 'MediaWikiPageNameNormalizerTest needs internet connectivity.' );
54 }
55 }
56
57 /**
58 * @dataProvider normalizePageTitleProvider
59 */
60 public function testNormalizePageTitle( $expected, $pageName ) {
61 $normalizer = new MediaWikiPageNameNormalizer();
62
63 $this->assertSame(
64 $expected,
65 $normalizer->normalizePageName( $pageName, 'https://www.wikidata.org/w/api.php' )
66 );
67 }
68
69 public function normalizePageTitleProvider() {
70 // Note: This makes (very conservative) assumptions about pages on Wikidata
71 // existing or not.
72 return [
73 'universe (Q1)' => [
74 'Q1', 'Q1'
75 ],
76 'Q404 redirects to Q395' => [
77 'Q395', 'Q404'
78 ],
79 'there is no Q0' => [
80 false, 'Q0'
81 ]
82 ];
83 }
84
85 }