Passed
Branch master (631cc3)
by Stephan
33:03
created

ArticleAnnotationTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 82
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
B provideData() 0 37 4
A setup() 0 3 1
A testArticleAnnotation() 0 18 1
A tearDown() 0 8 1
1
<?php
2
/**
3
 * This file is part of the MediaWiki extension Lingo.
4
 *
5
 * @copyright 2011 - 2016, 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
 * @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;
0 ignored issues
show
Bug introduced by
The type Parser 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...
32
use ParserOptions;
0 ignored issues
show
Bug introduced by
The type ParserOptions 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...
33
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase 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...
34
35
use PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls;
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls 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...
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
54
		$GLOBALS[ 'wgexLingoDisplayOnce' ] = false;
55
56
	}
57
58
	public function tearDown() {
59
		// reset LingoParser singleton
60
		$lingoParser = LingoParser::getInstance();
61
		$reflection = new ReflectionClass( $lingoParser );
62
		$instance = $reflection->getProperty( 'parserSingleton' );
63
		$instance->setAccessible( true );
64
		$instance->setValue( null, null );
65
		$instance->setAccessible( false );
66
	}
67
68
	/**
69
	 * @dataProvider provideData
70
	 * @param $text
71
	 * @param $glossaryEntries
72
	 * @param $expected
73
	 */
74
	public function testArticleAnnotation( $file = null, $text = '', $glossaryEntries = null, $expected = '' ) {
75
76
		$parser = new Parser();
77
		$parser->parse( $text, \Title::newFromText( 'Foo' ), new ParserOptions() );
0 ignored issues
show
Bug introduced by
The type Title 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...
78
		$GLOBALS[ 'wgParser' ] = $parser;
79
80
		$backend = $this->getMockForAbstractClass( '\Lingo\Backend' );
81
		$backend->expects( $this->any() )
82
			->method( 'next' )
83
			->will( new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $glossaryEntries ) );
84
85
86
		$lingoParser = LingoParser::getInstance();
87
		$lingoParser->setBackend( $backend );
88
89
		$lingoParser->parse();
90
91
		$this->assertEquals( trim( $expected ), trim( $parser->getOutput()->getText() ) );
92
93
	}
94
95
	public function provideData() {
96
97
		$data = [];
98
99
		$xmlFileProvider = new XmlFileProvider( __DIR__ . '/../Fixture/articleAnnotation' );
100
		$files = $xmlFileProvider->getFiles();
101
102
		foreach ( $files as $file ) {
103
104
			$xml = simplexml_load_file( $file, "SimpleXMLElement", LIBXML_NOCDATA );
105
			$json = json_encode( $xml );
106
			$decoded = json_decode( $json, TRUE );
107
108
			// suppress warnings for non-existant array keys
109
			\MediaWiki\suppressWarnings();
0 ignored issues
show
Bug introduced by
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

109
			/** @scrutinizer ignore-call */ 
110
   \MediaWiki\suppressWarnings();
Loading history...
110
111
			$testCase = [
112
				0 => substr( $file, strlen( __DIR__ . '/../Fixture/articleAnnotation' ) ),
113
				1 => trim( $decoded[ 'text' ] ),
114
				2 => [],
115
				3 => trim( $decoded[ 'expected' ] ) . "\n",
116
			];
117
118
			if ( array_key_exists( 'term', $decoded[ 'glossary-entry' ] ) ) {
119
				$decoded[ 'glossary-entry' ] = [ $decoded[ 'glossary-entry' ] ];
120
			}
121
122
			foreach ( $decoded[ 'glossary-entry' ] as $entry ) {
123
				$testCase[ 2 ][] = [ $entry[ 'term' ], $entry[ 'definition' ], $entry[ 'link' ], $entry[ 'style' ] ];
124
			}
125
126
			\MediaWiki\restoreWarnings();
0 ignored issues
show
Bug introduced by
The function restoreWarnings 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

126
			/** @scrutinizer ignore-call */ 
127
   \MediaWiki\restoreWarnings();
Loading history...
127
128
			$data[] = $testCase;
129
		}
130
131
		return $data;
132
	}
133
}
134