Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / site / MediaWikiPageNameNormalizerTest.php
blob64cdbaa915fea249b5469acf2094cc64ad19e259
1 <?php
3 use MediaWiki\Site\MediaWikiPageNameNormalizer;
5 /**
6 * @covers MediaWiki\Site\MediaWikiPageNameNormalizer
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.
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.
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
23 * @since 1.27
25 * @group Site
26 * @group medium
28 * @author Marius Hoch
30 class MediaWikiPageNameNormalizerTest extends PHPUnit_Framework_TestCase {
32 /**
33 * @dataProvider normalizePageTitleProvider
35 public function testNormalizePageTitle( $expected, $pageName, $getResponse ) {
36 MediaWikiPageNameNormalizerTestMockHttp::$response = $getResponse;
38 $normalizer = new MediaWikiPageNameNormalizer(
39 new MediaWikiPageNameNormalizerTestMockHttp()
42 $this->assertSame(
43 $expected,
44 $normalizer->normalizePageName( $pageName, 'https://www.wikidata.org/w/api.php' )
48 public function normalizePageTitleProvider() {
49 // Response are taken from wikidata and kkwiki using the following API request
50 // api.php?action=query&prop=info&redirects=1&converttitles=1&format=json&titles=…
51 return [
52 'universe (Q1)' => [
53 'Q1',
54 'Q1',
55 '{"batchcomplete":"","query":{"pages":{"129":{"pageid":129,"ns":0,'
56 . '"title":"Q1","contentmodel":"wikibase-item","pagelanguage":"en",'
57 . '"pagelanguagehtmlcode":"en","pagelanguagedir":"ltr",'
58 . '"touched":"2016-06-23T05:11:21Z","lastrevid":350004448,"length":58001}}}}'
60 'Q404 redirects to Q395' => [
61 'Q395',
62 'Q404',
63 '{"batchcomplete":"","query":{"redirects":[{"from":"Q404","to":"Q395"}],"pages"'
64 . ':{"601":{"pageid":601,"ns":0,"title":"Q395","contentmodel":"wikibase-item",'
65 . '"pagelanguage":"en","pagelanguagehtmlcode":"en","pagelanguagedir":"ltr",'
66 . '"touched":"2016-06-23T08:00:20Z","lastrevid":350021914,"length":60108}}}}'
68 'D converted to Д (Latin to Cyrillic) (taken from kkwiki)' => [
69 'Д',
70 'D',
71 '{"batchcomplete":"","query":{"converted":[{"from":"D","to":"\u0414"}],'
72 . '"pages":{"510541":{"pageid":510541,"ns":0,"title":"\u0414",'
73 . '"contentmodel":"wikitext","pagelanguage":"kk","pagelanguagehtmlcode":"kk",'
74 . '"pagelanguagedir":"ltr","touched":"2015-11-22T09:16:18Z",'
75 . '"lastrevid":2373618,"length":3501}}}}'
77 'there is no Q0' => [
78 false,
79 'Q0',
80 '{"batchcomplete":"","query":{"pages":{"-1":{"ns":0,"title":"Q0",'
81 . '"missing":"","contentmodel":"wikibase-item","pagelanguage":"en",'
82 . '"pagelanguagehtmlcode":"en","pagelanguagedir":"ltr"}}}}'
84 'invalid title' => [
85 false,
86 '{{',
87 '{"batchcomplete":"","query":{"pages":{"-1":{"title":"{{",'
88 . '"invalidreason":"The requested page title contains invalid '
89 . 'characters: \"{\".","invalid":""}}}}'
91 'error on get' => [ false, 'ABC', false ]
97 /**
98 * @private
99 * @see Http
101 class MediaWikiPageNameNormalizerTestMockHttp extends Http {
104 * @var mixed
106 public static $response;
108 public static function get( $url, $options = [], $caller = __METHOD__ ) {
109 PHPUnit_Framework_Assert::assertInternalType( 'string', $url );
110 PHPUnit_Framework_Assert::assertInternalType( 'array', $options );
111 PHPUnit_Framework_Assert::assertInternalType( 'string', $caller );
113 return self::$response;