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
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
|
25
|
|
|
$title = Title::newFromText( 'Foo/Bar' ); |
26
|
|
|
|
27
|
|
|
$this->parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
$this->parserData->expects( $this->any() ) |
32
|
|
|
->method( 'getTitle' ) |
33
|
|
|
->will( $this->returnValue( $title ) ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCanConstruct() { |
37
|
|
|
|
38
|
|
|
$this->assertInstanceOf( |
39
|
|
|
'\SBL\SubpageParentAnnotator', |
40
|
|
|
new SubpageParentAnnotator( $this->parserData ) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testAddAnnotation() { |
45
|
|
|
|
46
|
|
|
$property = DIProperty::newFromUserLabel( SBL_PROP_PARENTPAGE ); |
47
|
|
|
$subject = DIWikiPage::newFromText( 'Foo' ); |
48
|
|
|
|
49
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
50
|
|
|
->disableOriginalConstructor() |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$semanticData->expects( $this->once() ) |
54
|
|
|
->method( 'getPropertyValues' ) |
55
|
|
|
->will( $this->returnValue( [] ) ); |
56
|
|
|
|
57
|
|
|
$semanticData->expects( $this->once() ) |
58
|
|
|
->method( 'addPropertyObjectValue' ) |
59
|
|
|
->with( |
60
|
|
|
$this->equalTo( $property ), |
61
|
|
|
$this->equalTo( $subject ) ); |
62
|
|
|
|
63
|
|
|
$this->parserData->expects( $this->atLeastOnce() ) |
64
|
|
|
->method( 'getSemanticData' ) |
65
|
|
|
->will( $this->returnValue( $semanticData ) ); |
66
|
|
|
|
67
|
|
|
$instance = new SubpageParentAnnotator( |
68
|
|
|
$this->parserData |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$instance->addAnnotation(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testDisabledAnnotationFunctionality() { |
75
|
|
|
|
76
|
|
|
$this->parserData->expects( $this->never() ) |
77
|
|
|
->method( 'getSemanticData' ); |
78
|
|
|
|
79
|
|
|
$instance = new SubpageParentAnnotator( |
80
|
|
|
$this->parserData |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$instance->enableSubpageParentAnnotation( false ); |
84
|
|
|
$instance->addAnnotation(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testDisabledAnnotationFunctionalityDueToPreexisingValues() { |
88
|
|
|
|
89
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
90
|
|
|
->disableOriginalConstructor() |
91
|
|
|
->getMock(); |
92
|
|
|
|
93
|
|
|
$semanticData->expects( $this->once() ) |
94
|
|
|
->method( 'getPropertyValues' ) |
95
|
|
|
->will( $this->returnValue( [ 'Foo' ] ) ); |
96
|
|
|
|
97
|
|
|
$semanticData->expects( $this->never() ) |
98
|
|
|
->method( 'addPropertyObjectValue' ); |
99
|
|
|
|
100
|
|
|
$this->parserData->expects( $this->atLeastOnce() ) |
101
|
|
|
->method( 'getSemanticData' ) |
102
|
|
|
->will( $this->returnValue( $semanticData ) ); |
103
|
|
|
|
104
|
|
|
$instance = new SubpageParentAnnotator( |
105
|
|
|
$this->parserData |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$instance->enableSubpageParentAnnotation( true ); |
109
|
|
|
$instance->addAnnotation(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testNoAnnotationOnPagesWithSpaces() { |
113
|
|
|
|
114
|
|
|
$title = Title::newFromText( 'Foo / Bar' ); |
115
|
|
|
|
116
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
117
|
|
|
->disableOriginalConstructor() |
118
|
|
|
->getMock(); |
119
|
|
|
|
120
|
|
|
$parserData->expects( $this->any() ) |
121
|
|
|
->method( 'getTitle' ) |
122
|
|
|
->will( $this->returnValue( $title ) ); |
123
|
|
|
|
124
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$semanticData->expects( $this->once() ) |
129
|
|
|
->method( 'getPropertyValues' ) |
130
|
|
|
->will( $this->returnValue( [] ) ); |
131
|
|
|
|
132
|
|
|
$semanticData->expects( $this->never() ) |
133
|
|
|
->method( 'addPropertyObjectValue' ); |
134
|
|
|
|
135
|
|
|
$parserData->expects( $this->atLeastOnce() ) |
136
|
|
|
->method( 'getSemanticData' ) |
137
|
|
|
->will( $this->returnValue( $semanticData ) ); |
138
|
|
|
|
139
|
|
|
$instance = new SubpageParentAnnotator( |
140
|
|
|
$parserData |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$instance->enableSubpageParentAnnotation( true ); |
144
|
|
|
$instance->addAnnotation(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|