Test Setup Failed
Push — master ( 1f58dd...e46154 )
by
unknown
31:29
created

phpunit/Integration/ArticleAnnotationTest.php (1 issue)

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
35
use PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls;
36
use ReflectionClass;
37
38
/**
39
 * @group extensions-lingo
40
 * @group extensions-lingo-integration
41
 * @group mediawiki-databaseless
42
 *
43
 * @coversNothing
44
 *
45
 * @ingroup Lingo
46
 * @ingroup Test
47
 * @since 2.0.1
48
 * @author Stephan Gambke
49
 */
50
class ArticleAnnotationTest extends TestCase {
51
52
	public function setup() {
53
		$GLOBALS[ 'wgexLingoDisplayOnce' ] = false;
54
	}
55
56
	public function tearDown() {
57
		// reset LingoParser singleton
58
		$lingoParser = LingoParser::getInstance();
59
		$reflection = new ReflectionClass( $lingoParser );
60
		$instance = $reflection->getProperty( 'parserSingleton' );
61
		$instance->setAccessible( true );
62
		$instance->setValue( null, null );
63
		$instance->setAccessible( false );
64
	}
65
66
	/**
67
	 * @dataProvider provideData
68
	 * @param $text
69
	 * @param $glossaryEntries
70
	 * @param $expected
71
	 *
72
	 * Tests fail when run via MediaWiki extensions testsuite T196456
73
	 * @group Broken
74
	 */
75
	public function testArticleAnnotation( $file = null, $text = '', $glossaryEntries = null, $expected = '' ) {
76
		$parser = new Parser();
77
		$parser->parse( $text, \Title::newFromText( 'Foo' ), new ParserOptions() );
78
79
		$backend = $this->getMockForAbstractClass( '\Lingo\Backend' );
80
		$backend->expects( $this->any() )
81
			->method( 'next' )
82
			->will( new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $glossaryEntries ) );
83
84
		$lingoParser = LingoParser::getInstance();
85
		$lingoParser->setBackend( $backend );
86
87
		$lingoParser->parse( $parser );
88
89
		$this->assertEquals( trim( $expected ), trim( $parser->getOutput()->getText() ) );
90
	}
91
92
	public function provideData() {
93
		$data = [];
94
95
		$xmlFileProvider = new XmlFileProvider( __DIR__ . '/../Fixture/articleAnnotation' );
96
		$files = $xmlFileProvider->getFiles();
97
98
		foreach ( $files as $file ) {
99
100
			$xml = simplexml_load_file( $file, "SimpleXMLElement", LIBXML_NOCDATA );
101
			$json = json_encode( $xml );
102
			$decoded = json_decode( $json, true );
103
104
			// suppress warnings for non-existant array keys
105
			\Wikimedia\suppressWarnings();
0 ignored issues
show
The function suppressWarnings was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
			/** @scrutinizer ignore-call */ 
106
   \Wikimedia\suppressWarnings();
Loading history...
106
107
			$testCase = [
108
				0 => substr( $file, strlen( __DIR__ . '/../Fixture/articleAnnotation' ) ),
109
				1 => trim( $decoded[ 'text' ] ),
110
				2 => [],
111
				3 => trim( $decoded[ 'expected' ] ) . "\n",
112
			];
113
114
			if ( array_key_exists( 'term', $decoded[ 'glossary-entry' ] ) ) {
115
				$decoded[ 'glossary-entry' ] = [ $decoded[ 'glossary-entry' ] ];
116
			}
117
118
			foreach ( $decoded[ 'glossary-entry' ] as $entry ) {
119
				$testCase[ 2 ][] = [ $entry[ 'term' ], $entry[ 'definition' ], $entry[ 'link' ], $entry[ 'style' ] ];
120
			}
121
122
			\Wikimedia\restoreWarnings();
123
124
			$data[] = $testCase;
125
		}
126
127
		return $data;
128
	}
129
}
130