|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SCI\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SCI\SciteParserFunction; |
|
6
|
|
|
use SMW\DIWikiPage; |
|
7
|
|
|
use SMW\Tests\PHPUnitCompat; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \SCI\SciteParserFunction |
|
11
|
|
|
* @group semantic-cite |
|
12
|
|
|
* |
|
13
|
|
|
* @license GNU GPL v2+ |
|
14
|
|
|
* @since 1.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @author mwjames |
|
17
|
|
|
*/ |
|
18
|
|
|
class SciteParserFunctionTest extends \PHPUnit_Framework_TestCase { |
|
19
|
|
|
|
|
20
|
|
|
use PHPUnitCompat; |
|
21
|
|
|
|
|
22
|
|
|
private $parserData; |
|
23
|
|
|
private $namespaceExaminer; |
|
24
|
|
|
private $citationTextTemplateRenderer; |
|
25
|
|
|
private $mediaWikiNsContentMapper; |
|
26
|
|
|
private $bibtexProcessor; |
|
27
|
|
|
|
|
28
|
|
|
protected function setUp() : void { |
|
29
|
|
|
|
|
30
|
|
|
$this->parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
31
|
|
|
->disableOriginalConstructor() |
|
32
|
|
|
->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$this->parserData->expects( $this->any() ) |
|
35
|
|
|
->method( 'getSubject' ) |
|
36
|
|
|
->will( $this->returnValue( DIWikiPage::newFromText( __METHOD__ ) ) ); |
|
37
|
|
|
|
|
38
|
|
|
$this->namespaceExaminer = $this->getMockBuilder( '\SMW\NamespaceExaminer' ) |
|
39
|
|
|
->disableOriginalConstructor() |
|
40
|
|
|
->getMock(); |
|
41
|
|
|
|
|
42
|
|
|
$this->citationTextTemplateRenderer = $this->getMockBuilder( '\SCI\CitationTextTemplateRenderer' ) |
|
43
|
|
|
->disableOriginalConstructor() |
|
44
|
|
|
->getMock(); |
|
45
|
|
|
|
|
46
|
|
|
$this->mediaWikiNsContentMapper = $this->getMockBuilder( '\SCI\MediaWikiNsContentMapper' ) |
|
47
|
|
|
->disableOriginalConstructor() |
|
48
|
|
|
->getMock(); |
|
49
|
|
|
|
|
50
|
|
|
$this->bibtexProcessor = $this->getMockBuilder( '\SCI\Bibtex\BibtexProcessor' ) |
|
51
|
|
|
->disableOriginalConstructor() |
|
52
|
|
|
->getMock(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testCanConstruct() { |
|
56
|
|
|
|
|
57
|
|
|
$instance = new SciteParserFunction( |
|
58
|
|
|
$this->parserData, |
|
59
|
|
|
$this->namespaceExaminer, |
|
60
|
|
|
$this->citationTextTemplateRenderer, |
|
61
|
|
|
$this->mediaWikiNsContentMapper, |
|
62
|
|
|
$this->bibtexProcessor |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertInstanceOf( |
|
66
|
|
|
'\SCI\SciteParserFunction', |
|
67
|
|
|
$instance |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testErrorForNotEnabledNamespace() { |
|
72
|
|
|
|
|
73
|
|
|
$this->parserData->expects( $this->once() ) |
|
74
|
|
|
->method( 'getTitle' ) |
|
75
|
|
|
->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) ); |
|
76
|
|
|
|
|
77
|
|
|
$this->namespaceExaminer->expects( $this->once() ) |
|
78
|
|
|
->method( 'isSemanticEnabled' ) |
|
79
|
|
|
->will( $this->returnValue( false ) ); |
|
80
|
|
|
|
|
81
|
|
|
$parserParameterProcessor = $this->getMockBuilder( '\SMW\ParserParameterProcessor' ) |
|
82
|
|
|
->disableOriginalConstructor() |
|
83
|
|
|
->getMock(); |
|
84
|
|
|
|
|
85
|
|
|
$instance = new SciteParserFunction( |
|
86
|
|
|
$this->parserData, |
|
87
|
|
|
$this->namespaceExaminer, |
|
88
|
|
|
$this->citationTextTemplateRenderer, |
|
89
|
|
|
$this->mediaWikiNsContentMapper, |
|
90
|
|
|
$this->bibtexProcessor |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertInternalType( |
|
94
|
|
|
'string', |
|
95
|
|
|
$instance->doProcess( $parserParameterProcessor ) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testErrorForEnabledNamespaceButMissingReference() { |
|
100
|
|
|
|
|
101
|
|
|
$this->parserData->expects( $this->once() ) |
|
102
|
|
|
->method( 'getTitle' ) |
|
103
|
|
|
->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) ); |
|
104
|
|
|
|
|
105
|
|
|
$this->namespaceExaminer->expects( $this->once() ) |
|
106
|
|
|
->method( 'isSemanticEnabled' ) |
|
107
|
|
|
->will( $this->returnValue( true ) ); |
|
108
|
|
|
|
|
109
|
|
|
$parserParameterProcessor = $this->getMockBuilder( '\SMW\ParserParameterProcessor' ) |
|
110
|
|
|
->disableOriginalConstructor() |
|
111
|
|
|
->getMock(); |
|
112
|
|
|
|
|
113
|
|
|
$instance = new SciteParserFunction( |
|
114
|
|
|
$this->parserData, |
|
115
|
|
|
$this->namespaceExaminer, |
|
116
|
|
|
$this->citationTextTemplateRenderer, |
|
117
|
|
|
$this->mediaWikiNsContentMapper, |
|
118
|
|
|
$this->bibtexProcessor |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertInternalType( |
|
122
|
|
|
'string', |
|
123
|
|
|
$instance->doProcess( $parserParameterProcessor ) |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function testErrorForEnabledNamespaceButMissingType() { |
|
128
|
|
|
|
|
129
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
130
|
|
|
->disableOriginalConstructor() |
|
131
|
|
|
->getMock(); |
|
132
|
|
|
|
|
133
|
|
|
$this->parserData->expects( $this->any() ) |
|
134
|
|
|
->method( 'getTitle' ) |
|
135
|
|
|
->will( $this->returnValue( \Title::newFromText( __METHOD__ ) ) ); |
|
136
|
|
|
|
|
137
|
|
|
$this->parserData->expects( $this->any() ) |
|
138
|
|
|
->method( 'getSemanticData' ) |
|
139
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
140
|
|
|
|
|
141
|
|
|
$this->namespaceExaminer->expects( $this->once() ) |
|
142
|
|
|
->method( 'isSemanticEnabled' ) |
|
143
|
|
|
->will( $this->returnValue( true ) ); |
|
144
|
|
|
|
|
145
|
|
|
$parserParameterProcessor = $this->getMockBuilder( '\SMW\ParserParameterProcessor' ) |
|
146
|
|
|
->disableOriginalConstructor() |
|
147
|
|
|
->getMock(); |
|
148
|
|
|
|
|
149
|
|
|
$parserParameterProcessor->expects( $this->any() ) |
|
150
|
|
|
->method( 'hasParameter' ) |
|
151
|
|
|
->will( $this->returnCallback( function( $key ) { |
|
152
|
|
|
return $key === 'reference' ? true : false; } ) ); |
|
153
|
|
|
|
|
154
|
|
|
$parserParameterProcessor->expects( $this->any() ) |
|
155
|
|
|
->method( 'getParameterValuesFor' ) |
|
156
|
|
|
->will( $this->returnCallback( function( $key ) { |
|
157
|
|
|
return $key === 'reference' ? [ 'Foo' ] : null; } ) ); |
|
158
|
|
|
|
|
159
|
|
|
$parserParameterProcessor->expects( $this->once() ) |
|
160
|
|
|
->method( 'toArray' ) |
|
161
|
|
|
->will( $this->returnValue( [ '_ERRP' => [ 'Foo' ] ] ) ); |
|
162
|
|
|
|
|
163
|
|
|
$instance = new SciteParserFunction( |
|
164
|
|
|
$this->parserData, |
|
165
|
|
|
$this->namespaceExaminer, |
|
166
|
|
|
$this->citationTextTemplateRenderer, |
|
167
|
|
|
$this->mediaWikiNsContentMapper, |
|
168
|
|
|
$this->bibtexProcessor |
|
169
|
|
|
); |
|
170
|
|
|
|
|
171
|
|
|
$instance->setStrictParserValidationState( true ); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertInternalType( |
|
174
|
|
|
'string', |
|
175
|
|
|
$instance->doProcess( $parserParameterProcessor ) |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
|