|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Queryr\EntityStore; |
|
4
|
|
|
|
|
5
|
|
|
use Queryr\EntityStore\Data\ItemInfo; |
|
6
|
|
|
use Queryr\EntityStore\Data\ItemRow; |
|
7
|
|
|
use Queryr\EntityStore\Data\PropertyInfo; |
|
8
|
|
|
use Queryr\EntityStore\Data\PropertyRow; |
|
9
|
|
|
use Queryr\EntityStore\EntityStore; |
|
10
|
|
|
use Queryr\EntityStore\EntityStoreConfig; |
|
11
|
|
|
use Queryr\EntityStore\EntityStoreFactory; |
|
12
|
|
|
use Queryr\EntityStore\EntityStoreInstaller; |
|
13
|
|
|
use Tests\Queryr\EntityStore\Fixtures\TestFixtureFactory; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @covers Queryr\EntityStore\EntityStore |
|
17
|
|
|
* |
|
18
|
|
|
* @licence GNU GPL v2+ |
|
19
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
20
|
|
|
*/ |
|
21
|
|
|
class EntityStoreInfoFetchingTest extends \PHPUnit_Framework_TestCase { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var EntityStore |
|
25
|
|
|
*/ |
|
26
|
|
|
private $store; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var ItemInfo[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $itemInfos = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var PropertyInfo[] |
|
35
|
|
|
*/ |
|
36
|
|
|
private $propertyInfos = []; |
|
37
|
|
|
|
|
38
|
|
|
public function setUp() { |
|
39
|
|
|
$this->createStore(); |
|
40
|
|
|
$this->insertPropertyRows(); |
|
41
|
|
|
$this->insertItemRows(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function createStore() { |
|
45
|
|
|
$connection = TestFixtureFactory::newInstance()->newConnection(); |
|
46
|
|
|
$config = new EntityStoreConfig(); |
|
47
|
|
|
|
|
48
|
|
|
$installer = new EntityStoreInstaller( $connection->getSchemaManager(), $config ); |
|
49
|
|
|
$installer->install(); |
|
50
|
|
|
|
|
51
|
|
|
$this->store = ( new EntityStoreFactory( $connection, $config ) )->newEntityStore(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function insertItemRows() { |
|
55
|
|
|
foreach ( [ 1, 10, 2, 9, 8, 7, 3, 4, 6, 5 ] as $integer ) { |
|
56
|
|
|
$row = ( new ItemRow() ) |
|
57
|
|
|
->setItemJson( 'json be here ' . $integer ) |
|
58
|
|
|
->setEnglishLabel( 'item ' . $integer ) |
|
59
|
|
|
->setItemType( $integer + 1 ) |
|
60
|
|
|
->setRevisionTime( '2014-02-27T11:40:' . $integer . 'Z' ) |
|
61
|
|
|
->setRevisionId( '424242' . $integer ) |
|
62
|
|
|
->setNumericItemId( $integer ) |
|
63
|
|
|
->setPageTitle( 'Item:Q' . $integer ); |
|
64
|
|
|
|
|
65
|
|
|
$this->itemInfos[$integer] = $row->getItemInfo(); |
|
66
|
|
|
|
|
67
|
|
|
$this->store->storeItemRow( $row ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
sort( $this->itemInfos ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function insertPropertyRows() { |
|
74
|
|
|
foreach ( [ 101, 110, 102, 109, 108, 107, 103, 104, 106, 105 ] as $integer ) { |
|
75
|
|
|
$info = new PropertyInfo( |
|
76
|
|
|
$integer, |
|
77
|
|
|
'Property:P' . $integer, |
|
78
|
|
|
'424242' . $integer, |
|
79
|
|
|
$integer . '4-02-27T11:40:12Z', |
|
80
|
|
|
'string' |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$this->propertyInfos[$integer] = $info; |
|
84
|
|
|
|
|
85
|
|
|
$this->store->storePropertyRow( |
|
86
|
|
|
new PropertyRow( |
|
87
|
|
|
'json be here ' . $integer, |
|
88
|
|
|
$info |
|
89
|
|
|
) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
sort( $this->propertyInfos ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testGivenLimitBiggerThanSet_getPropertyInfoReturnsAllRows() { |
|
97
|
|
|
$propertyInfoSets = $this->store->getPropertyInfo( 100, 0 ); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertIsPropertyInfoArray( $propertyInfoSets ); |
|
100
|
|
|
$this->assertEquals( |
|
101
|
|
|
array_values( $this->propertyInfos ), |
|
102
|
|
|
$propertyInfoSets |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testGivenLimitSmallerThanSet_getPropertyInfoReturnsLimitedRows() { |
|
107
|
|
|
$propertyInfoSets = $this->store->getPropertyInfo( 5, 0 ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertIsPropertyInfoArray( $propertyInfoSets ); |
|
110
|
|
|
$this->assertEquals( |
|
111
|
|
|
array_values( array_slice( $this->propertyInfos, 0, 5 ) ), |
|
112
|
|
|
$propertyInfoSets |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testGivenOffsetSmallerThanSet_getPropertyInfoReturnsPagedRows() { |
|
117
|
|
|
$propertyInfoSets = $this->store->getPropertyInfo( 5, 7 ); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertIsPropertyInfoArray( $propertyInfoSets ); |
|
120
|
|
|
$this->assertEquals( |
|
121
|
|
|
array_values( array_slice( $this->propertyInfos, 7, 5 ) ), |
|
122
|
|
|
$propertyInfoSets |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function testGivenOffsetBiggerThanSet_getPropertyInfoReturnsEmptyArray() { |
|
127
|
|
|
$propertyInfoSets = $this->store->getPropertyInfo( 5, 20 ); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertIsPropertyInfoArray( $propertyInfoSets ); |
|
130
|
|
|
$this->assertEquals( |
|
131
|
|
|
[], |
|
132
|
|
|
$propertyInfoSets |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
private function assertIsPropertyInfoArray( $info ) { |
|
137
|
|
|
$this->assertInternalType( 'array', $info ); |
|
138
|
|
|
$this->assertContainsOnlyInstancesOf( 'Queryr\EntityStore\Data\PropertyInfo', $info ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testGivenLimitBiggerThanSet_getItemInfoReturnsAllRows() { |
|
142
|
|
|
$itemInfoSets = $this->store->getItemInfo( 100, 0 ); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertIsItemInfoArray( $itemInfoSets ); |
|
145
|
|
|
$this->assertEquals( |
|
146
|
|
|
array_values( $this->itemInfos ), |
|
147
|
|
|
$itemInfoSets |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function testGivenLimitSmallerThanSet_getItemInfoReturnsLimitedRows() { |
|
152
|
|
|
$itemInfoSets = $this->store->getItemInfo( 5, 0 ); |
|
153
|
|
|
|
|
154
|
|
|
$this->assertIsItemInfoArray( $itemInfoSets ); |
|
155
|
|
|
$this->assertEquals( |
|
156
|
|
|
array_values( array_slice( $this->itemInfos, 0, 5 ) ), |
|
157
|
|
|
$itemInfoSets |
|
158
|
|
|
); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function testGivenOffsetSmallerThanSet_getItemInfoReturnsPagedRows() { |
|
162
|
|
|
$itemInfoSets = $this->store->getItemInfo( 5, 7 ); |
|
163
|
|
|
|
|
164
|
|
|
$this->assertIsItemInfoArray( $itemInfoSets ); |
|
165
|
|
|
$this->assertEquals( |
|
166
|
|
|
array_values( array_slice( $this->itemInfos, 7, 5 ) ), |
|
167
|
|
|
$itemInfoSets |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function testGivenOffsetBiggerThanSet_getItemInfoReturnsEmptyArray() { |
|
172
|
|
|
$itemInfoSets = $this->store->getItemInfo( 5, 20 ); |
|
173
|
|
|
|
|
174
|
|
|
$this->assertIsItemInfoArray( $itemInfoSets ); |
|
175
|
|
|
$this->assertEquals( |
|
176
|
|
|
[], |
|
177
|
|
|
$itemInfoSets |
|
178
|
|
|
); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
private function assertIsItemInfoArray( $info ) { |
|
182
|
|
|
$this->assertInternalType( 'array', $info ); |
|
183
|
|
|
$this->assertContainsOnlyInstancesOf( 'Queryr\EntityStore\Data\ItemInfo', $info ); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|