1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Profiles\Tests\Engine; |
4
|
|
|
|
5
|
|
|
use Backend\Modules\Profiles\DataFixtures\LoadProfilesGroup; |
6
|
|
|
use Backend\Modules\Profiles\DataFixtures\LoadProfilesGroupData; |
7
|
|
|
use Backend\Modules\Profiles\DataFixtures\LoadProfilesProfile; |
8
|
|
|
use Backend\Modules\Profiles\Engine\Model; |
9
|
|
|
use Backend\Core\Tests\BackendWebTestCase; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
11
|
|
|
|
12
|
|
|
final class ModelTest extends BackendWebTestCase |
13
|
|
|
{ |
14
|
|
|
public function testPasswordGetsEncrypted(): void |
15
|
|
|
{ |
16
|
|
|
$encryptedPassword = Model::encryptPassword(LoadProfilesProfile::PROFILES_PROFILE_PASSWORD); |
17
|
|
|
|
18
|
|
|
self::assertTrue(password_verify(LoadProfilesProfile::PROFILES_PROFILE_PASSWORD, $encryptedPassword)); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testInsertingProfile(): void |
22
|
|
|
{ |
23
|
|
|
$profileData = LoadProfilesProfile::getProfileArray( |
24
|
|
|
LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_DATA |
25
|
|
|
); |
26
|
|
|
$profileId = Model::insert($profileData); |
27
|
|
|
$addedProfile = Model::get($profileId); |
28
|
|
|
|
29
|
|
|
self::assertEquals($profileId, $addedProfile['id']); |
30
|
|
|
self::assertEquals($profileData['email'], $addedProfile['email']); |
31
|
|
|
self::assertEquals($profileData['status'], $addedProfile['status']); |
32
|
|
|
self::assertEquals($profileData['display_name'], $addedProfile['display_name']); |
33
|
|
|
self::assertEquals($profileData['url'], $addedProfile['url']); |
34
|
|
|
|
35
|
|
|
$addedProfileByEmail = Model::getByEmail($profileData['email']); |
36
|
|
|
|
37
|
|
|
self::assertEquals($profileId, $addedProfileByEmail['id']); |
38
|
|
|
self::assertEquals($profileData['email'], $addedProfileByEmail['email']); |
39
|
|
|
self::assertEquals($profileData['status'], $addedProfileByEmail['status']); |
40
|
|
|
self::assertEquals($profileData['display_name'], $addedProfileByEmail['display_name']); |
41
|
|
|
self::assertEquals($profileData['url'], $addedProfileByEmail['url']); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGettingUrl(Client $client): void |
45
|
|
|
{ |
46
|
|
|
$firstUrl = Model::getUrl(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_DISPLAY_NAME); |
47
|
|
|
self::assertEquals(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_URL, $firstUrl); |
48
|
|
|
|
49
|
|
|
$this->loadFixtures($client, [LoadProfilesProfile::class]); |
50
|
|
|
|
51
|
|
|
$secondUrl = Model::getUrl(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_DISPLAY_NAME); |
52
|
|
|
self::assertEquals(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_URL . '-2', $secondUrl); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testIfProfileExists(Client $client): void |
56
|
|
|
{ |
57
|
|
|
$this->loadFixtures($client, [LoadProfilesProfile::class]); |
58
|
|
|
|
59
|
|
|
self::assertTrue(Model::exists(LoadProfilesProfile::getProfileActiveId())); |
60
|
|
|
self::assertTrue(Model::existsByEmail(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_EMAIL)); |
61
|
|
|
self::assertTrue(Model::existsDisplayName(LoadProfilesProfile::PROFILES_ACTIVE_PROFILE_DISPLAY_NAME)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testUpdatingProfile(Client $client): void |
65
|
|
|
{ |
66
|
|
|
$this->loadFixtures($client, [LoadProfilesProfile::class]); |
67
|
|
|
|
68
|
|
|
$updatedProfileData = [ |
69
|
|
|
'email' => '[email protected]', |
70
|
|
|
'password' => Model::encryptPassword(LoadProfilesProfile::PROFILES_PROFILE_PASSWORD), |
71
|
|
|
'status' => 'blocked', |
72
|
|
|
'display_name' => 'Fork CMS 2', |
73
|
|
|
'url' => 'fork-cms-2', |
74
|
|
|
'registered_on' => '2018-03-05 10:22:34', |
75
|
|
|
'last_login' => '2018-03-05 10:16:19', |
76
|
|
|
]; |
77
|
|
|
$profileId = LoadProfilesProfile::getProfileActiveId(); |
78
|
|
|
|
79
|
|
|
self::assertEquals(1, Model::update($profileId, $updatedProfileData)); |
80
|
|
|
|
81
|
|
|
$updatedProfile = Model::get($profileId); |
82
|
|
|
|
83
|
|
|
self::assertEquals($profileId, $updatedProfile['id']); |
84
|
|
|
self::assertEquals($updatedProfileData['email'], $updatedProfile['email']); |
85
|
|
|
self::assertEquals($updatedProfileData['status'], $updatedProfile['status']); |
86
|
|
|
self::assertEquals($updatedProfileData['display_name'], $updatedProfile['display_name']); |
87
|
|
|
self::assertEquals($updatedProfileData['url'], $updatedProfile['url']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testDeletingProfile(Client $client): void |
91
|
|
|
{ |
92
|
|
|
$this->loadFixtures($client, [LoadProfilesProfile::class]); |
93
|
|
|
Model::delete(LoadProfilesProfile::getProfileActiveId()); |
94
|
|
|
$deletedProfile = Model::get(LoadProfilesProfile::getProfileActiveId()); |
95
|
|
|
|
96
|
|
|
self::assertEquals('deleted', $deletedProfile['status']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testSettingSettings(Client $client): void |
100
|
|
|
{ |
101
|
|
|
$this->loadFixtures($client, [LoadProfilesProfile::class]); |
102
|
|
|
$profileId = LoadProfilesProfile::getProfileActiveId(); |
103
|
|
|
|
104
|
|
|
Model::setSetting($profileId, 'my_setting', 'My setting\'s value'); |
105
|
|
|
self::assertEquals('My setting\'s value', Model::getSetting($profileId, 'my_setting')); |
106
|
|
|
|
107
|
|
|
Model::setSetting($profileId, 'my_setting', 'My updated value'); |
108
|
|
|
self::assertEquals('My updated value', Model::getSetting($profileId, 'my_setting')); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testInsertingGroup(Client $client): void |
112
|
|
|
{ |
113
|
|
|
$groupData = LoadProfilesGroup::PROFILES_GROUP_DATA; |
114
|
|
|
$groupId = Model::insertGroup($groupData); |
115
|
|
|
|
116
|
|
|
$addedGroup = Model::getGroup($groupId); |
117
|
|
|
|
118
|
|
|
self::assertEquals($groupId, $addedGroup['id']); |
119
|
|
|
self::assertEquals($groupData['name'], $addedGroup['name']); |
120
|
|
|
|
121
|
|
|
$groups = Model::getGroups(); |
122
|
|
|
|
123
|
|
|
self::assertContains($groupData['name'], $groups); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testUpdatingGroup(Client $client): void |
127
|
|
|
{ |
128
|
|
|
$this->loadFixtures($client, [LoadProfilesGroup::class]); |
129
|
|
|
$updatedGroupData = [ |
130
|
|
|
'name' => 'My updated Fork CMS group', |
131
|
|
|
]; |
132
|
|
|
$groupId = LoadProfilesGroup::getGroupId(); |
133
|
|
|
self::assertEquals(1, Model::updateGroup($groupId, $updatedGroupData)); |
|
|
|
|
134
|
|
|
|
135
|
|
|
$updatedGroup = Model::getGroup($groupId); |
|
|
|
|
136
|
|
|
|
137
|
|
|
self::assertEquals($groupId, $updatedGroup['id']); |
138
|
|
|
self::assertEquals($updatedGroupData['name'], $updatedGroup['name']); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testIfGroupExists(Client $client): void |
142
|
|
|
{ |
143
|
|
|
$this->loadFixtures($client, [LoadProfilesGroup::class]); |
144
|
|
|
self::assertTrue(Model::existsGroup(LoadProfilesGroup::getGroupId())); |
|
|
|
|
145
|
|
|
self::assertTrue(Model::existsGroupName(LoadProfilesGroup::PROFILES_GROUP_NAME)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testDeletingGroup(Client $client): void |
149
|
|
|
{ |
150
|
|
|
$this->loadFixtures( |
151
|
|
|
$client, |
152
|
|
|
[ |
153
|
|
|
LoadProfilesProfile::class, |
154
|
|
|
LoadProfilesGroup::class, |
155
|
|
|
LoadProfilesGroupData::class, |
156
|
|
|
] |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
self::assertNotEmpty(Model::getGroup(LoadProfilesGroup::getGroupId())); |
|
|
|
|
160
|
|
|
self::assertNotEmpty(Model::getProfileGroup(LoadProfilesGroupData::getId())); |
|
|
|
|
161
|
|
|
|
162
|
|
|
Model::deleteGroup(LoadProfilesGroup::getGroupId()); |
|
|
|
|
163
|
|
|
|
164
|
|
|
self::assertEmpty(Model::getGroup(LoadProfilesGroup::getGroupId())); |
165
|
|
|
self::assertEmpty(Model::getProfileGroup(LoadProfilesGroupData::getId())); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testInsertingProfileGroup(Client $client): void |
169
|
|
|
{ |
170
|
|
|
$this->loadFixtures( |
171
|
|
|
$client, |
172
|
|
|
[ |
173
|
|
|
LoadProfilesProfile::class, |
174
|
|
|
LoadProfilesGroup::class, |
175
|
|
|
] |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$profileGroupData = [ |
179
|
|
|
'profile_id' => LoadProfilesProfile::getProfileActiveId(), |
180
|
|
|
'group_id' => LoadProfilesGroup::getGroupId(), |
181
|
|
|
'starts_on' => date('Y-m-d H:i:s', LoadProfilesGroupData::getStartsOnTimestamp()), |
182
|
|
|
'expires_on' => date('Y-m-d H:i:s', LoadProfilesGroupData::getExpiresOnTimestamp()), |
183
|
|
|
]; |
184
|
|
|
|
185
|
|
|
$profileGroupId = Model::insertProfileGroup($profileGroupData); |
186
|
|
|
$addedProfileGroup = Model::getProfileGroup($profileGroupId); |
187
|
|
|
|
188
|
|
|
self::assertEquals($profileGroupId, $addedProfileGroup['id']); |
189
|
|
|
self::assertEquals($profileGroupData['profile_id'], $addedProfileGroup['profile_id']); |
190
|
|
|
self::assertEquals($profileGroupData['group_id'], $addedProfileGroup['group_id']); |
191
|
|
|
self::assertEquals(strtotime($profileGroupData['expires_on'] . '.UTC'), $addedProfileGroup['expires_on']); |
192
|
|
|
|
193
|
|
|
self::assertContains( |
194
|
|
|
[ |
195
|
|
|
'id' => (string) $profileGroupId, |
196
|
|
|
'group_id' => (string) LoadProfilesGroup::getGroupId(), |
197
|
|
|
'group_name' => LoadProfilesGroup::PROFILES_GROUP_NAME, |
198
|
|
|
'expires_on' => $profileGroupData['expires_on'], |
199
|
|
|
], |
200
|
|
|
Model::getProfileGroups(LoadProfilesProfile::getProfileActiveId()) |
201
|
|
|
); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function testUpdatingProfileGroup(Client $client): void |
205
|
|
|
{ |
206
|
|
|
$this->loadFixtures( |
207
|
|
|
$client, |
208
|
|
|
[ |
209
|
|
|
LoadProfilesProfile::class, |
210
|
|
|
LoadProfilesGroup::class, |
211
|
|
|
LoadProfilesGroupData::class, |
212
|
|
|
] |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
$updatedProfileGroupData = [ |
216
|
|
|
'profile_id' => LoadProfilesProfile::getProfileActiveId(), |
217
|
|
|
'group_id' => LoadProfilesGroup::getGroupId(), |
218
|
|
|
'expires_on' => date('Y-m-d H:i:s', LoadProfilesGroupData::getExpiresOnTimestamp() + 2), |
219
|
|
|
]; |
220
|
|
|
|
221
|
|
|
self::assertEquals(1, Model::updateProfileGroup(LoadProfilesGroupData::getId(), $updatedProfileGroupData)); |
|
|
|
|
222
|
|
|
|
223
|
|
|
$updatedProfileGroup = Model::getProfileGroup(LoadProfilesGroupData::getId()); |
|
|
|
|
224
|
|
|
|
225
|
|
|
self::assertEquals(LoadProfilesGroupData::getId(), $updatedProfileGroup['id']); |
226
|
|
|
self::assertEquals($updatedProfileGroupData['profile_id'], $updatedProfileGroup['profile_id']); |
227
|
|
|
self::assertEquals($updatedProfileGroupData['group_id'], $updatedProfileGroup['group_id']); |
228
|
|
|
self::assertEquals( |
229
|
|
|
strtotime($updatedProfileGroupData['expires_on'] . '.UTC'), |
230
|
|
|
$updatedProfileGroup['expires_on'] |
231
|
|
|
); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function testIfProfileGroupExists(Client $client): void |
235
|
|
|
{ |
236
|
|
|
$this->loadFixtures( |
237
|
|
|
$client, |
238
|
|
|
[ |
239
|
|
|
LoadProfilesProfile::class, |
240
|
|
|
LoadProfilesGroup::class, |
241
|
|
|
LoadProfilesGroupData::class, |
242
|
|
|
] |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
self::assertTrue(Model::existsProfileGroup(LoadProfilesGroupData::getId())); |
|
|
|
|
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testDeletingProfileGroup(Client $client): void |
249
|
|
|
{ |
250
|
|
|
$this->loadFixtures( |
251
|
|
|
$client, |
252
|
|
|
[ |
253
|
|
|
LoadProfilesProfile::class, |
254
|
|
|
LoadProfilesGroup::class, |
255
|
|
|
LoadProfilesGroupData::class, |
256
|
|
|
] |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
$profileGroupId = LoadProfilesGroupData::getId(); |
260
|
|
|
|
261
|
|
|
self::assertNotEmpty(Model::getProfileGroup($profileGroupId)); |
|
|
|
|
262
|
|
|
Model::deleteProfileGroup($profileGroupId); |
|
|
|
|
263
|
|
|
self::assertEmpty(Model::getProfileGroup($profileGroupId)); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|