GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( 1f58dd...e46154 )
by
unknown
31:29
created

tests/phpunit/Unit/BasicBackendTest.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * This file is part of the MediaWiki extension Lingo.
4
 *
5
 * @copyright 2011 - 2017, Stephan Gambke
6
 * @license GPL-2.0-or-later
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
29
use Lingo\BasicBackend;
30
31
/**
32
 * @group extensions-lingo
33
 * @group extensions-lingo-unit
34
 * @group mediawiki-databaseless
35
 *
36
 * @coversDefaultClass \Lingo\BasicBackend
37
 * @covers ::<private>
38
 * @covers ::<protected>
39
 *
40
 * @ingroup Lingo
41
 * @ingroup Test
42
 */
43
class BasicBackendTest extends BackendTest {
44
45
	/**
46
	 * @covers ::__construct
47
	 */
48
	public function testCanConstruct() {
49
		$this->assertInstanceOf(
50
			'\Lingo\BasicBackend',
51
			new \Lingo\BasicBackend()
52
		);
53
	}
54
55
	/**
56
	 * @covers ::purgeCache
57
	 */
58
	public function testPurgeCache() {
59
		$GLOBALS[ 'wgexLingoPage' ] = 'SomePage';
60
61
		$title = $this->getMockBuilder( 'Title' )
62
			->getMock();
63
64
		$wikiPage = $this->getMockBuilder( 'WikiPage' )
65
			->disableOriginalConstructor()
66
			->getMock();
67
68
		$lingoParser = $this->getMockBuilder( 'Lingo\LingoParser' )
69
			->getMock();
70
71
		$testObject = $this->getMockBuilder( 'Lingo\BasicBackend' )
72
			->setMethods( [ 'getLingoParser' ] )
73
			->getMock();
74
75
		// Assert that the wikipage is tested against the wgexLingoPage, i.e.
76
		// that $wikipage->getTitle()->getText() === $page is tested
77
78
		$wikiPage->expects( $this->once() )
79
			->method( 'getTitle' )
80
			->willReturn( $title );
81
82
		$title->expects( $this->once() )
83
			->method( 'getText' )
84
			->willReturn( 'SomePage' );
85
86
		// Assert that purgeGlossaryFromCache is called
87
		$lingoParser->expects( $this->once() )
88
			->method( 'purgeGlossaryFromCache' );
89
90
		$testObject->expects( $this->once() )
91
			->method( 'getLingoParser' )
92
			->willReturn( $lingoParser );
93
94
		$this->assertTrue( $testObject->purgeCache( $wikiPage ) );
95
	}
96
97
	/**
98
	 * @covers ::useCache
99
	 */
100
	public function testUseCache() {
101
		$backend = new BasicBackend();
102
		$this->assertTrue( $backend->useCache() );
103
	}
104
105
	/**
106
	 * @covers ::next
107
	 * @dataProvider provideForTestNext
108
	 */
109
	public function testNext( $lingoPageText, $expectedResults ) {
110
		$backend = $this->getTestObject( $lingoPageText );
111
		foreach ( $expectedResults as $expected ) {
112
			$this->assertEquals( $expected, $backend->next() );
113
		}
114
	}
115
116
	public function testNext_LingoPageIsInterwiki() {
117
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', 'someInterwiki' );
118
		$backend->getMessageLog()->expects( $this->once() )
119
			->method( 'addError' )
120
			->willReturn( null );
121
122
		$this->assertNull( $backend->next() );
123
	}
124
125
	public function testNext_LingoPageWasJustEdited() {
126
		$backend = $this->getTestObject( ';SOT:Some old text', 'submit' );
127
		$this->assertEquals( [ 'JST', 'Just saved text', null, null ], $backend->next() );
128
	}
129
130
	public function testNext_LingoPageDoesNotExist() {
131
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', '', null, false );
132
		$backend->getMessageLog()->expects( $this->once() )
133
			->method( 'addWarning' )
134
			->willReturn( null );
135
136
		$this->assertEquals( null, $backend->next() );
137
	}
138
139
	public function testNext_LingoPageNotAccessible() {
140
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', '', false, null );
141
		$this->assertEquals( null, $backend->next() );
142
	}
143
144
	public function testNext_LingoPageIsNotATextPage() {
145
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', '', false, 'This is not a TextContent object' );
146
		$backend->getMessageLog()->expects( $this->once() )
147
			->method( 'addError' )
148
			->willReturn( null );
149
150
		$this->assertEquals( null, $backend->next() );
151
	}
152
153
	public function testNext_ApprovedRevsEnabledButNotInstalled() {
154
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', '', false, false, ';SAT:Some approved text' );
155
		$backend->getMessageLog()->expects( $this->once() )
156
			->method( 'addWarning' )
157
			->willReturn( null );
158
159
		$GLOBALS[ 'wgexLingoEnableApprovedRevs' ] = true;
160
161
		$this->assertEquals( [ 'SOT', 'Some old text', null, null ], $backend->next() );
162
	}
163
164
	public function testNext_ApprovedRevsEnabledAndInstalled() {
165
		$backend = $this->getTestObject( ';SOT:Some old text', 'view', '', false, false, ';SAT:Some approved text' );
166
167
		$GLOBALS[ 'wgexLingoEnableApprovedRevs' ] = true;
168
		define( 'APPROVED_REVS_VERSION', '42' );
169
170
		$this->assertEquals( [ 'SAT', 'Some approved text', null, null ], $backend->next() );
171
	}
172
173
	/**
174
	 * @return array
175
	 */
176
	public function provideForTestNext() {
177
		return [
178
179
			// Empty page
180
			[
181
				'',
182
				[ null ]
183
			],
184
185
			// Simple entries
186
			[
187
<<<'TESTTEXT'
188
;CIP:Common image point
189
;CMP:Common midpoint
190
TESTTEXT
191
			,
192
				[
193
					[ 'CMP', 'Common midpoint', null, null ],
194
					[ 'CIP', 'Common image point', null, null ],
195
				],
196
			],
197
198
			// Simple entries with line break
199
			[
200
<<<'TESTTEXT'
201
;CIP
202
:Common image point
203
;CMP
204
:Common midpoint
205
TESTTEXT
206
			,
207
				[
208
					[ 'CMP', 'Common midpoint', null, null ],
209
					[ 'CIP', 'Common image point', null, null ],
210
				],
211
			],
212
213
			// Two terms having the same definition
214
			[
215
<<<'TESTTEXT'
216
;CIP
217
;CMP
218
:Common midpoint
219
TESTTEXT
220
			,
221
				[
222
					[ 'CMP', 'Common midpoint', null, null ],
223
					[ 'CIP', 'Common midpoint', null, null ],
224
				],
225
			],
226
227
			// One term having two definitions
228
			[
229
<<<'TESTTEXT'
230
;CIP
231
:Common image point
232
:Common midpoint
233
TESTTEXT
234
			,
235
				[
236
					[ 'CIP', 'Common image point', null, null ],
237
					[ 'CIP', 'Common midpoint', null, null ],
238
				],
239
			],
240
241
			// Two terms sharing two definitions
242
			[
243
<<<'TESTTEXT'
244
;CIP
245
;CMP
246
:Common image point
247
:Common midpoint
248
TESTTEXT
249
			,
250
				[
251
					[ 'CMP', 'Common image point', null, null ],
252
					[ 'CMP', 'Common midpoint', null, null ],
253
					[ 'CIP', 'Common image point', null, null ],
254
					[ 'CIP', 'Common midpoint', null, null ],
255
				],
256
			],
257
258
			// Mixed entries and noise
259
			[
260
<<<'TESTTEXT'
261
;CIP:Common image point
262
; CMP : Common midpoint
263
264
;DIMO
265
;DMO
266
:Dip move-out
267
268
== headline ==
269
Sed ut perspiciatis unde; omnis iste natus error: sit voluptatem accusantium...
270
271
;NMO:Normal move-out
272
TESTTEXT
273
			,
274
				[
275
					[ 'NMO', 'Normal move-out', null, null ],
276
					[ 'DMO', 'Dip move-out', null, null ],
277
					[ 'DIMO', 'Dip move-out', null, null ],
278
					[ 'CMP', 'Common midpoint', null, null ],
279
					[ 'CIP', 'Common image point', null, null ],
280
				],
281
			],
282
283
		];
284
	}
285
286
	/**
287
	 * @return \PHPUnit_Framework_MockObject_MockObject
0 ignored issues
show
The type PHPUnit_Framework_MockObject_MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
288
	 */
289
	protected function getTestObject( $lingoPageText = '', $action = 'view', $interwiki = '', $lingoPageRevision = false, $lingoPageContent = false, $lingoApprovedText = '' ) {
290
		$messageLog = $this->getMockBuilder( 'Lingo\MessageLog' )
291
			->getMock();
292
293
		$backend = $this->getMockBuilder( 'Lingo\BasicBackend' )
294
			->disableOriginalConstructor()
295
			->setMethods( [
296
				'getLatestRevisionFromTitle',
297
				'getApprovedRevisionFromTitle',
298
				'getTitleFromText',
299
			] )
300
			->getMock();
301
302
		$reflected = new \ReflectionClass( '\Lingo\BasicBackend' );
303
		$constructor = $reflected->getConstructor();
304
		$constructor->invokeArgs( $backend, [ &$messageLog ] );
305
306
		$GLOBALS[ 'wgLingoPageName' ] = 'SomePage';
307
308
		$lingoPageTitle = $this->getMockBuilder( 'Title' )
309
			->getMock();
310
		$lingoPageTitle->expects( $this->once() )
311
			->method( 'getInterwiki' )
312
			->willReturn( $interwiki );
313
		$lingoPageTitle->expects( $this->any() )
314
			->method( 'getArticleID' )
315
			->willReturn( 'Foom' );
316
317
		$backend->expects( $this->any() )
318
			->method( 'getTitleFromText' )
319
			->willReturn( $lingoPageTitle );
320
321
		$request = $this->getMockBuilder( 'FauxRequest' )
322
			->getMock();
323
		$request->expects( $this->any() )
324
			->method( 'getVal' )
325
			->willReturnMap( [
326
				[ 'action', 'view', $action ], // action = submit
327
				[ 'title', null, $lingoPageTitle ], // title = $lingoPageTitle
328
				[ 'wpTextbox1', null, ';JST:Just saved text' ]
329
			] );
330
331
		$GLOBALS[ 'wgRequest' ] = $request;
332
333
		unset( $GLOBALS[ 'wgexLingoEnableApprovedRevs' ] );
334
335
		$backend->expects( $this->any() )
336
			->method( 'getLatestRevisionFromTitle' )
337
			->willReturn( $this->getRevisionMock( $lingoPageText, $lingoPageRevision, $lingoPageContent ) );
338
339
		$backend->expects( $this->any() )
340
			->method( 'getApprovedRevisionFromTitle' )
341
			->willReturn( $this->getRevisionMock( $lingoApprovedText ) );
342
343
		return $backend;
344
	}
345
346
	/**
347
	 * @param $lingoPageText
348
	 * @param $lingoPageRevision
349
	 * @param $lingoPageContent
350
	 * @return \PHPUnit_Framework_MockObject_MockObject
351
	 */
352
	protected function getRevisionMock( $lingoPageText, $lingoPageRevision = false, $lingoPageContent = false ) {
353
		if ( $lingoPageRevision === false ) {
354
355
			if ( $lingoPageContent === false ) {
356
				$lingoPageContent = $this->getMockBuilder( 'TextContent' )
357
					->disableOriginalConstructor()
358
					->getMock();
359
				$lingoPageContent->expects( $this->any() )
360
					->method( 'getText' )
361
					->willReturn( $lingoPageText );
362
			}
363
364
			$lingoPageRevision = $this->getMockBuilder( 'Revision' )
365
				->disableOriginalConstructor()
366
				->getMock();
367
			$lingoPageRevision->expects( $this->any() )
368
				->method( 'getContent' )
369
				->willReturn( $lingoPageContent );
370
			return $lingoPageRevision;
371
		}
372
		return $lingoPageRevision;
373
	}
374
375
}
376