Skip to content

Commit f14a03f

Browse files
committed
fix: avatar return string prevented saving comments in some cases
1 parent 01d0ca4 commit f14a03f

File tree

5 files changed

+62
-58
lines changed

5 files changed

+62
-58
lines changed

lib/Storage.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,14 @@ public function createComment(
4949
string $createdAt,
5050
string | null $updatedAt
5151
): Content {
52-
53-
$avatarHandler = new AvatarHandler();
54-
$avatar = $avatarHandler->getAvatar($authorAvatar, $authorName);
55-
5652
return new Content([
5753
'id' => $id,
5854
'pageUuid' => $pageUuid,
5955
'parentId' => $parentId,
6056
'type' => $type,
6157
'content' => $content,
6258
'authorName' => $authorName,
63-
'authorAvatar' => $avatar,
59+
'authorAvatar' => $authorAvatar,
6460
'authorEmail' => $authorEmail,
6561
'authorUrl' => $authorUrl,
6662
'published' => $published,

lib/StorageMarkdown.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,22 @@ public function findPageOfComment(string $commentId): ?Page
154154
*/
155155
public function convertToStructure(Obj|Collection|Structure $databaseResults): Structure
156156
{
157+
$avatarHandler = new AvatarHandler();
158+
157159
$comments = [];
158160
$databaseResults = ($databaseResults instanceof Obj) ? [$databaseResults] : $databaseResults;
159161

160162
foreach ($databaseResults as $databaseResult) {
163+
$avatar = $avatarHandler->getAvatar($databaseResult->author_avatar, $databaseResult->author_name);
164+
161165
$comment = $this->createComment(
162166
id: $databaseResult->id,
163167
pageUuid: $databaseResult->page_uuid,
164168
parentId: $databaseResult->parent_id,
165169
type: $databaseResult->type,
166170
content: $databaseResult->content,
167171
authorName: $databaseResult->author_name,
168-
authorAvatar: $databaseResult->author_avatar,
172+
authorAvatar: $avatar,
169173
authorEmail: $databaseResult->author_email,
170174
authorUrl: $databaseResult->author_url,
171175
published: $databaseResult->published,

lib/StorageSqlite.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,22 @@ public function deleteComments(string $type): bool
121121
*/
122122
public function convertToStructure(Obj|Collection|Structure $databaseResults): Structure
123123
{
124+
$avatarHandler = new AvatarHandler();
125+
124126
$comments = [];
125127
$databaseResults = ($databaseResults instanceof Obj) ? [$databaseResults] : $databaseResults;
126128

127129
foreach ($databaseResults as $databaseResult) {
130+
$avatar = $avatarHandler->getAvatar($databaseResult->author_avatar, $databaseResult->author_name);
131+
128132
$comment = $this->createComment(
129133
id: $databaseResult->id,
130134
pageUuid: $databaseResult->page_uuid,
131135
parentId: $databaseResult->parent_id,
132136
type: $databaseResult->type,
133137
content: $databaseResult->content,
134138
authorName: $databaseResult->author_name,
135-
authorAvatar: $databaseResult->author_avatar,
139+
authorAvatar: $avatar,
136140
authorEmail: $databaseResult->author_email,
137141
authorUrl: $databaseResult->author_url,
138142
published: $databaseResult->published,

tests/KommentReceiverTest.php

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function testValidateFieldsAuthorUrlEmpty()
6969

7070

7171
/**
72-
* @group validation
73-
* @testdox validateFields - should return invalid email
74-
*/
72+
* @group validation
73+
* @testdox validateFields - should return invalid email
74+
*/
7575
public function testValidateFieldsEmail()
7676
{
7777
$receiverClass = new KommentReceiver();
@@ -88,9 +88,9 @@ public function testValidateFieldsEmail()
8888
}
8989

9090
/**
91-
* @group validation
92-
* @testdox validateFields - should return invalid author
93-
*/
91+
* @group validation
92+
* @testdox validateFields - should return invalid author
93+
*/
9494
public function testValidateFieldsAuthor()
9595
{
9696
$receiverClass = new KommentReceiver();
@@ -107,9 +107,9 @@ public function testValidateFieldsAuthor()
107107
}
108108

109109
/**
110-
* @group validation
111-
* @testdox validateFields - should return invalid author
112-
*/
110+
* @group validation
111+
* @testdox validateFields - should return invalid author
112+
*/
113113
public function testValidateFieldsComment()
114114
{
115115
$receiverClass = new KommentReceiver();
@@ -126,9 +126,9 @@ public function testValidateFieldsComment()
126126
}
127127

128128
/**
129-
* @group validation
130-
* @testdox validateFields - should return invalid fields
131-
*/
129+
* @group validation
130+
* @testdox validateFields - should return invalid fields
131+
*/
132132
public function testValidateFieldsMultiple()
133133
{
134134
$receiverClass = new KommentReceiver();
@@ -141,13 +141,13 @@ public function testValidateFieldsMultiple()
141141
];
142142

143143
$result = $receiverClass->validateFields($fields);
144-
$this->assertEquals(['email','comment'], $result);
144+
$this->assertEquals(['email', 'comment'], $result);
145145
}
146146

147147
/**
148-
* @group spam
149-
* @testdox getSpamlevel - should return level 0
150-
*/
148+
* @group spam
149+
* @testdox getSpamlevel - should return level 0
150+
*/
151151
public function testGetSpamlevelZero()
152152
{
153153
$receiverClass = new KommentReceiver();
@@ -163,9 +163,9 @@ public function testGetSpamlevelZero()
163163
}
164164

165165
/**
166-
* @group spam
167-
* @testdox getSpamlevel - should return level 12
168-
*/
166+
* @group spam
167+
* @testdox getSpamlevel - should return level 12
168+
*/
169169
public function testGetSpamlevel12()
170170
{
171171
$receiverClass = new KommentReceiver();
@@ -181,9 +181,9 @@ public function testGetSpamlevel12()
181181
}
182182

183183
/**
184-
* @group spam
185-
* @testdox getSpamlevel - should return level 14
186-
*/
184+
* @group spam
185+
* @testdox getSpamlevel - should return level 14
186+
*/
187187
public function testGetSpamlevel14()
188188
{
189189
$receiverClass = new KommentReceiver();
@@ -199,9 +199,9 @@ public function testGetSpamlevel14()
199199
}
200200

201201
/**
202-
* @group spam
203-
* @testdox getSpamlevel - should return level 60
204-
*/
202+
* @group spam
203+
* @testdox getSpamlevel - should return level 60
204+
*/
205205
public function testGetSpamlevel60()
206206
{
207207
$receiverClass = new KommentReceiver();
@@ -213,13 +213,13 @@ public function testGetSpamlevel60()
213213
];
214214

215215
$result = $receiverClass->getSpamlevel($fields, $page);
216-
$this->assertEquals(60, $result);
216+
$this->assertEquals(80, $result);
217217
}
218218

219219
/**
220-
* @group spam
221-
* @testdox getSpamlevel - should return level 80
222-
*/
220+
* @group spam
221+
* @testdox getSpamlevel - should return level 80
222+
*/
223223
public function testGetSpamlevel80()
224224
{
225225
$receiverClass = new KommentReceiver();
@@ -235,9 +235,9 @@ public function testGetSpamlevel80()
235235
}
236236

237237
/**
238-
* @group spam
239-
* @testdox getSpamlevel - should return level 100
240-
*/
238+
* @group spam
239+
* @testdox getSpamlevel - should return level 100
240+
*/
241241
public function testGetSpamlevel100()
242242
{
243243
$receiverClass = new KommentReceiver();
@@ -253,9 +253,9 @@ public function testGetSpamlevel100()
253253
}
254254

255255
/**
256-
* @group spam
257-
* @testdox getSpamlevel - should return level 100
258-
*/
256+
* @group spam
257+
* @testdox getSpamlevel - should return level 100
258+
*/
259259
public function testGetSpamlevelMax100()
260260
{
261261
$receiverClass = new KommentReceiver();
@@ -271,9 +271,9 @@ public function testGetSpamlevelMax100()
271271
}
272272

273273
/**
274-
* @group moderation
275-
* @testdox autoPublish - should auto publish by email
276-
*/
274+
* @group moderation
275+
* @testdox autoPublish - should auto publish by email
276+
*/
277277
public function testAutoPublish()
278278
{
279279
$receiverClass = new KommentReceiver(autoPublish: ['[email protected]']);
@@ -283,9 +283,9 @@ public function testAutoPublish()
283283
}
284284

285285
/**
286-
* @group moderation
287-
* @testdox autoPublish - should auto publish by verification
288-
*/
286+
* @group moderation
287+
* @testdox autoPublish - should auto publish by verification
288+
*/
289289
public function testAutoPublishVerified()
290290
{
291291
$receiverClass = new KommentReceiver(autoPublishVerified: true);
@@ -295,9 +295,9 @@ public function testAutoPublishVerified()
295295
}
296296

297297
/**
298-
* @group moderation
299-
* @testdox autoPublish - should not auto publish
300-
*/
298+
* @group moderation
299+
* @testdox autoPublish - should not auto publish
300+
*/
301301
public function testAutoPublishShouldNot()
302302
{
303303
$receiverClass = new KommentReceiver();
@@ -307,9 +307,9 @@ public function testAutoPublishShouldNot()
307307
}
308308

309309
/**
310-
* @group moderation
311-
* @testdox getAvatarFromEmail - should return url string
312-
*/
310+
* @group moderation
311+
* @testdox getAvatarFromEmail - should return url string
312+
*/
313313
public function testGetAvatarFromEmail()
314314
{
315315
$receiverClass = new KommentReceiver();
@@ -320,9 +320,9 @@ public function testGetAvatarFromEmail()
320320
}
321321

322322
/**
323-
* @group moderation
324-
* @testdox createSafeString - should return safe string
325-
*/
323+
* @group moderation
324+
* @testdox createSafeString - should return safe string
325+
*/
326326
public function testCreateSafeString()
327327
{
328328
$receiverClass = new KommentReceiver();

tests/KommentsModerationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
final class KommentsModerationTest extends TestCaseMocked
77
{
8-
private $avatar = '<img class="u-photo" src="https://api.dicebear.com/9.x/pixel-art/png?seed=AuthorName" alt="Author Name" />';
8+
private $avatar = 'https://api.dicebear.com/9.x/pixel-art/png?seed=AuthorName';
99

1010
public function setUp(): void
1111
{

0 commit comments

Comments
 (0)