1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\EntityStore; |
4
|
|
|
|
5
|
|
|
use Queryr\EntityStore\Data\ItemRow; |
6
|
|
|
use Queryr\EntityStore\Data\PropertyInfo; |
7
|
|
|
use Queryr\EntityStore\Data\PropertyRow; |
8
|
|
|
use Queryr\EntityStore\EntityStore; |
9
|
|
|
use Queryr\EntityStore\EntityStoreConfig; |
10
|
|
|
use Queryr\EntityStore\EntityStoreFactory; |
11
|
|
|
use Queryr\EntityStore\EntityStoreInstaller; |
12
|
|
|
use Tests\Queryr\EntityStore\Fixtures\TestFixtureFactory; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers Queryr\EntityStore\EntityStore |
16
|
|
|
* @covers Queryr\EntityStore\ItemStore |
17
|
|
|
* @covers Queryr\EntityStore\PropertyStore |
18
|
|
|
* |
19
|
|
|
* @licence GNU GPL v2+ |
20
|
|
|
* @author Jeroen De Dauw < [email protected] > |
21
|
|
|
*/ |
22
|
|
|
class EntityStoreTest extends \PHPUnit_Framework_TestCase { |
23
|
|
|
|
24
|
|
|
const ITEM_ID = '1337'; |
25
|
|
|
const PROPERTY_ID = '42'; |
26
|
|
|
|
27
|
|
|
const AND_INSTALL = true; |
28
|
|
|
const WITHOUT_INSTALLING = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var EntityStore |
32
|
|
|
*/ |
33
|
|
|
private $store; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Queryr\EntityStore\Data\ItemRow |
37
|
|
|
*/ |
38
|
|
|
private $itemRow; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var PropertyRow |
42
|
|
|
*/ |
43
|
|
|
private $propertyRow; |
44
|
|
|
|
45
|
|
|
public function setUp() { |
46
|
|
|
$this->createItemRowField(); |
47
|
|
|
$this->createPropertyRowField(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function createStore( $doDbInstall = false ) { |
51
|
|
|
$connection = TestFixtureFactory::newInstance()->newConnection(); |
52
|
|
|
$config = new EntityStoreConfig(); |
53
|
|
|
|
54
|
|
|
if ( $doDbInstall ) { |
55
|
|
|
$installer = new EntityStoreInstaller( $connection->getSchemaManager(), $config ); |
56
|
|
|
$installer->install(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->store = ( new EntityStoreFactory( $connection, $config ) )->newEntityStore(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function createItemRowField() { |
63
|
|
|
$this->itemRow = ( new ItemRow() ) |
64
|
|
|
->setPageTitle( 'Item:Q1337' ) |
65
|
|
|
->setRevisionId( '424242' ) |
66
|
|
|
->setItemType( 1 ) |
67
|
|
|
->setRevisionTime( '2014-02-27T11:40:12Z' ) |
68
|
|
|
->setEnglishLabel( 'kittens' ) |
69
|
|
|
->setItemJson( 'json be here' ) |
70
|
|
|
->setNumericItemId( self::ITEM_ID ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function createPropertyRowField() { |
74
|
|
|
$this->propertyRow = new PropertyRow( |
75
|
|
|
'json be here', |
76
|
|
|
new PropertyInfo( |
77
|
|
|
self::PROPERTY_ID, |
78
|
|
|
'Property:P42', |
79
|
|
|
'424242', |
80
|
|
|
'2014-02-27T11:40:12Z', |
81
|
|
|
'string' |
82
|
|
|
) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testCanStoreAndRetrieveItemPage() { |
87
|
|
|
$this->createStore( self::AND_INSTALL ); |
88
|
|
|
|
89
|
|
|
$this->store->storeItemRow( $this->itemRow ); |
90
|
|
|
|
91
|
|
|
$newItemRow = $this->store->getItemRowByNumericItemId( self::ITEM_ID ); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf( 'Queryr\EntityStore\Data\ItemRow', $newItemRow ); |
94
|
|
|
|
95
|
|
|
$this->assertSame( $this->itemRow->getNumericItemId(), $newItemRow->getNumericItemId() ); |
96
|
|
|
$this->assertSame( $this->itemRow->getItemJson(), $newItemRow->getItemJson() ); |
97
|
|
|
$this->assertSame( $this->itemRow->getPageTitle(), $newItemRow->getPageTitle() ); |
98
|
|
|
$this->assertSame( $this->itemRow->getRevisionId(), $newItemRow->getRevisionId() ); |
99
|
|
|
$this->assertSame( $this->itemRow->getRevisionTime(), $newItemRow->getRevisionTime() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testGivenNotKnownId_getItemRowByNumericItemIdReturnsNull() { |
103
|
|
|
$this->createStore( self::AND_INSTALL ); |
104
|
|
|
$this->assertNull( $this->store->getItemRowByNumericItemId( '32202' ) ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testCanStoreAndRetrievePropertyPage() { |
108
|
|
|
$this->createStore( self::AND_INSTALL ); |
109
|
|
|
|
110
|
|
|
$this->store->storePropertyRow( $this->propertyRow ); |
111
|
|
|
|
112
|
|
|
$newPropertyRow = $this->store->getPropertyRowByNumericPropertyId( self::PROPERTY_ID ); |
113
|
|
|
|
114
|
|
|
$this->assertInstanceOf( 'Queryr\EntityStore\Data\PropertyRow', $newPropertyRow ); |
115
|
|
|
|
116
|
|
|
$this->assertSame( $this->propertyRow->getNumericPropertyId(), $newPropertyRow->getNumericPropertyId() ); |
117
|
|
|
$this->assertSame( $this->propertyRow->getPropertyJson(), $newPropertyRow->getPropertyJson() ); |
118
|
|
|
$this->assertSame( $this->propertyRow->getPageTitle(), $newPropertyRow->getPageTitle() ); |
119
|
|
|
$this->assertSame( $this->propertyRow->getRevisionId(), $newPropertyRow->getRevisionId() ); |
120
|
|
|
$this->assertSame( $this->propertyRow->getRevisionTime(), $newPropertyRow->getRevisionTime() ); |
121
|
|
|
$this->assertSame( $this->propertyRow->getPropertyType(), $newPropertyRow->getPropertyType() ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testGivenNotKnownId_getPropertyRowByNumericPropertyIdReturnsNull() { |
125
|
|
|
$this->createStore( self::AND_INSTALL ); |
126
|
|
|
$this->assertNull( $this->store->getPropertyRowByNumericPropertyId( '32202' ) ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testWhenStoreNotInitialized_storeItemRowThrowsException() { |
130
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
131
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
132
|
|
|
$this->store->storeItemRow( $this->itemRow ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testWhenStoreNotInitialized_storePropertyRowThrowsException() { |
136
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
137
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
138
|
|
|
$this->store->storePropertyRow( $this->propertyRow ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testWhenStoreNotInitialized_getItemRowByNumericItemIdThrowsException() { |
142
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
143
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
144
|
|
|
$this->store->getItemRowByNumericItemId( 1 ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testWhenStoreNotInitialized_getPropertyRowByNumericPropertyIdThrowsException() { |
148
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
149
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
150
|
|
|
$this->store->getPropertyRowByNumericPropertyId( 1 ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function testWhenStoreNotInitialized_getPropertyInfoThrowsException() { |
154
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
155
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
156
|
|
|
$this->store->getPropertyInfo( 10, 0 ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testWhenStoreNotInitialized_getItemInfoThrowsException() { |
160
|
|
|
$this->createStore( self::WITHOUT_INSTALLING ); |
161
|
|
|
$this->setExpectedException( 'Queryr\EntityStore\EntityStoreException' ); |
|
|
|
|
162
|
|
|
$this->store->getItemInfo( 10, 0 ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.