1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\SQLStore; |
4
|
|
|
|
5
|
|
|
use SMW\DIProperty; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\SemanticData; |
8
|
|
|
use SMW\Tests\TestEnvironment; |
9
|
|
|
use SMWDITime as DITime; |
10
|
|
|
use SMWSql3StubSemanticData as StubSemanticData; |
11
|
|
|
use Title; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \SMWSql3StubSemanticData |
15
|
|
|
* |
16
|
|
|
* @group SMW |
17
|
|
|
* @group SMWExtension |
18
|
|
|
* |
19
|
|
|
* @license GNU GPL v2+ |
20
|
|
|
* @since 1.9.0.2 |
21
|
|
|
* |
22
|
|
|
* @author mwjames |
23
|
|
|
*/ |
24
|
|
|
class Sql3StubSemanticDataTest extends \PHPUnit_Framework_TestCase { |
25
|
|
|
|
26
|
|
|
private $store; |
27
|
|
|
private $testEnvironment; |
28
|
|
|
|
29
|
|
|
protected function setUp() { |
30
|
|
|
|
31
|
|
|
$this->testEnvironment = new TestEnvironment(); |
32
|
|
|
|
33
|
|
|
$this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$this->store->expects( $this->any() ) |
38
|
|
|
->method( 'getRedirectTarget' ) |
39
|
|
|
->will( $this->returnArgument( 0 ) ); |
40
|
|
|
|
41
|
|
|
$this->testEnvironment->registerObject( 'Store', $this->store ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function tearDown() { |
45
|
|
|
$this->testEnvironment->tearDown(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCanConstruct() { |
49
|
|
|
|
50
|
|
|
$subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
51
|
|
|
|
52
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
|
56
|
|
|
$semanticData->expects( $this->once() ) |
57
|
|
|
->method( 'getSubject' ) |
58
|
|
|
->will( $this->returnValue( $subject ) ); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf( |
61
|
|
|
'\SMWSql3StubSemanticData', |
62
|
|
|
StubSemanticData::newFromSemanticData( $semanticData, $this->store ) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testNotToResolveSubobjectsForRedirect() { |
67
|
|
|
|
68
|
|
|
$instance = $this->getMockBuilder( '\SMWSql3StubSemanticData' ) |
69
|
|
|
->setConstructorArgs( array( |
70
|
|
|
DIWikiPage::newFromText( __METHOD__ ), |
71
|
|
|
$this->store ) ) |
72
|
|
|
->setMethods( array( |
73
|
|
|
'getProperties', |
74
|
|
|
'isRedirect', |
75
|
|
|
'getPropertyValues' ) ) |
76
|
|
|
->getMock(); |
77
|
|
|
|
78
|
|
|
$instance->expects( $this->once() ) |
79
|
|
|
->method( 'getProperties' ) |
80
|
|
|
->will( $this->returnValue( array( new DIProperty( '_SOBJ' ) ) ) ); |
81
|
|
|
|
82
|
|
|
$instance->expects( $this->once() ) |
83
|
|
|
->method( 'isRedirect' ) |
84
|
|
|
->will( $this->returnValue( true ) ); |
85
|
|
|
|
86
|
|
|
$instance->expects( $this->never() ) |
87
|
|
|
->method( 'getPropertyValues' ); |
88
|
|
|
|
89
|
|
|
$instance->getSubSemanticData(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetPropertyValues() { |
93
|
|
|
|
94
|
|
|
$instance = StubSemanticData::newFromSemanticData( |
95
|
|
|
new SemanticData( DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ) ), |
|
|
|
|
96
|
|
|
$this->store |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->assertInstanceOf( |
100
|
|
|
'SMW\DIWikiPage', |
101
|
|
|
$instance->getSubject() |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->assertEmpty( |
105
|
|
|
$instance->getPropertyValues( new DIProperty( 'unknownInverseProperty', true ) ) |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->assertEmpty( |
109
|
|
|
$instance->getPropertyValues( new DIProperty( 'unknownProperty' ) ) |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @dataProvider propertyObjectProvider |
115
|
|
|
*/ |
116
|
|
|
public function testPhpSerialization( $property, $dataItem ) { |
117
|
|
|
|
118
|
|
|
$instance = StubSemanticData::newFromSemanticData( |
119
|
|
|
new SemanticData( new DIWikiPage( 'Foo', NS_MAIN ) ), |
|
|
|
|
120
|
|
|
$this->store |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$instance->addPropertyObjectValue( |
124
|
|
|
$property, |
125
|
|
|
$dataItem |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$serialization = serialize( $instance ); |
129
|
|
|
|
130
|
|
|
$this->assertEquals( |
131
|
|
|
$instance->getHash(), |
132
|
|
|
unserialize( $serialization )->getHash() |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @dataProvider propertyObjectProvider |
138
|
|
|
*/ |
139
|
|
|
public function testRemovePropertyObjectValue( $property, $dataItem ) { |
140
|
|
|
|
141
|
|
|
$instance = StubSemanticData::newFromSemanticData( |
142
|
|
|
new SemanticData( new DIWikiPage( 'Foo', NS_MAIN ) ), |
|
|
|
|
143
|
|
|
$this->store |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
$instance->addPropertyObjectValue( $property, $dataItem ); |
147
|
|
|
$this->assertFalse( $instance->isEmpty() ); |
148
|
|
|
|
149
|
|
|
$instance->removePropertyObjectValue( $property, $dataItem ); |
150
|
|
|
$this->assertTrue( $instance->isEmpty() ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function propertyObjectProvider() { |
154
|
|
|
|
155
|
|
|
$provider = array(); |
156
|
|
|
|
157
|
|
|
// #0 |
158
|
|
|
$provider[] = array( |
159
|
|
|
new DIProperty( '_MDAT' ), |
160
|
|
|
DITime::newFromTimestamp( 1272508903 ) |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
return $provider; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.