MediaWiki REL1_31
MediaWikiPageNameNormalizerTest.php
Go to the documentation of this file.
1<?php
2
4
30class MediaWikiPageNameNormalizerTest extends PHPUnit\Framework\TestCase {
31
32 use MediaWikiCoversValidator;
33
37 public function testNormalizePageTitle( $expected, $pageName, $getResponse ) {
39
40 $normalizer = new MediaWikiPageNameNormalizer(
42 );
43
44 $this->assertSame(
45 $expected,
46 $normalizer->normalizePageName( $pageName, 'https://www.wikidata.org/w/api.php' )
47 );
48 }
49
50 public function normalizePageTitleProvider() {
51 // Response are taken from wikidata and kkwiki using the following API request
52 // api.php?action=query&prop=info&redirects=1&converttitles=1&format=json&titles=…
53 return [
54 'universe (Q1)' => [
55 'Q1',
56 'Q1',
57 '{"batchcomplete":"","query":{"pages":{"129":{"pageid":129,"ns":0,'
58 . '"title":"Q1","contentmodel":"wikibase-item","pagelanguage":"en",'
59 . '"pagelanguagehtmlcode":"en","pagelanguagedir":"ltr",'
60 . '"touched":"2016-06-23T05:11:21Z","lastrevid":350004448,"length":58001}}}}'
61 ],
62 'Q404 redirects to Q395' => [
63 'Q395',
64 'Q404',
65 '{"batchcomplete":"","query":{"redirects":[{"from":"Q404","to":"Q395"}],"pages"'
66 . ':{"601":{"pageid":601,"ns":0,"title":"Q395","contentmodel":"wikibase-item",'
67 . '"pagelanguage":"en","pagelanguagehtmlcode":"en","pagelanguagedir":"ltr",'
68 . '"touched":"2016-06-23T08:00:20Z","lastrevid":350021914,"length":60108}}}}'
69 ],
70 'D converted to Д (Latin to Cyrillic) (taken from kkwiki)' => [
71 'Д',
72 'D',
73 '{"batchcomplete":"","query":{"converted":[{"from":"D","to":"\u0414"}],'
74 . '"pages":{"510541":{"pageid":510541,"ns":0,"title":"\u0414",'
75 . '"contentmodel":"wikitext","pagelanguage":"kk","pagelanguagehtmlcode":"kk",'
76 . '"pagelanguagedir":"ltr","touched":"2015-11-22T09:16:18Z",'
77 . '"lastrevid":2373618,"length":3501}}}}'
78 ],
79 'there is no Q0' => [
80 false,
81 'Q0',
82 '{"batchcomplete":"","query":{"pages":{"-1":{"ns":0,"title":"Q0",'
83 . '"missing":"","contentmodel":"wikibase-item","pagelanguage":"en",'
84 . '"pagelanguagehtmlcode":"en","pagelanguagedir":"ltr"}}}}'
85 ],
86 'invalid title' => [
87 false,
88 '{{',
89 '{"batchcomplete":"","query":{"pages":{"-1":{"title":"{{",'
90 . '"invalidreason":"The requested page title contains invalid '
91 . 'characters: \"{\".","invalid":""}}}}'
92 ],
93 'error on get' => [ false, 'ABC', false ]
94 ];
95 }
96
97}
98
104
108 public static $response;
109
110 public static function get( $url, $options = [], $caller = __METHOD__ ) {
111 PHPUnit_Framework_Assert::assertInternalType( 'string', $url );
112 PHPUnit_Framework_Assert::assertInternalType( 'array', $options );
113 PHPUnit_Framework_Assert::assertInternalType( 'string', $caller );
114
115 return self::$response;
116 }
117}
Various HTTP related functions.
Definition Http.php:27
MediaWiki\Site\MediaWikiPageNameNormalizer.
testNormalizePageTitle( $expected, $pageName, $getResponse)
normalizePageTitleProvider
Service for normalizing a page name using a MediaWiki api.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187