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
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \SMW\PropertySpecificationLookup |
12
|
|
|
* @group semantic-mediawiki |
13
|
|
|
* |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 2.4 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class PropertySpecificationLookupTest extends \PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
private $store; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->getMockForAbstractClass(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testCanConstruct() { |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf( |
34
|
|
|
'\SMW\PropertySpecificationLookup', |
35
|
|
|
new PropertySpecificationLookup( $this->store ) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetPropertyDescriptionForPredefinedProperty() { |
40
|
|
|
|
41
|
|
|
$instance = new PropertySpecificationLookup( |
42
|
|
|
$this->store |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$this->assertInternalType( |
46
|
|
|
'string', |
47
|
|
|
$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) ) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetPropertyDescriptionForPredefinedPropertyViaCacheForLanguageCode() { |
52
|
|
|
|
53
|
|
|
$cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMockForAbstractClass(); |
56
|
|
|
|
57
|
|
|
$cache->expects( $this->once() ) |
58
|
|
|
->method( 'contains' ) |
59
|
|
|
->will( $this->returnValue( true ) ); |
60
|
|
|
|
61
|
|
|
$cache->expects( $this->once() ) |
62
|
|
|
->method( 'fetch' ) |
63
|
|
|
->with( $this->stringContains( 'foo:smw:pspec:' ) ) |
64
|
|
|
->will( $this->returnValue( array( 'en:-' => 1001 ) ) ); |
65
|
|
|
|
66
|
|
|
$instance = new PropertySpecificationLookup( |
67
|
|
|
$this->store, |
68
|
|
|
$cache |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$instance->setCachePrefix( 'foo' ); |
72
|
|
|
$instance->setLanguageCode( 'en' ); |
73
|
|
|
|
74
|
|
|
$this->assertEquals( |
75
|
|
|
1001, |
76
|
|
|
$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) ) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testTryToGetLocalPropertyDescriptionForUserdefinedProperty() { |
81
|
|
|
|
82
|
|
|
$property = new DIProperty( 'SomeProperty' ); |
83
|
|
|
|
84
|
|
|
$this->store->expects( $this->once() ) |
85
|
|
|
->method( 'getPropertyValues' ) |
86
|
|
|
->with( |
87
|
|
|
$this->equalTo( $property->getDiWikiPage() ), |
88
|
|
|
$this->equalTo( new DIProperty( '_PDESC' ) ), |
89
|
|
|
$this->anything() ) |
90
|
|
|
->will( $this->returnValue( array( |
91
|
|
|
new DIContainer( ContainerSemanticData::makeAnonymousContainer() ) ) ) ); |
92
|
|
|
|
93
|
|
|
$instance = new PropertySpecificationLookup( |
94
|
|
|
$this->store |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$this->assertInternalType( |
98
|
|
|
'string', |
99
|
|
|
$instance->getPropertyDescriptionFor( $property ) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|