1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Section\Gateway\DoctrineDatabaseTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content\Section\Gateway; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; |
14
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Test case for eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase. |
18
|
|
|
*/ |
19
|
|
|
class DoctrineDatabaseTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Database gateway to test. |
23
|
|
|
* |
24
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase |
25
|
|
|
*/ |
26
|
|
|
protected $databaseGateway; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Inserts DB fixture. |
30
|
|
|
*/ |
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
parent::setUp(); |
34
|
|
|
|
35
|
|
|
$this->insertDatabaseFixture( |
36
|
|
|
__DIR__ . '/../../_fixtures/sections.php' |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::__construct |
42
|
|
|
*/ |
43
|
|
|
public function testCtor() |
44
|
|
|
{ |
45
|
|
|
$handler = $this->getDatabaseHandler(); |
46
|
|
|
$gateway = $this->getDatabaseGateway(); |
47
|
|
|
|
48
|
|
|
$this->assertAttributeSame( |
49
|
|
|
$handler, |
50
|
|
|
'dbHandler', |
51
|
|
|
$gateway |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::insertSection |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
public function testInsertSection() |
59
|
|
|
{ |
60
|
|
|
$gateway = $this->getDatabaseGateway(); |
61
|
|
|
|
62
|
|
|
$gateway->insertSection('New Section', 'new_section'); |
63
|
|
|
$query = $this->getDatabaseHandler()->createSelectQuery(); |
64
|
|
|
|
65
|
|
|
$this->assertQueryResult( |
66
|
|
|
array( |
67
|
|
|
array( |
68
|
|
|
'id' => '7', |
69
|
|
|
'identifier' => 'new_section', |
70
|
|
|
'name' => 'New Section', |
71
|
|
|
'locale' => '', |
72
|
|
|
), |
73
|
|
|
), |
74
|
|
|
$query |
75
|
|
|
->select('id', 'identifier', 'name', 'locale') |
76
|
|
|
->from('ezsection') |
77
|
|
|
->where($query->expr->eq('identifier', $query->bindValue('new_section'))) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::updateSection |
83
|
|
|
*/ |
84
|
|
View Code Duplication |
public function testUpdateSection() |
85
|
|
|
{ |
86
|
|
|
$gateway = $this->getDatabaseGateway(); |
87
|
|
|
|
88
|
|
|
$gateway->updateSection(2, 'New Section', 'new_section'); |
89
|
|
|
|
90
|
|
|
$this->assertQueryResult( |
91
|
|
|
array( |
92
|
|
|
array( |
93
|
|
|
'id' => '2', |
94
|
|
|
'identifier' => 'new_section', |
95
|
|
|
'name' => 'New Section', |
96
|
|
|
'locale' => '', |
97
|
|
|
), |
98
|
|
|
), |
99
|
|
|
$this->getDatabaseHandler()->createSelectQuery() |
100
|
|
|
->select('id', 'identifier', 'name', 'locale') |
101
|
|
|
->from('ezsection') |
102
|
|
|
->where('id=2') |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::loadSectionData |
108
|
|
|
*/ |
109
|
|
View Code Duplication |
public function testLoadSectionData() |
110
|
|
|
{ |
111
|
|
|
$gateway = $this->getDatabaseGateway(); |
112
|
|
|
|
113
|
|
|
$result = $gateway->loadSectionData(2); |
114
|
|
|
|
115
|
|
|
$this->assertEquals( |
116
|
|
|
array( |
117
|
|
|
array( |
118
|
|
|
'id' => '2', |
119
|
|
|
'identifier' => 'users', |
120
|
|
|
'name' => 'Users', |
121
|
|
|
), |
122
|
|
|
), |
123
|
|
|
$result |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::loadAllSectionData |
129
|
|
|
*/ |
130
|
|
|
public function testLoadAllSectionData() |
131
|
|
|
{ |
132
|
|
|
$gateway = $this->getDatabaseGateway(); |
133
|
|
|
|
134
|
|
|
$result = $gateway->loadAllSectionData(); |
135
|
|
|
|
136
|
|
|
$expected = array( |
137
|
|
|
array( |
138
|
|
|
'id' => '1', |
139
|
|
|
'identifier' => 'standard', |
140
|
|
|
'name' => 'Standard', |
141
|
|
|
), |
142
|
|
|
|
143
|
|
|
array( |
144
|
|
|
'id' => '2', |
145
|
|
|
'identifier' => 'users', |
146
|
|
|
'name' => 'Users', |
147
|
|
|
), |
148
|
|
|
|
149
|
|
|
array( |
150
|
|
|
'id' => '3', |
151
|
|
|
'identifier' => 'media', |
152
|
|
|
'name' => 'Media', |
153
|
|
|
), |
154
|
|
|
|
155
|
|
|
array( |
156
|
|
|
'id' => '4', |
157
|
|
|
'identifier' => 'setup', |
158
|
|
|
'name' => 'Setup', |
159
|
|
|
), |
160
|
|
|
|
161
|
|
|
array( |
162
|
|
|
'id' => '5', |
163
|
|
|
'identifier' => 'design', |
164
|
|
|
'name' => 'Design', |
165
|
|
|
), |
166
|
|
|
|
167
|
|
|
array( |
168
|
|
|
'id' => '6', |
169
|
|
|
'identifier' => '', |
170
|
|
|
'name' => 'Restricted', |
171
|
|
|
), |
172
|
|
|
); |
173
|
|
|
$this->assertEquals( |
174
|
|
|
$expected, |
175
|
|
|
$result |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::loadSectionDataByIdentifier |
181
|
|
|
*/ |
182
|
|
View Code Duplication |
public function testLoadSectionDataByIdentifier() |
183
|
|
|
{ |
184
|
|
|
$gateway = $this->getDatabaseGateway(); |
185
|
|
|
|
186
|
|
|
$result = $gateway->loadSectionDataByIdentifier('users'); |
187
|
|
|
|
188
|
|
|
$this->assertEquals( |
189
|
|
|
array( |
190
|
|
|
array( |
191
|
|
|
'id' => '2', |
192
|
|
|
'identifier' => 'users', |
193
|
|
|
'name' => 'Users', |
194
|
|
|
), |
195
|
|
|
), |
196
|
|
|
$result |
197
|
|
|
); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::countContentObjectsInSection |
202
|
|
|
*/ |
203
|
|
View Code Duplication |
public function testCountContentObjectsInSection() |
204
|
|
|
{ |
205
|
|
|
$this->insertDatabaseFixture( |
206
|
|
|
__DIR__ . '/../../_fixtures/contentobjects.php' |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$gateway = $this->getDatabaseGateway(); |
210
|
|
|
|
211
|
|
|
$result = $gateway->countContentObjectsInSection(2); |
212
|
|
|
|
213
|
|
|
$this->assertSame( |
214
|
|
|
7, |
215
|
|
|
$result |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::countRoleAssignmentsUsingSection |
221
|
|
|
*/ |
222
|
|
View Code Duplication |
public function testCountRoleAssignmentsUsingSection() |
223
|
|
|
{ |
224
|
|
|
$this->insertDatabaseFixture( |
225
|
|
|
__DIR__ . '/../../../User/_fixtures/roles.php' |
226
|
|
|
); |
227
|
|
|
|
228
|
|
|
$gateway = $this->getDatabaseGateway(); |
229
|
|
|
|
230
|
|
|
$result = $gateway->countRoleAssignmentsUsingSection(2); |
231
|
|
|
|
232
|
|
|
$this->assertSame( |
233
|
|
|
1, |
234
|
|
|
$result |
235
|
|
|
); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::deleteSection |
240
|
|
|
*/ |
241
|
|
View Code Duplication |
public function testDeleteSection() |
242
|
|
|
{ |
243
|
|
|
$gateway = $this->getDatabaseGateway(); |
244
|
|
|
|
245
|
|
|
$result = $gateway->deleteSection(2); |
|
|
|
|
246
|
|
|
|
247
|
|
|
$this->assertQueryResult( |
248
|
|
|
array( |
249
|
|
|
array( |
250
|
|
|
'count' => '5', |
251
|
|
|
), |
252
|
|
|
), |
253
|
|
|
$this->getDatabaseHandler()->createSelectQuery() |
254
|
|
|
->select('COUNT( * ) AS count') |
255
|
|
|
->from('ezsection') |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
$this->assertQueryResult( |
259
|
|
|
array( |
260
|
|
|
array( |
261
|
|
|
'count' => '0', |
262
|
|
|
), |
263
|
|
|
), |
264
|
|
|
$this->getDatabaseHandler()->createSelectQuery() |
265
|
|
|
->select('COUNT( * ) AS count') |
266
|
|
|
->from('ezsection') |
267
|
|
|
->where('id=2') |
268
|
|
|
); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase::assignSectionToContent |
273
|
|
|
* @depends testCountContentObjectsInSection |
274
|
|
|
*/ |
275
|
|
|
public function testAssignSectionToContent() |
276
|
|
|
{ |
277
|
|
|
$this->insertDatabaseFixture( |
278
|
|
|
__DIR__ . '/../../_fixtures/contentobjects.php' |
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
$gateway = $this->getDatabaseGateway(); |
282
|
|
|
|
283
|
|
|
$beforeCount = $gateway->countContentObjectsInSection(4); |
284
|
|
|
|
285
|
|
|
$result = $gateway->assignSectionToContent(4, 10); |
|
|
|
|
286
|
|
|
|
287
|
|
|
$this->assertSame( |
288
|
|
|
$beforeCount + 1, |
289
|
|
|
$gateway->countContentObjectsInSection(4) |
290
|
|
|
); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Returns a ready to test DoctrineDatabase gateway. |
295
|
|
|
* |
296
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway\DoctrineDatabase |
297
|
|
|
*/ |
298
|
|
|
protected function getDatabaseGateway() |
299
|
|
|
{ |
300
|
|
|
if (!isset($this->databaseGateway)) { |
301
|
|
|
$this->databaseGateway = new DoctrineDatabase( |
302
|
|
|
$this->getDatabaseHandler() |
303
|
|
|
); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
return $this->databaseGateway; |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.