3 use MediaWiki\Site\MediaWikiPageNameNormalizer
;
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
30 class MediaWikiPageNameNormalizerTest
extends PHPUnit_Framework_TestCase
{
33 * @dataProvider normalizePageTitleProvider
35 public function testNormalizePageTitle( $expected, $pageName, $getResponse ) {
36 MediaWikiPageNameNormalizerTestMockHttp
::$response = $getResponse;
38 $normalizer = new MediaWikiPageNameNormalizer(
39 new MediaWikiPageNameNormalizerTestMockHttp()
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=…
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' => [
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)' => [
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}}}}'
80 '{"batchcomplete":"","query":{"pages":{"-1":{"ns":0,"title":"Q0",'
81 . '"missing":"","contentmodel":"wikibase-item","pagelanguage":"en",'
82 . '"pagelanguagehtmlcode":"en","pagelanguagedir":"ltr"}}}}'
87 '{"batchcomplete":"","query":{"pages":{"-1":{"title":"{{",'
88 . '"invalidreason":"The requested page title contains invalid '
89 . 'characters: \"{\".","invalid":""}}}}'
91 'error on get' => [ false, 'ABC', false ]
101 class MediaWikiPageNameNormalizerTestMockHttp
extends Http
{
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;