Passed
Pull Request — master (#136)
by None
04:09
created

ReferenceListParserFunctionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 107
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SCI\Tests;
4
5
use SCI\ReferenceListParserFunction;
6
use SMW\DIWikiPage;
7
use SMW\Tests\PHPUnitCompat;
8
9
/**
10
 * @covers \SCI\ReferenceListParserFunction
11
 * @group semantic-cite
12
 *
13
 * @license GNU GPL v2+
14
 * @since   1.0
15
 *
16
 * @author mwjames
17
 */
18
class ReferenceListParserFunctionTest extends \PHPUnit_Framework_TestCase {
19
20
	use PHPUnitCompat;
21
22
	public function testCanConstruct() {
23
24
		$parserData = $this->getMockBuilder( '\SMW\ParserData' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$this->assertInstanceOf(
29
			'\SCI\ReferenceListParserFunction',
30
			new ReferenceListParserFunction( $parserData )
31
		);
32
	}
33
34
	/**
35
	 * @dataProvider parametersDataProvider
36
	 */
37
	public function testDoProcessForParameter( $parameters, $expected ) {
38
39
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
40
			->disableOriginalConstructor()
41
			->getMock();
42
43
		$parserData = $this->getMockBuilder( '\SMW\ParserData' )
44
			->disableOriginalConstructor()
45
			->getMock();
46
47
		$parserData->expects( $this->any() )
48
			->method( 'getSubject' )
49
			->will( $this->returnValue( new DIWikiPage( 'Foo', NS_MAIN ) ) );
50
51
		$parserData->expects( $this->any() )
52
			->method( 'getSemanticData' )
53
			->will( $this->returnValue( $semanticData ) );
54
55
		$parserParameterProcessor = $this->getMockBuilder( '\SMW\ParserParameterProcessor' )
56
			->disableOriginalConstructor()
57
			->getMock();
58
59
		$parserParameterProcessor->expects( $this->once() )
60
			->method( 'toArray' )
61
			->will( $this->returnValue( $parameters ) );
62
63
		$instance = new ReferenceListParserFunction( $parserData );
64
65
		$this->assertContains(
66
			$expected,
67
			$instance->doProcess( $parserParameterProcessor )
68
		);
69
	}
70
71
	public function testDoProcessForReferenceParameter() {
72
73
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
74
			->disableOriginalConstructor()
75
			->getMock();
76
77
		$parserData = $this->getMockBuilder( '\SMW\ParserData' )
78
			->disableOriginalConstructor()
79
			->getMock();
80
81
		$parserData->expects( $this->any() )
82
			->method( 'getSubject' )
83
			->will( $this->returnValue( new DIWikiPage( 'Foo', NS_MAIN ) ) );
84
85
		$parserData->expects( $this->once() )
86
			->method( 'pushSemanticDataToParserOutput' );
87
88
		$parserData->expects( $this->any() )
89
			->method( 'getSemanticData' )
90
			->will( $this->returnValue( $semanticData ) );
91
92
		$parserParameterProcessor = $this->getMockBuilder( '\SMW\ParserParameterProcessor' )
93
			->disableOriginalConstructor()
94
			->getMock();
95
96
		$parserParameterProcessor->expects( $this->once() )
97
			->method( 'toArray' )
98
			->will( $this->returnValue( [ 'references' => [ 'Foo', 42 ] ] ) );
99
100
		$instance = new ReferenceListParserFunction( $parserData );
101
		$instance->doProcess( $parserParameterProcessor );
102
	}
103
104
	public function parametersDataProvider() {
105
106
		$provider[] = [
107
			[],
108
			'span'
109
		];
110
111
		$provider[] = [
112
			[ 'toc' => [ true ] ],
113
			'h2'
114
		];
115
116
		$provider[] = [
117
			[ 'references' => [ 'Foo', 42 ] ],
118
			'data-references="[&quot;Foo&quot;,42]"'
119
		];
120
121
		return $provider;
122
	}
123
124
}
125