|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Notification\Gateway; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase; |
|
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; |
|
13
|
|
|
use eZ\Publish\SPI\Persistence\Notification\CreateStruct; |
|
14
|
|
|
use eZ\Publish\SPI\Persistence\Notification\Notification; |
|
15
|
|
|
use PDO; |
|
16
|
|
|
|
|
17
|
|
|
class DoctrineDatabaseTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
const EXISTING_NOTIFICATION_ID = 1; |
|
20
|
|
|
const EXISTING_NOTIFICATION_DATA = [ |
|
21
|
|
|
'id' => 1, |
|
22
|
|
|
'owner_id' => 14, |
|
23
|
|
|
'is_pending' => 1, |
|
24
|
|
|
'type' => 'Workflow:Review', |
|
25
|
|
|
'created' => 1529995052, |
|
26
|
|
|
'data' => null, |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
public function setUp() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::setUp(); |
|
32
|
|
|
|
|
33
|
|
|
$this->insertDatabaseFixture( |
|
34
|
|
|
__DIR__ . '/../_fixtures/notifications.php' |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::insert() |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testInsert() |
|
42
|
|
|
{ |
|
43
|
|
|
$id = $this->getGateway()->insert(new CreateStruct([ |
|
44
|
|
|
'ownerId' => 14, |
|
45
|
|
|
'isPending' => true, |
|
46
|
|
|
'type' => 'Workflow:Review', |
|
47
|
|
|
'created' => 1529995052, |
|
48
|
|
|
'data' => null, |
|
49
|
|
|
])); |
|
50
|
|
|
|
|
51
|
|
|
$data = $this->loadNotification($id); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals([ |
|
54
|
|
|
'id' => "$id", |
|
55
|
|
|
'owner_id' => '14', |
|
56
|
|
|
'is_pending' => 1, |
|
57
|
|
|
'type' => 'Workflow:Review', |
|
58
|
|
|
'created' => '1529995052', |
|
59
|
|
|
'data' => 'null', |
|
60
|
|
|
], $data); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::getNotificationById() |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testGetNotificationById() |
|
67
|
|
|
{ |
|
68
|
|
|
$data = $this->getGateway()->getNotificationById(self::EXISTING_NOTIFICATION_ID); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals([ |
|
71
|
|
|
self::EXISTING_NOTIFICATION_DATA, |
|
72
|
|
|
], $data); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::updateNotification() |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testUpdateNotification() |
|
79
|
|
|
{ |
|
80
|
|
|
$notification = new Notification([ |
|
81
|
|
|
'id' => self::EXISTING_NOTIFICATION_ID, |
|
82
|
|
|
'ownerId' => 14, |
|
83
|
|
|
'isPending' => false, |
|
84
|
|
|
'type' => 'Workflow:Review', |
|
85
|
|
|
'created' => 1529995052, |
|
86
|
|
|
'data' => null, |
|
87
|
|
|
]); |
|
88
|
|
|
|
|
89
|
|
|
$this->getGateway()->updateNotification($notification); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertEquals([ |
|
92
|
|
|
'id' => (string) self::EXISTING_NOTIFICATION_ID, |
|
93
|
|
|
'owner_id' => '14', |
|
94
|
|
|
'is_pending' => '0', |
|
95
|
|
|
'type' => 'Workflow:Review', |
|
96
|
|
|
'created' => '1529995052', |
|
97
|
|
|
'data' => null, |
|
98
|
|
|
], $this->loadNotification(self::EXISTING_NOTIFICATION_ID)); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::countUserNotifications() |
|
103
|
|
|
*/ |
|
104
|
|
|
public function testCountUserNotifications() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertEquals(5, $this->getGateway()->countUserNotifications( |
|
107
|
|
|
self::EXISTING_NOTIFICATION_DATA['owner_id'] |
|
108
|
|
|
)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::countUserPendingNotifications() |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testCountUserPendingNotifications() |
|
115
|
|
|
{ |
|
116
|
|
|
$this->assertEquals(3, $this->getGateway()->countUserPendingNotifications( |
|
117
|
|
|
self::EXISTING_NOTIFICATION_DATA['owner_id']) |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::loadUserNotifications() |
|
123
|
|
|
*/ |
|
124
|
|
|
public function testLoadUserNotifications() |
|
125
|
|
|
{ |
|
126
|
|
|
$userId = 14; |
|
127
|
|
|
$offset = 1; |
|
128
|
|
|
$limit = 3; |
|
129
|
|
|
|
|
130
|
|
|
$results = $this->getGateway()->loadUserNotifications($userId, $offset, $limit); |
|
131
|
|
|
|
|
132
|
|
|
$this->assertEquals([ |
|
133
|
|
|
[ |
|
134
|
|
|
'id' => '4', |
|
135
|
|
|
'owner_id' => '14', |
|
136
|
|
|
'is_pending' => 1, |
|
137
|
|
|
'type' => 'Workflow:Review', |
|
138
|
|
|
'created' => '1530005852', |
|
139
|
|
|
'data' => null, |
|
140
|
|
|
], |
|
141
|
|
|
[ |
|
142
|
|
|
'id' => '3', |
|
143
|
|
|
'owner_id' => '14', |
|
144
|
|
|
'is_pending' => 0, |
|
145
|
|
|
'type' => 'Workflow:Reject', |
|
146
|
|
|
'created' => '1530002252', |
|
147
|
|
|
'data' => null, |
|
148
|
|
|
], |
|
149
|
|
|
[ |
|
150
|
|
|
'id' => '2', |
|
151
|
|
|
'owner_id' => '14', |
|
152
|
|
|
'is_pending' => 0, |
|
153
|
|
|
'type' => 'Workflow:Approve', |
|
154
|
|
|
'created' => '1529998652', |
|
155
|
|
|
'data' => null, |
|
156
|
|
|
], |
|
157
|
|
|
], $results); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase::delete() |
|
162
|
|
|
*/ |
|
163
|
|
|
public function testDelete() |
|
164
|
|
|
{ |
|
165
|
|
|
$this->getGateway()->delete(self::EXISTING_NOTIFICATION_ID); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEmpty($this->loadNotification(self::EXISTING_NOTIFICATION_ID)); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Return a ready to test DoctrineStorage gateway. |
|
172
|
|
|
* |
|
173
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function getGateway(): DoctrineDatabase |
|
176
|
|
|
{ |
|
177
|
|
|
return new DoctrineDatabase( |
|
178
|
|
|
$this->getDatabaseHandler()->getConnection() |
|
179
|
|
|
); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
View Code Duplication |
private function loadNotification(int $id): array |
|
183
|
|
|
{ |
|
184
|
|
|
$data = $this->connection |
|
185
|
|
|
->executeQuery('SELECT * FROM eznotification WHERE id = :id', ['id' => $id]) |
|
186
|
|
|
->fetch(PDO::FETCH_ASSOC); |
|
187
|
|
|
|
|
188
|
|
|
return is_array($data) ? $data : []; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|