|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SIL\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SIL\LanguageLinkAnnotator; |
|
6
|
|
|
use SIL\InterlanguageLink; |
|
7
|
|
|
use SIL\InterwikiLanguageLink; |
|
8
|
|
|
use SIL\PropertyRegistry; |
|
9
|
|
|
use SMW\DIWikiPage; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \SIL\LanguageLinkAnnotator |
|
13
|
|
|
* @group semantic-interlanguage-links |
|
14
|
|
|
* |
|
15
|
|
|
* @license GNU GPL v2+ |
|
16
|
|
|
* @since 1.0 |
|
17
|
|
|
* |
|
18
|
|
|
* @author mwjames |
|
19
|
|
|
*/ |
|
20
|
|
|
class LanguageLinkAnnotatorTest extends \PHPUnit_Framework_TestCase { |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() { |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
|
|
25
|
|
|
$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' ) |
|
26
|
|
|
->disableOriginalConstructor() |
|
27
|
|
|
->getMock(); |
|
28
|
|
|
|
|
29
|
|
|
$instance = new PropertyRegistry(); |
|
30
|
|
|
$instance->register( $propertyRegistry ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testCanConstruct() { |
|
34
|
|
|
|
|
35
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
36
|
|
|
->disableOriginalConstructor() |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf( |
|
40
|
|
|
'\SIL\LanguageLinkAnnotator', |
|
41
|
|
|
new LanguageLinkAnnotator( $parserData ) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @dataProvider differentLanguageAnnotationProvider |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testHasDifferentLanguageAnnotation( $pValues, $expected ) { |
|
49
|
|
|
|
|
50
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
51
|
|
|
->disableOriginalConstructor() |
|
52
|
|
|
->getMock(); |
|
53
|
|
|
|
|
54
|
|
|
$semanticData->expects( $this->once() ) |
|
55
|
|
|
->method( 'getPropertyValues' ) |
|
56
|
|
|
->will( $this->returnValue( $pValues ) ); |
|
57
|
|
|
|
|
58
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
59
|
|
|
->disableOriginalConstructor() |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
|
|
62
|
|
|
$parserData->expects( $this->once() ) |
|
63
|
|
|
->method( 'getSemanticData' ) |
|
64
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
65
|
|
|
|
|
66
|
|
|
$instance = new LanguageLinkAnnotator( $parserData ); |
|
67
|
|
|
|
|
68
|
|
|
$result = $instance->hasDifferentLanguageAnnotation( |
|
69
|
|
|
new InterlanguageLink( 'ja', 'bar' ) |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals( |
|
73
|
|
|
$expected, |
|
74
|
|
|
$result |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testAddAnnotationForInterlanguageLink() { |
|
80
|
|
|
|
|
81
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
82
|
|
|
->disableOriginalConstructor() |
|
83
|
|
|
->getMock(); |
|
84
|
|
|
|
|
85
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
86
|
|
|
->disableOriginalConstructor() |
|
87
|
|
|
->getMock(); |
|
88
|
|
|
|
|
89
|
|
|
$parserData->expects( $this->once() ) |
|
90
|
|
|
->method( 'getTitle' ) |
|
91
|
|
|
->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
|
92
|
|
|
|
|
93
|
|
|
$parserData->expects( $this->once() ) |
|
94
|
|
|
->method( 'getSemanticData' ) |
|
95
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
96
|
|
|
|
|
97
|
|
|
$parserData->expects( $this->once() ) |
|
98
|
|
|
->method( 'pushSemanticDataToParserOutput' ); |
|
99
|
|
|
|
|
100
|
|
|
$parserData->expects( $this->once() ) |
|
101
|
|
|
->method( 'setSemanticDataStateToParserOutputProperty' ); |
|
102
|
|
|
|
|
103
|
|
|
$instance = new LanguageLinkAnnotator( $parserData ); |
|
104
|
|
|
|
|
105
|
|
|
$instance->addAnnotationForInterlanguageLink( |
|
106
|
|
|
new InterlanguageLink( 'en', 'bar' ) |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testAddAnnotationForInterwikiLanguageLink() { |
|
111
|
|
|
|
|
112
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
113
|
|
|
->disableOriginalConstructor() |
|
114
|
|
|
->getMock(); |
|
115
|
|
|
|
|
116
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
117
|
|
|
->disableOriginalConstructor() |
|
118
|
|
|
->getMock(); |
|
119
|
|
|
|
|
120
|
|
|
$parserData->expects( $this->once() ) |
|
121
|
|
|
->method( 'getTitle' ) |
|
122
|
|
|
->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
|
123
|
|
|
|
|
124
|
|
|
$parserData->expects( $this->once() ) |
|
125
|
|
|
->method( 'getSemanticData' ) |
|
126
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
127
|
|
|
|
|
128
|
|
|
$parserData->expects( $this->once() ) |
|
129
|
|
|
->method( 'pushSemanticDataToParserOutput' ); |
|
130
|
|
|
|
|
131
|
|
|
$parserData->expects( $this->once() ) |
|
132
|
|
|
->method( 'setSemanticDataStateToParserOutputProperty' ); |
|
133
|
|
|
|
|
134
|
|
|
$instance = new LanguageLinkAnnotator( $parserData ); |
|
135
|
|
|
|
|
136
|
|
|
$instance->addAnnotationForInterwikiLanguageLink( |
|
137
|
|
|
new InterwikiLanguageLink( 'en:Foo' ) |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testCanAddAnnotation() { |
|
142
|
|
|
|
|
143
|
|
|
$parserData = $this->getMockBuilder( '\SMW\ParserData' ) |
|
144
|
|
|
->disableOriginalConstructor() |
|
145
|
|
|
->getMock(); |
|
146
|
|
|
|
|
147
|
|
|
// SMW 3.0 |
|
148
|
|
|
$parserData->expects( $this->any() ) |
|
149
|
|
|
->method( 'canUse' ) |
|
150
|
|
|
->will( $this->returnValue( false ) ); |
|
151
|
|
|
|
|
152
|
|
|
$instance = new LanguageLinkAnnotator( $parserData ); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertFalse( |
|
155
|
|
|
$instance->canAddAnnotation() |
|
156
|
|
|
); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function differentLanguageAnnotationProvider() { |
|
160
|
|
|
|
|
161
|
|
|
$provider[] = [ |
|
162
|
|
|
[ new DIWikiPage( 'Foo', NS_MAIN, '' , 'ill.en' ) ], |
|
163
|
|
|
true |
|
164
|
|
|
]; |
|
165
|
|
|
|
|
166
|
|
|
$provider[] = [ |
|
167
|
|
|
[], |
|
168
|
|
|
false |
|
169
|
|
|
]; |
|
170
|
|
|
|
|
171
|
|
|
return $provider; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|