1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the MediaWiki extension Lingo. |
4
|
|
|
* |
5
|
|
|
* @copyright 2011 - 2018, Stephan Gambke |
6
|
|
|
* @license GNU General Public License, version 2 (or any later version) |
7
|
|
|
* |
8
|
|
|
* The Lingo extension is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by the Free |
10
|
|
|
* Software Foundation; either version 2 of the License, or (at your option) any |
11
|
|
|
* later version. |
12
|
|
|
* |
13
|
|
|
* The Lingo extension is distributed in the hope that it will be useful, but |
14
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
15
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
16
|
|
|
* details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License along |
19
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
* @author Stephan Gambke |
22
|
|
|
* @since 2.0 |
23
|
|
|
* @file |
24
|
|
|
* @ingroup Lingo |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace Lingo\Tests\Unit; |
28
|
|
|
use Lingo\LingoParser; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @group extensions-lingo |
32
|
|
|
* @group extensions-lingo-unit |
33
|
|
|
* @group mediawiki-databaseless |
34
|
|
|
* |
35
|
|
|
* @coversDefaultClass \Lingo\LingoParser |
36
|
|
|
* |
37
|
|
|
* @ingroup Lingo |
38
|
|
|
* @ingroup Test |
39
|
|
|
*/ |
40
|
|
|
class LingoParserTest extends \PHPUnit\Framework\TestCase { |
|
|
|
|
41
|
|
|
|
42
|
|
|
private static $defaultParserConfig = [ |
43
|
|
|
'mwParserExpectsGetOutput' => null, |
44
|
|
|
'mwParserExpectsGetTitle' => null, |
45
|
|
|
'mwTitleExpectsGetNamespace' => null, |
46
|
|
|
'mwOutputExpectsGetText' => null, |
47
|
|
|
|
48
|
|
|
'mwParserProperties' => [], |
49
|
|
|
|
50
|
|
|
'namespace' => 0, |
51
|
|
|
'text' => null, |
52
|
|
|
|
53
|
|
|
'wgexLingoUseNamespaces' => [], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @covers ::__construct |
58
|
|
|
*/ |
59
|
|
|
public function testCanConstruct() { |
60
|
|
|
$this->assertInstanceOf( |
61
|
|
|
'\Lingo\LingoParser', |
62
|
|
|
new \Lingo\LingoParser() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Tests |
68
|
|
|
* |
69
|
|
|
* |
70
|
|
|
* @dataProvider parseProvider |
71
|
|
|
*/ |
72
|
|
|
public function testParse( $config ) { |
73
|
|
|
|
74
|
|
|
// Setup |
75
|
|
|
$mwParser = $this->getParserMock( $config ); |
76
|
|
|
$parser = new LingoParser(); |
77
|
|
|
|
78
|
|
|
// Run |
79
|
|
|
$ret = $parser->parse( $mwParser ); |
80
|
|
|
|
81
|
|
|
// Check |
82
|
|
|
$this->assertTrue( $ret ); |
83
|
|
|
|
84
|
|
|
// Teardown |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function parseProvider() { |
91
|
|
|
return [ |
92
|
|
|
// trivial case where $wgParser being unset should at least not raise any exceptions |
93
|
|
|
[ [ 'mwParser' => null ] ], |
94
|
|
|
|
95
|
|
|
// Lingo parser does not start parsing (i.e. accesses parser output) when __NOGLOSSARY__ is set |
96
|
|
|
[ [ |
97
|
|
|
'mwParserExpectsGetOutput' => $this->never(), |
98
|
|
|
'mwParserProperties' => [ 'mDoubleUnderscores' => [ 'noglossary' => true ] ], |
99
|
|
|
] ], |
100
|
|
|
|
101
|
|
|
// Lingo parser does not start parsing (i.e. accesses parser output) when parsed Page is unknown |
102
|
|
|
[ [ |
103
|
|
|
'mwParserExpectsGetOutput' => $this->never(), |
104
|
|
|
'mwTitle' => null |
105
|
|
|
] ], |
106
|
|
|
|
107
|
|
|
// Lingo parser does not start parsing (i.e. accesses parser output) when parsed Page is in explicitly forbidden namespace |
108
|
|
|
[ [ |
109
|
|
|
'mwParserExpectsGetOutput' => $this->never(), |
110
|
|
|
'namespace' => 100, |
111
|
|
|
'wgexLingoUseNamespaces' => [ 100 => false ], |
112
|
|
|
] ], |
113
|
|
|
|
114
|
|
|
// Lingo parser starts parsing (i.e. accesses parser output) when parsed Page is in explicitly allowed namespace |
115
|
|
|
[ [ |
116
|
|
|
'mwParserExpectsGetOutput' => $this->once(), |
117
|
|
|
'namespace' => 100, |
118
|
|
|
'wgexLingoUseNamespaces' => [ 100 => true ], |
119
|
|
|
] ], |
120
|
|
|
|
121
|
|
|
// Lingo parser starts parsing (i.e. accesses parser output) when parsed Page is not in explicitly forbidden namespace |
122
|
|
|
[ [ |
123
|
|
|
'mwParserExpectsGetOutput' => $this->once(), |
124
|
|
|
'namespace' => 100, |
125
|
|
|
'wgexLingoUseNamespaces' => [ 101 => false ], |
126
|
|
|
] ], |
127
|
|
|
|
128
|
|
|
// parser output returns null text |
129
|
|
|
// TODO |
130
|
|
|
[ [ |
131
|
|
|
|
132
|
|
|
] ], |
133
|
|
|
|
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
|
|
|
139
|
|
|
*/ |
140
|
|
|
protected function getParserMock( $config = [] ) { |
141
|
|
|
|
142
|
|
|
$config += self::$defaultParserConfig; |
143
|
|
|
|
144
|
|
|
if ( array_key_exists( 'mwParser', $config ) ) { |
145
|
|
|
return $config[ 'mwParser' ]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$mwTitle = $this->getTitleMock( $config ); |
149
|
|
|
|
150
|
|
|
$mwParserOutput = $this->getMockBuilder( '\ParserOutput' ) |
151
|
|
|
->disableOriginalConstructor() |
152
|
|
|
->getMock(); |
153
|
|
|
|
154
|
|
|
$mwParser = $this->getMockBuilder( '\Parser' ) |
155
|
|
|
->disableOriginalConstructor() |
156
|
|
|
->getMock(); |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
$mwParserOutput->expects( $config[ 'mwOutputExpectsGetText' ]?:$this->any() ) |
160
|
|
|
->method( 'getText' ) |
161
|
|
|
->willReturn( $config[ 'text' ] ); |
162
|
|
|
|
163
|
|
|
$mwParser->expects( $config[ 'mwParserExpectsGetTitle' ]?:$this->any() ) |
164
|
|
|
->method( 'getTitle' ) |
165
|
|
|
->willReturn( $mwTitle ); |
166
|
|
|
|
167
|
|
|
$mwParser->expects( $config[ 'mwParserExpectsGetOutput' ]?:$this->any() ) |
168
|
|
|
->method( 'getOutput' ) |
169
|
|
|
->willReturn( $mwParserOutput ); |
170
|
|
|
|
171
|
|
|
foreach ( $config[ 'mwParserProperties' ] as $propName => $propValue ) { |
172
|
|
|
$mwParser->$propName = $propValue; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$GLOBALS[ 'wgexLingoUseNamespaces' ] = $config[ 'wgexLingoUseNamespaces' ]; |
176
|
|
|
|
177
|
|
|
return $mwParser; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param $config |
182
|
|
|
* |
183
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
184
|
|
|
*/ |
185
|
|
|
protected function getTitleMock( $config ) { |
186
|
|
|
|
187
|
|
|
if ( array_key_exists( 'mwTitle', $config ) ) { |
188
|
|
|
return $config[ 'mwTitle' ]; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$mwTitle = $this->getMockBuilder( '\Title' ) |
192
|
|
|
->disableOriginalConstructor() |
193
|
|
|
->getMock(); |
194
|
|
|
|
195
|
|
|
$mwTitle->expects( $config[ 'mwTitleExpectsGetNamespace' ] ?: $this->any() ) |
196
|
|
|
->method( 'getNamespace' ) |
197
|
|
|
->willReturn( $config[ 'namespace' ] ); |
198
|
|
|
|
199
|
|
|
return $mwTitle; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths