|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SIL\Tests\Integration; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\Tests\MwDBaseUnitTestCase; |
|
6
|
|
|
use SMW\Tests\Utils\UtilityFactory; |
|
7
|
|
|
|
|
8
|
|
|
use SMW\DIWikiPage; |
|
9
|
|
|
use SMW\DIProperty; |
|
10
|
|
|
|
|
11
|
|
|
use Title; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @group semantic-interlanguage-links |
|
15
|
|
|
* @group semantic-mediawiki-integration |
|
16
|
|
|
* |
|
17
|
|
|
* @group mediawiki-database |
|
18
|
|
|
* @group medium |
|
19
|
|
|
* |
|
20
|
|
|
* @license GNU GPL v2+ |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
* |
|
23
|
|
|
* @author mwjames |
|
24
|
|
|
*/ |
|
25
|
|
|
class ParserFunctionIntegrationTest extends MwDBaseUnitTestCase { |
|
26
|
|
|
|
|
27
|
|
|
private $pageCreator; |
|
28
|
|
|
private $semanticDataValidator; |
|
29
|
|
|
private $subjects = []; |
|
30
|
|
|
|
|
31
|
|
|
protected function setUp() : void { |
|
32
|
|
|
parent::setUp(); |
|
33
|
|
|
|
|
34
|
|
|
$this->markTestSkipped( |
|
35
|
|
|
"This test is broken in newer MW, needs some investigation!" |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$this->pageCreator = UtilityFactory::getInstance()->newPageCreator(); |
|
39
|
|
|
$this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); |
|
40
|
|
|
|
|
41
|
|
|
// Manipulate the interwiki prefix on-the-fly |
|
42
|
|
|
$GLOBALS['wgHooks']['InterwikiLoadPrefix'][] = function( $prefix, &$interwiki ) { |
|
43
|
|
|
|
|
44
|
|
|
if ( $prefix !== 'en' ) { |
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$interwiki = [ |
|
49
|
|
|
'iw_prefix' => 'en', |
|
50
|
|
|
'iw_url' => 'http://www.example.org/$1', |
|
51
|
|
|
'iw_api' => false, |
|
52
|
|
|
'iw_wikiid' => 'foo', |
|
53
|
|
|
'iw_local' => true, |
|
54
|
|
|
'iw_trans' => false, |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
return false; |
|
58
|
|
|
}; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function tearDown() : void { |
|
62
|
|
|
|
|
63
|
|
|
UtilityFactory::getInstance()->newPageDeleter()->doDeletePoolOfPages( $this->subjects ); |
|
64
|
|
|
unset( $GLOBALS['wgHooks']['InterwikiLoadPrefix'] ); |
|
65
|
|
|
|
|
66
|
|
|
parent::tearDown(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testUseInterlanguageLinkParserInPage() { |
|
70
|
|
|
|
|
71
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ ); |
|
72
|
|
|
|
|
73
|
|
|
$this->pageCreator |
|
74
|
|
|
->createPage( $subject->getTitle() ) |
|
75
|
|
|
->doEdit( '{{INTERLANGUAGELINK:en|Lorem ipsum}}' ); |
|
76
|
|
|
|
|
77
|
|
|
$expected = [ |
|
78
|
|
|
'propertyCount' => 3, |
|
79
|
|
|
'properties' => [ |
|
80
|
|
|
DIProperty::newFromUserLabel( '_SKEY' ), |
|
81
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_ILL_REF ), |
|
82
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_ILL_LANG ) |
|
83
|
|
|
], |
|
84
|
|
|
'propertyValues' => [ 'en', 'Lorem ipsum', __METHOD__ ] |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
|
88
|
|
|
$expected, |
|
89
|
|
|
$this->getStore()->getSemanticData( $subject )->findSubSemanticData( 'ill.en' ) |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$this->subjects = [ $subject ]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testInterlanguageLinkParserToUseRedirect() { |
|
96
|
|
|
|
|
97
|
|
|
$subject = DIWikiPage::newFromText( __METHOD__ ); |
|
98
|
|
|
|
|
99
|
|
|
$this->pageCreator |
|
100
|
|
|
->createPage( Title::newFromText( 'Sil-redirect' ) ) |
|
101
|
|
|
->doEdit( '{{INTERLANGUAGELINK:en|Sil-redirect}} {{INTERLANGUAGELINK:fr|Sil-redirect}}' ) |
|
102
|
|
|
->doMoveTo( Title::newFromText( 'Sil-redirect-2' ) ); |
|
103
|
|
|
|
|
104
|
|
|
$this->pageCreator |
|
105
|
|
|
->createPage( Title::newFromText( __METHOD__ ) ) |
|
106
|
|
|
->doEdit( '{{INTERLANGUAGELINK:ja|Sil-redirect}}' ); |
|
107
|
|
|
|
|
108
|
|
|
$expected = [ |
|
109
|
|
|
'propertyCount' => 3, |
|
110
|
|
|
'properties' => [ |
|
111
|
|
|
DIProperty::newFromUserLabel( '_SKEY' ), |
|
112
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_ILL_REF ), |
|
113
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_ILL_LANG ) |
|
114
|
|
|
], |
|
115
|
|
|
'propertyValues' => [ 'ja', 'Sil-redirect-2', __METHOD__ ] |
|
116
|
|
|
]; |
|
117
|
|
|
|
|
118
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
|
119
|
|
|
$expected, |
|
120
|
|
|
$this->getStore()->getSemanticData( $subject )->findSubSemanticData( 'ill.ja' ) |
|
121
|
|
|
); |
|
122
|
|
|
|
|
123
|
|
|
$this->subjects = [ $subject, 'Sil-redirect', 'Sil-redirect-2' ]; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function testUseInterwikiLanguageLinkInPage() { |
|
127
|
|
|
|
|
128
|
|
|
$subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
|
129
|
|
|
|
|
130
|
|
|
$this->pageCreator |
|
131
|
|
|
->createPage( $subject->getTitle() ) |
|
132
|
|
|
->doEdit( '[[en:Foo]]' ); |
|
133
|
|
|
|
|
134
|
|
|
$expected = [ |
|
135
|
|
|
'propertyCount' => 3, |
|
136
|
|
|
'properties' => [ |
|
137
|
|
|
DIProperty::newFromUserLabel( '_SKEY' ), |
|
138
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_IWL_REF ), |
|
139
|
|
|
DIProperty::newFromUserLabel( SIL_PROP_IWL_LANG ) |
|
140
|
|
|
], |
|
141
|
|
|
'propertyValues' => [ 'en', 'en:Foo', __METHOD__ ] |
|
142
|
|
|
]; |
|
143
|
|
|
|
|
144
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
|
145
|
|
|
$expected, |
|
146
|
|
|
$this->getStore()->getSemanticData( $subject )->findSubSemanticData( 'iwl.en' ) |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
$this->subjects = [ $subject ]; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function testUseInterlanguageListParserForTemplateInclusion() { |
|
153
|
|
|
|
|
154
|
|
|
$subject = Title::newFromText( 'InterlanguageList' ); |
|
155
|
|
|
$targetEn = Title::newFromText( 'InterlanguageListParserTargetEn' ); |
|
156
|
|
|
$targetJa = Title::newFromText( 'InterlanguageListParserTargetJa' ); |
|
157
|
|
|
$template = Title::newFromText( 'InterlanguageListTemplate', NS_TEMPLATE ); |
|
158
|
|
|
|
|
159
|
|
|
$this->pageCreator |
|
160
|
|
|
->createPage( $template ) |
|
161
|
|
|
->doEdit( '<includeonly>[[{{{target-link}}}|{{{lang-name}}}]]</includeonly>' ); |
|
162
|
|
|
|
|
163
|
|
|
$this->pageCreator |
|
164
|
|
|
->createPage( $targetEn ) |
|
165
|
|
|
->doEdit( '{{INTERLANGUAGELINK:en|Lorem ipsum}}' ); |
|
166
|
|
|
|
|
167
|
|
|
$this->pageCreator |
|
168
|
|
|
->createPage( $targetJa ) |
|
169
|
|
|
->doEdit( '{{interlanguagelink:ja|Lorem ipsum}}' ); |
|
170
|
|
|
|
|
171
|
|
|
$this->pageCreator |
|
172
|
|
|
->createPage( $subject ) |
|
173
|
|
|
->doEdit( '{{INTERLANGUAGELIST:Lorem ipsum|InterlanguageListTemplate}}' ); |
|
174
|
|
|
|
|
175
|
|
|
$text = $this->pageCreator->getEditInfo()->getOutput()->getText(); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertContains( |
|
178
|
|
|
'title="InterlanguageListParserTargetEn">English</a>', |
|
179
|
|
|
$text |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
$this->assertContains( |
|
183
|
|
|
'title="InterlanguageListParserTargetJa">日本語</a>', |
|
184
|
|
|
$text |
|
185
|
|
|
); |
|
186
|
|
|
|
|
187
|
|
|
$this->subjects = [ $template, $subject, $targetEn, $targetJa ]; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function testQuerySubjectsForWildcardPageContentLanguage() { |
|
191
|
|
|
|
|
192
|
|
|
$subject = Title::newFromText( 'InterlanguageLinkByAsk' ); |
|
193
|
|
|
$targetEn = Title::newFromText( 'InterlanguageLinkParserTargetEn' ); |
|
194
|
|
|
$targetJa = Title::newFromText( 'InterlanguageLinkParserTargetJa' ); |
|
195
|
|
|
|
|
196
|
|
|
$this->pageCreator |
|
197
|
|
|
->createPage( $targetEn ) |
|
198
|
|
|
->doEdit( '{{INTERLANGUAGELINK:en|Lorem ipsum}}' ); |
|
199
|
|
|
|
|
200
|
|
|
$this->pageCreator |
|
201
|
|
|
->createPage( $targetJa ) |
|
202
|
|
|
->doEdit( '{{INTERLANGUAGELINK:ja|Lorem ipsum}}' ); |
|
203
|
|
|
|
|
204
|
|
|
$this->pageCreator |
|
205
|
|
|
->createPage( $subject ) |
|
206
|
|
|
->doEdit( '{{#ask: [[Has interlanguage link.Page content language::+]] }}' ); |
|
207
|
|
|
|
|
208
|
|
|
$text = $this->pageCreator->getEditInfo()->getOutput()->getText(); |
|
209
|
|
|
|
|
210
|
|
|
$this->assertContains( |
|
211
|
|
|
'title="InterlanguageLinkParserTargetEn">InterlanguageLinkParserTargetEn</a>', |
|
212
|
|
|
$text |
|
213
|
|
|
); |
|
214
|
|
|
|
|
215
|
|
|
$this->assertContains( |
|
216
|
|
|
'title="InterlanguageLinkParserTargetJa">InterlanguageLinkParserTargetJa</a>', |
|
217
|
|
|
$text |
|
218
|
|
|
); |
|
219
|
|
|
|
|
220
|
|
|
$this->subjects = [ $subject, $targetEn, $targetJa ]; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function testQuerySubjectsForSpecificPageContentLanguage() { |
|
224
|
|
|
|
|
225
|
|
|
$subject = Title::newFromText( 'InterlanguageLinkByLanguage' ); |
|
226
|
|
|
$targetEn = Title::newFromText( 'InterlanguageLinkByLanguageParserTargetEn' ); |
|
227
|
|
|
$targetJa = Title::newFromText( 'InterlanguageLinkByLanguageParserTargetJa' ); |
|
228
|
|
|
|
|
229
|
|
|
$this->pageCreator |
|
230
|
|
|
->createPage( $targetEn ) |
|
231
|
|
|
->doEdit( '{{INTERLANGUAGELINK:en|Lorem ipsum}}' ); |
|
232
|
|
|
|
|
233
|
|
|
$this->pageCreator |
|
234
|
|
|
->createPage( $targetJa ) |
|
235
|
|
|
->doEdit( '{{INTERLANGUAGELINK:ja|Lorem ipsum}}' ); |
|
236
|
|
|
|
|
237
|
|
|
$this->pageCreator |
|
238
|
|
|
->createPage( $subject ) |
|
239
|
|
|
->doEdit( '{{#ask: [[Has interlanguage link.Page content language::en]] }}' ); |
|
240
|
|
|
|
|
241
|
|
|
$text = $this->pageCreator->getEditInfo()->getOutput()->getText(); |
|
242
|
|
|
|
|
243
|
|
|
$this->assertContains( |
|
244
|
|
|
'title="InterlanguageLinkByLanguageParserTargetEn">InterlanguageLinkByLanguageParserTargetEn</a>', |
|
245
|
|
|
$text |
|
246
|
|
|
); |
|
247
|
|
|
|
|
248
|
|
|
$this->assertNotContains( |
|
249
|
|
|
'title="InterlanguageLinkByLanguageParserTargetJa">InterlanguageLinkByLanguageParserTargetJa</a>', |
|
250
|
|
|
$text |
|
251
|
|
|
); |
|
252
|
|
|
|
|
253
|
|
|
$this->subjects = [ $subject, $targetEn, $targetJa ]; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
} |
|
257
|
|
|
|