1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL\Tests; |
4
|
|
|
|
5
|
|
|
use SIL\InterlanguageListParserFunction; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SIL\InterlanguageListParserFunction |
9
|
|
|
* @group semantic-interlanguage-links |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class InterlanguageListParserFunctionTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf( |
25
|
|
|
'\SIL\InterlanguageListParserFunction', |
26
|
|
|
new InterlanguageListParserFunction( |
27
|
|
|
$interlanguageLinksLookup |
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testTryParseThatCausesErrorMessage() { |
33
|
|
|
|
34
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$instance = new InterlanguageListParserFunction( |
39
|
|
|
$interlanguageLinksLookup |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$this->assertContains( |
43
|
|
|
'div class="smw-callout smw-callout-error"', |
44
|
|
|
$instance->parse( '', 'Foo' ) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$this->assertContains( |
48
|
|
|
'div class="smw-callout smw-callout-error"', |
49
|
|
|
$instance->parse( 'Foo', '' ) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->assertContains( |
53
|
|
|
'div class="smw-callout smw-callout-error"', |
54
|
|
|
$instance->parse( '{[[:Template:Foo]]', 'en' ) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testParseForEmptyLanguageTargetLinks() { |
59
|
|
|
|
60
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
61
|
|
|
->disableOriginalConstructor() |
62
|
|
|
->getMock(); |
63
|
|
|
|
64
|
|
|
$interlanguageLinksLookup->expects( $this->once() ) |
65
|
|
|
->method( 'queryLanguageTargetLinks' ) |
66
|
|
|
->will( $this->returnValue( [] ) ); |
67
|
|
|
|
68
|
|
|
$interlanguageLinksLookup->expects( $this->once() ) |
69
|
|
|
->method( 'getRedirectTargetFor' ) |
70
|
|
|
->will( $this->returnValue( 'Foo' ) ); |
71
|
|
|
|
72
|
|
|
$instance = new InterlanguageListParserFunction( |
73
|
|
|
$interlanguageLinksLookup |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->assertEquals( |
77
|
|
|
[ "", "noparse" => true, "isHTML" => false ], |
78
|
|
|
$instance->parse( 'Foo', 'FakeTemplate' ) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @dataProvider languageTargetLinksTemplateProvider |
84
|
|
|
*/ |
85
|
|
|
public function testParseForValidLanguageTargetLinks( $targetLink, $expected ) { |
86
|
|
|
|
87
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
88
|
|
|
->disableOriginalConstructor() |
89
|
|
|
->getMock(); |
90
|
|
|
|
91
|
|
|
$interlanguageLinksLookup->expects( $this->once() ) |
92
|
|
|
->method( 'queryLanguageTargetLinks' ) |
93
|
|
|
->will( $this->returnValue( $targetLink ) ); |
94
|
|
|
|
95
|
|
|
$interlanguageLinksLookup->expects( $this->once() ) |
96
|
|
|
->method( 'getRedirectTargetFor' ) |
97
|
|
|
->will( $this->returnValue( 'Foo' ) ); |
98
|
|
|
|
99
|
|
|
$instance = new InterlanguageListParserFunction( |
100
|
|
|
$interlanguageLinksLookup |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$this->assertEquals( |
104
|
|
|
[ $expected, "noparse" => false, "isHTML" => false ], |
105
|
|
|
$instance->parse( 'Foo', 'FakeTemplate' ) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function languageTargetLinksTemplateProvider() { |
110
|
|
|
|
111
|
|
|
$provider = []; |
112
|
|
|
|
113
|
|
|
$provider[] = [ |
114
|
|
|
[ 'en' => 'Test' ], |
115
|
|
|
'{{FakeTemplate' . |
116
|
|
|
'|#=0' . |
117
|
|
|
'|target-link=Test' . |
118
|
|
|
'|lang-code=en' . |
119
|
|
|
'|lang-name=English}}' |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$provider[] = [ |
123
|
|
|
[ 'ja' => \Title::newFromText( 'テスト' ) ], |
124
|
|
|
'{{FakeTemplate' . |
125
|
|
|
'|#=0' . |
126
|
|
|
'|target-link=テスト' . |
127
|
|
|
'|lang-code=ja' . |
128
|
|
|
'|lang-name=日本語}}' |
129
|
|
|
]; |
130
|
|
|
|
131
|
|
|
$provider[] = [ |
132
|
|
|
[ 'zh-hans' => \Title::newFromText( '分类:汉字' ) ], |
133
|
|
|
'{{FakeTemplate' . |
134
|
|
|
'|#=0' . |
135
|
|
|
'|target-link=分类:汉字' . |
136
|
|
|
'|lang-code=zh-Hans' . |
137
|
|
|
'|lang-name=中文(简体)}}' |
138
|
|
|
]; |
139
|
|
|
|
140
|
|
|
$categoryNS = $GLOBALS['wgContLang']->getNsText( NS_CATEGORY ); |
141
|
|
|
|
142
|
|
|
$provider[] = [ |
143
|
|
|
[ 'zh-hans' => \Title::newFromText( 'Category:汉字' ) ], |
144
|
|
|
'{{FakeTemplate' . |
145
|
|
|
'|#=0' . |
146
|
|
|
"|target-link=:$categoryNS:汉字" . |
147
|
|
|
'|lang-code=zh-Hans' . |
148
|
|
|
'|lang-name=中文(简体)}}' |
149
|
|
|
]; |
150
|
|
|
|
151
|
|
|
$provider[] = [ |
152
|
|
|
[ 'de' => 'Category:Foo' ], |
153
|
|
|
'{{FakeTemplate' . |
154
|
|
|
'|#=0' . |
155
|
|
|
"|target-link=:$categoryNS:Foo" . |
156
|
|
|
'|lang-code=de' . |
157
|
|
|
'|lang-name=Deutsch}}' |
158
|
|
|
]; |
159
|
|
|
|
160
|
|
|
return $provider; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|