1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the MediaWiki extension Lingo. |
4
|
|
|
* |
5
|
|
|
* @copyright 2011 - 2018, 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
|
|
|
* @since 2.0.1 |
22
|
|
|
* @file |
23
|
|
|
* @ingroup Lingo |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace Lingo\Tests\Integration; |
27
|
|
|
|
28
|
|
|
use Lingo\LingoParser; |
29
|
|
|
use Lingo\Tests\Util\XmlFileProvider; |
30
|
|
|
|
31
|
|
|
use Parser; |
|
|
|
|
32
|
|
|
use ParserOptions; |
|
|
|
|
33
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
34
|
|
|
use ReflectionClass; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @group extensions-lingo |
38
|
|
|
* @group extensions-lingo-integration |
39
|
|
|
* @group mediawiki-databaseless |
40
|
|
|
* |
41
|
|
|
* @coversNothing |
42
|
|
|
* |
43
|
|
|
* @ingroup Lingo |
44
|
|
|
* @ingroup Test |
45
|
|
|
* @since 2.0.1 |
46
|
|
|
* @author Stephan Gambke |
47
|
|
|
*/ |
48
|
|
|
class ArticleAnnotationTest extends TestCase { |
49
|
|
|
|
50
|
|
|
public function setUp() { |
51
|
|
|
$GLOBALS[ 'wgexLingoDisplayOnce' ] = false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function tearDown() { |
55
|
|
|
// reset LingoParser singleton |
56
|
|
|
$lingoParser = LingoParser::getInstance(); |
57
|
|
|
$reflection = new ReflectionClass( $lingoParser ); |
58
|
|
|
$instance = $reflection->getProperty( 'parserSingleton' ); |
59
|
|
|
$instance->setAccessible( true ); |
60
|
|
|
$instance->setValue( null, null ); |
61
|
|
|
$instance->setAccessible( false ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider provideData |
66
|
|
|
* @param $text |
67
|
|
|
* @param $glossaryEntries |
68
|
|
|
* @param $expected |
69
|
|
|
* |
70
|
|
|
* Tests fail when run via MediaWiki extensions testsuite T196456 |
71
|
|
|
* @group Broken |
72
|
|
|
*/ |
73
|
|
|
public function testArticleAnnotation( $file = null, $text = '', $glossaryEntries = null, $expected = '' ) { |
74
|
|
|
$parser = new Parser(); |
75
|
|
|
$parser->parse( $text, \Title::newFromText( 'Foo' ), new ParserOptions() ); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$backend = $this->getMockForAbstractClass( '\Lingo\Backend' ); |
78
|
|
|
$backend->expects( $this->any() ) |
79
|
|
|
->method( 'next' ) |
80
|
|
|
->will( self::onConsecutiveCalls( ...$glossaryEntries ) ); |
81
|
|
|
|
82
|
|
|
$lingoParser = LingoParser::getInstance(); |
83
|
|
|
$lingoParser->setBackend( $backend ); |
84
|
|
|
|
85
|
|
|
$lingoParser->parse( $parser ); |
86
|
|
|
|
87
|
|
|
$this->assertEquals( trim( $expected ), trim( $parser->getOutput()->getText() ) ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function provideData() { |
91
|
|
|
$data = []; |
92
|
|
|
|
93
|
|
|
$xmlFileProvider = new XmlFileProvider( __DIR__ . '/../Fixture/articleAnnotation' ); |
94
|
|
|
$files = $xmlFileProvider->getFiles(); |
95
|
|
|
|
96
|
|
|
foreach ( $files as $file ) { |
97
|
|
|
|
98
|
|
|
$xml = simplexml_load_file( $file, "SimpleXMLElement", LIBXML_NOCDATA ); |
|
|
|
|
99
|
|
|
$json = json_encode( $xml ); |
100
|
|
|
$decoded = json_decode( $json, true ); |
101
|
|
|
|
102
|
|
|
// suppress warnings for non-existant array keys |
103
|
|
|
\Wikimedia\suppressWarnings(); |
|
|
|
|
104
|
|
|
|
105
|
|
|
$testCase = [ |
106
|
|
|
0 => substr( $file, strlen( __DIR__ . '/../Fixture/articleAnnotation' ) ), |
107
|
|
|
1 => trim( $decoded[ 'text' ] ), |
108
|
|
|
2 => [], |
109
|
|
|
3 => trim( $decoded[ 'expected' ] ) . "\n", |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
if ( array_key_exists( 'term', $decoded[ 'glossary-entry' ] ) ) { |
113
|
|
|
$decoded[ 'glossary-entry' ] = [ $decoded[ 'glossary-entry' ] ]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
foreach ( $decoded[ 'glossary-entry' ] as $entry ) { |
117
|
|
|
$testCase[ 2 ][] = [ $entry[ 'term' ], $entry[ 'definition' ], $entry[ 'link' ], $entry[ 'style' ] ]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
\Wikimedia\restoreWarnings(); |
|
|
|
|
121
|
|
|
|
122
|
|
|
$data[] = $testCase; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $data; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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