|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SBL\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SBL\SubpageParentAnnotator; |
|
6
|
|
|
use SMW\DIWikiPage; |
|
7
|
|
|
use SMW\DIProperty; |
|
8
|
|
|
use Title; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \SBL\SubpageParentAnnotator |
|
12
|
|
|
* @group semantic-breadcrumb-links |
|
13
|
|
|
* |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
* |
|
17
|
|
|
* @author mwjames |
|
18
|
|
|
*/ |
|
19
|
|
|
class SubpageParentAnnotatorTest extends \PHPUnit_Framework_TestCase { |
|
20
|
|
|
|
|
21
|
|
|
private $parserData; |
|
22
|
|
|
private $parserOutput; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() { |
|
25
|
|
|
|
|
26
|
|
|
$title = Title::newFromText( 'Foo/Bar' ); |
|
27
|
|
|
|
|
28
|
|
|
$this->parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
|
29
|
|
|
->disableOriginalConstructor() |
|
30
|
|
|
->getMock(); |
|
31
|
|
|
|
|
32
|
|
|
$this->parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
33
|
|
|
->disableOriginalConstructor() |
|
34
|
|
|
->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$this->parserData->expects( $this->any() ) |
|
37
|
|
|
->method( 'getTitle' ) |
|
38
|
|
|
->will( $this->returnValue( $title ) ); |
|
39
|
|
|
|
|
40
|
|
|
$this->parserData->expects( $this->any() ) |
|
41
|
|
|
->method( 'getOutput' ) |
|
42
|
|
|
->will( $this->returnValue( $this->parserOutput ) ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testCanConstruct() { |
|
46
|
|
|
|
|
47
|
|
|
$this->assertInstanceOf( |
|
48
|
|
|
'\SBL\SubpageParentAnnotator', |
|
49
|
|
|
new SubpageParentAnnotator( $this->parserData ) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testAddAnnotation() { |
|
54
|
|
|
|
|
55
|
|
|
$property = DIProperty::newFromUserLabel( SBL_PROP_PARENTPAGE ); |
|
56
|
|
|
$subject = DIWikiPage::newFromText( 'Foo' ); |
|
57
|
|
|
|
|
58
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
59
|
|
|
->disableOriginalConstructor() |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
|
|
62
|
|
|
$semanticData->expects( $this->once() ) |
|
63
|
|
|
->method( 'getPropertyValues' ) |
|
64
|
|
|
->will( $this->returnValue( [] ) ); |
|
65
|
|
|
|
|
66
|
|
|
$semanticData->expects( $this->once() ) |
|
67
|
|
|
->method( 'addPropertyObjectValue' ) |
|
68
|
|
|
->with( |
|
69
|
|
|
$this->equalTo( $property ), |
|
70
|
|
|
$this->equalTo( $subject ) ); |
|
71
|
|
|
|
|
72
|
|
|
$this->parserData->expects( $this->atLeastOnce() ) |
|
73
|
|
|
->method( 'getSemanticData' ) |
|
74
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
75
|
|
|
|
|
76
|
|
|
$instance = new SubpageParentAnnotator( |
|
77
|
|
|
$this->parserData |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$instance->addAnnotation(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testDisabledAnnotationFunctionality() { |
|
84
|
|
|
|
|
85
|
|
|
$this->parserData->expects( $this->never() ) |
|
86
|
|
|
->method( 'getSemanticData' ); |
|
87
|
|
|
|
|
88
|
|
|
$instance = new SubpageParentAnnotator( |
|
89
|
|
|
$this->parserData |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
$instance->enableSubpageParentAnnotation( false ); |
|
93
|
|
|
$instance->addAnnotation(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testDisabledAnnotationFunctionalityDueToPreexisingValues() { |
|
97
|
|
|
|
|
98
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
99
|
|
|
->disableOriginalConstructor() |
|
100
|
|
|
->getMock(); |
|
101
|
|
|
|
|
102
|
|
|
$semanticData->expects( $this->once() ) |
|
103
|
|
|
->method( 'getPropertyValues' ) |
|
104
|
|
|
->will( $this->returnValue( [ 'Foo' ] ) ); |
|
105
|
|
|
|
|
106
|
|
|
$semanticData->expects( $this->never() ) |
|
107
|
|
|
->method( 'addPropertyObjectValue' ); |
|
108
|
|
|
|
|
109
|
|
|
$this->parserData->expects( $this->atLeastOnce() ) |
|
110
|
|
|
->method( 'getSemanticData' ) |
|
111
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
112
|
|
|
|
|
113
|
|
|
$instance = new SubpageParentAnnotator( |
|
114
|
|
|
$this->parserData |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
|
|
$instance->enableSubpageParentAnnotation( true ); |
|
118
|
|
|
$instance->addAnnotation(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function testNoAnnotationOnPagesWithSpaces() { |
|
122
|
|
|
|
|
123
|
|
|
$title = Title::newFromText( 'Foo / Bar' ); |
|
124
|
|
|
|
|
125
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
126
|
|
|
->disableOriginalConstructor() |
|
127
|
|
|
->getMock(); |
|
128
|
|
|
|
|
129
|
|
|
$parserData->expects( $this->any() ) |
|
130
|
|
|
->method( 'getTitle' ) |
|
131
|
|
|
->will( $this->returnValue( $title ) ); |
|
132
|
|
|
|
|
133
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
134
|
|
|
->disableOriginalConstructor() |
|
135
|
|
|
->getMock(); |
|
136
|
|
|
|
|
137
|
|
|
$semanticData->expects( $this->once() ) |
|
138
|
|
|
->method( 'getPropertyValues' ) |
|
139
|
|
|
->will( $this->returnValue( [] ) ); |
|
140
|
|
|
|
|
141
|
|
|
$semanticData->expects( $this->never() ) |
|
142
|
|
|
->method( 'addPropertyObjectValue' ); |
|
143
|
|
|
|
|
144
|
|
|
$parserData->expects( $this->atLeastOnce() ) |
|
145
|
|
|
->method( 'getSemanticData' ) |
|
146
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
147
|
|
|
|
|
148
|
|
|
$instance = new SubpageParentAnnotator( |
|
149
|
|
|
$parserData |
|
150
|
|
|
); |
|
151
|
|
|
|
|
152
|
|
|
$instance->enableSubpageParentAnnotation( true ); |
|
153
|
|
|
$instance->addAnnotation(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function testDisableTranslationSubpageAnnotation() { |
|
157
|
|
|
|
|
158
|
|
|
$this->parserOutput->expects( $this->once() ) |
|
159
|
|
|
->method( 'getExtensionData' ) |
|
160
|
|
|
->with( $this->equalTo( 'translate-translation-page' ) ) |
|
161
|
|
|
->will( $this->returnValue( true ) ); |
|
162
|
|
|
|
|
163
|
|
|
$instance = new SubpageParentAnnotator( |
|
164
|
|
|
$this->parserData |
|
165
|
|
|
); |
|
166
|
|
|
|
|
167
|
|
|
$instance->disableTranslationSubpageAnnotation( true ); |
|
168
|
|
|
$instance->addAnnotation(); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|