1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\PropertySpecificationLookup; |
6
|
|
|
use SMW\DIProperty; |
7
|
|
|
use SMWDIContainer as DIContainer; |
8
|
|
|
use SMWContainerSemanticData as ContainerSemanticData; |
9
|
|
|
use SMWDIBlob as DIBlob; |
10
|
|
|
use SMWDINumber as DINumber; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \SMW\PropertySpecificationLookup |
14
|
|
|
* @group semantic-mediawiki |
15
|
|
|
* |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 2.4 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class PropertySpecificationLookupTest extends \PHPUnit_Framework_TestCase { |
22
|
|
|
|
23
|
|
|
private $store; |
24
|
|
|
private $blobStore; |
25
|
|
|
|
26
|
|
|
protected function setUp() { |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
30
|
|
|
->disableOriginalConstructor() |
31
|
|
|
->getMockForAbstractClass(); |
32
|
|
|
|
33
|
|
|
$this->blobStore = $this->getMockBuilder( '\Onoi\BlobStore\BlobStore' ) |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->getMock(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCanConstruct() { |
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf( |
41
|
|
|
'\SMW\PropertySpecificationLookup', |
42
|
|
|
new PropertySpecificationLookup( $this->store, $this->blobStore ) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetPropertyDescriptionForPredefinedProperty() { |
47
|
|
|
|
48
|
|
|
$instance = new PropertySpecificationLookup( |
49
|
|
|
$this->store, |
50
|
|
|
$this->blobStore |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$container = $this->getMockBuilder( '\Onoi\BlobStore\Container' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
|
57
|
|
|
$this->blobStore->expects( $this->once() ) |
58
|
|
|
->method( 'read' ) |
59
|
|
|
->will( $this->returnValue( $container ) ); |
60
|
|
|
|
61
|
|
|
$this->assertInternalType( |
62
|
|
|
'string', |
63
|
|
|
$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) ) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testGetPropertyDescriptionForPredefinedPropertyViaCacheForLanguageCode() { |
68
|
|
|
|
69
|
|
|
$container = $this->getMockBuilder( '\Onoi\BlobStore\Container' ) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->getMock(); |
72
|
|
|
|
73
|
|
|
$container->expects( $this->once() ) |
74
|
|
|
->method( 'has' ) |
75
|
|
|
->will( $this->returnValue( true ) ); |
76
|
|
|
|
77
|
|
|
$container->expects( $this->once() ) |
78
|
|
|
->method( 'get' ) |
79
|
|
|
->with( $this->stringContains( 'pdesc:en:0' ) ) |
80
|
|
|
->will( $this->returnValue( 1001 ) ); |
81
|
|
|
|
82
|
|
|
$this->blobStore->expects( $this->once() ) |
83
|
|
|
->method( 'read' ) |
84
|
|
|
->will( $this->returnValue( $container ) ); |
85
|
|
|
|
86
|
|
|
$instance = new PropertySpecificationLookup( |
87
|
|
|
$this->store, |
88
|
|
|
$this->blobStore |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$instance->setLanguageCode( 'en' ); |
92
|
|
|
|
93
|
|
|
$this->assertEquals( |
94
|
|
|
1001, |
95
|
|
|
$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) ) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testTryToGetLocalPropertyDescriptionForUserdefinedProperty() { |
100
|
|
|
|
101
|
|
|
$container = $this->getMockBuilder( '\Onoi\BlobStore\Container' ) |
102
|
|
|
->disableOriginalConstructor() |
103
|
|
|
->getMock(); |
104
|
|
|
|
105
|
|
|
$this->blobStore->expects( $this->once() ) |
106
|
|
|
->method( 'read' ) |
107
|
|
|
->will( $this->returnValue( $container ) ); |
108
|
|
|
|
109
|
|
|
$property = new DIProperty( 'SomeProperty' ); |
110
|
|
|
|
111
|
|
|
$this->store->expects( $this->once() ) |
112
|
|
|
->method( 'getPropertyValues' ) |
113
|
|
|
->with( |
114
|
|
|
$this->equalTo( $property->getDiWikiPage() ), |
115
|
|
|
$this->equalTo( new DIProperty( '_PDESC' ) ), |
116
|
|
|
$this->anything() ) |
117
|
|
|
->will( $this->returnValue( array( |
118
|
|
|
new DIContainer( ContainerSemanticData::makeAnonymousContainer() ) ) ) ); |
119
|
|
|
|
120
|
|
|
$instance = new PropertySpecificationLookup( |
121
|
|
|
$this->store, |
122
|
|
|
$this->blobStore |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$this->assertInternalType( |
126
|
|
|
'string', |
127
|
|
|
$instance->getPropertyDescriptionFor( $property ) |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testGetNonCachedDisplayUnit() { |
132
|
|
|
|
133
|
|
|
$container = $this->getMockBuilder( '\Onoi\BlobStore\Container' ) |
134
|
|
|
->disableOriginalConstructor() |
135
|
|
|
->getMock(); |
136
|
|
|
|
137
|
|
|
$this->blobStore->expects( $this->once() ) |
138
|
|
|
->method( 'read' ) |
139
|
|
|
->will( $this->returnValue( $container ) ); |
140
|
|
|
|
141
|
|
|
$this->blobStore->expects( $this->once() ) |
142
|
|
|
->method( 'save' ); |
143
|
|
|
|
144
|
|
|
$property = new DIProperty( 'SomeProperty' ); |
145
|
|
|
|
146
|
|
|
$this->store->expects( $this->once() ) |
147
|
|
|
->method( 'getPropertyValues' ) |
148
|
|
|
->with( |
149
|
|
|
$this->equalTo( $property->getDiWikiPage() ), |
150
|
|
|
$this->equalTo( new DIProperty( '_UNIT' ) ), |
151
|
|
|
$this->anything() ) |
152
|
|
|
->will( $this->returnValue( array( |
153
|
|
|
new DIBlob( 'abc,def' ), new DIBlob( '123' ) ) ) ); |
154
|
|
|
|
155
|
|
|
$instance = new PropertySpecificationLookup( |
156
|
|
|
$this->store, |
157
|
|
|
$this->blobStore |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
$this->assertEquals( |
161
|
|
|
array( 'abc', 'def', '123' ), |
162
|
|
|
$instance->getDisplayUnitsFor( $property ) |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testGetNonCachedDisplayPrecision() { |
167
|
|
|
|
168
|
|
|
$container = $this->getMockBuilder( '\Onoi\BlobStore\Container' ) |
169
|
|
|
->disableOriginalConstructor() |
170
|
|
|
->getMock(); |
171
|
|
|
|
172
|
|
|
$this->blobStore->expects( $this->once() ) |
173
|
|
|
->method( 'read' ) |
174
|
|
|
->will( $this->returnValue( $container ) ); |
175
|
|
|
|
176
|
|
|
$this->blobStore->expects( $this->once() ) |
177
|
|
|
->method( 'save' ); |
178
|
|
|
|
179
|
|
|
$property = new DIProperty( 'SomeProperty' ); |
180
|
|
|
|
181
|
|
|
$this->store->expects( $this->once() ) |
182
|
|
|
->method( 'getPropertyValues' ) |
183
|
|
|
->with( |
184
|
|
|
$this->equalTo( $property->getDiWikiPage() ), |
185
|
|
|
$this->equalTo( new DIProperty( '_PREC' ) ), |
186
|
|
|
$this->anything() ) |
187
|
|
|
->will( $this->returnValue( array( |
188
|
|
|
new DINumber( -2.3 ) ) ) ); |
189
|
|
|
|
190
|
|
|
$instance = new PropertySpecificationLookup( |
191
|
|
|
$this->store, |
192
|
|
|
$this->blobStore |
193
|
|
|
); |
194
|
|
|
|
195
|
|
|
$this->assertEquals( |
196
|
|
|
2, |
197
|
|
|
$instance->getDisplayPrecisionFor( $property ) |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|