Skip to content

Commit 2506eaf

Browse files
committed
fix: tests
1 parent 5b41ba4 commit 2506eaf

23 files changed

+345
-333
lines changed

_config/forum.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ Name: silverstripe-forum
44
SilverStripe\Security\Member:
55
extensions:
66
- FullscreenInteractive\SilverStripe\Forum\Extensions\ForumMemberExtension
7-
SilverStripe\Forum\Model\Post:
8-
extensions:
9-
- FullscreenInteractive\SilverStripe\Forum\Extensions\ForumSpamPostExtension

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"lint:fix": "phpcbf src/ tests/",
3030
"phpstan": "phpstan analyse -c phpstan.neon",
3131
"syntax-check": "find src/ tests/ -type f -name '*.php' -exec php -l {} \\;",
32-
"test": "phpunit tests"
32+
"test": "phpunit tests",
33+
"coverage": "phpunit tests --coverage-text"
3334
},
3435
"extra": {
3536
"branch-alias": {

src/Email/ForumNotifyModeratorEmail.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ public function setModerator(Member $moderator): self
4646
public function send(): void
4747
{
4848
if ($this->startingThread) {
49-
$this->setSubject('New thread "' . $this->thread->Title . '" in forum [' . $this->thread->Forum->Title . ']');
49+
$this->setSubject(sprintf(
50+
'New thread "%s" in forum [%s]', $this->thread->Title, $this->thread->Forum->Title
51+
));
5052
} else {
51-
$this->setSubject('New post "' . $this->post->Title . '" in forum [' . $this->thread->Forum->Title . ']');
53+
$this->setSubject(sprintf(
54+
'New post "%s" in forum [%s]', $this->post->Title, $this->thread->Forum->Title
55+
));
5256
}
57+
5358
$this->setHTMLTemplate('email/ForumMember_NotifyModerator');
5459
$this->addData([
5560
'NewThread' => $this->startingThread,

src/Email/ForumSubscriptionEmail.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FullscreenInteractive\SilverStripe\Forum\Email;
44

5+
use Exception;
56
use SilverStripe\Control\Director;
67
use SilverStripe\Control\Email\Email;
78
use FullscreenInteractive\SilverStripe\Forum\Model\ForumThreadSubscription;
@@ -38,11 +39,16 @@ public function send(): void
3839
$from = Email::config()->get('admin_email');
3940
}
4041

42+
if (!$this->post || !$this->subscription) {
43+
throw new Exception('Post and subscription are required');
44+
}
45+
4146
$this->setFrom($from);
4247
$this->setTo($this->subscription->Member()->Email);
4348
$this->setSubject(_t('Post.NEWREPLY', 'New reply for {title}', [
4449
'title' => $this->post->Title,
4550
]));
51+
4652
$this->setHTMLTemplate('email/ForumMember_TopicNotification');
4753
$this->setData($this->post);
4854
$this->addData('Nickname', $this->subscription->Member()->Nickname);

src/Extensions/ForumMemberExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function IsSuspended(): bool
295295
{
296296
$suspendedUntil = $this->owner->dbObject('SuspendedUntil');
297297
if ($suspendedUntil && $suspendedUntil->exists()) {
298-
return $suspendedUntil->isInThePast();
298+
return !$suspendedUntil->InPast();
299299
}
300300

301301
return false;

src/Extensions/ForumSpamPostExtension.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Form/ForumRegistrationForm.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public function __construct($controller, $name)
6060
if (ForumHolder::config()->get('use_spamprotection_on_register')) {
6161
$this->enableSpamProtection();
6262
}
63-
6463
}
6564

6665

@@ -93,8 +92,7 @@ public function doRegister($data, $form)
9392
$this->request->getSession()->set("FormInfo.Form_RegistrationForm.data", $data);
9493
return $this->redirectBack();
9594
}
96-
} elseif (
97-
$this->getForumHolder()->OpenIDAvailable()
95+
} elseif ($this->getForumHolder()->OpenIDAvailable()
9896
&& isset($data['IdentityURL'])
9997
&& ($member = Member::get()->filter('IdentityURL', $data['IdentityURL'])->first())
10098
) {

src/Form/PostMessageForm.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,14 @@ public function doPostMessageForm($data, $form)
218218
$obj->write();
219219
}
220220
} elseif ($isSubscribed) {
221-
// See if the member wanted to remove themselves
222-
ForumThreadSubscription::get()->filter([
221+
$subscriptions = ForumThreadSubscription::get()->filter([
223222
'ThreadID' => $thread->ID,
224223
'MemberID' => $member->ID
225-
])->delete();
224+
]);
225+
226+
foreach ($subscriptions as $subscription) {
227+
$subscription->delete();
228+
}
226229
}
227230

228231
// Send any notifications that need to be sent

src/Model/ForumThreadSubscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function notify(Post $post)
7070
try {
7171
$email->send();
7272
} catch (Exception $e) {
73-
Injector::inst()->get(LoggerInterface::class)->error($e->getMessage(), $e);
73+
Injector::inst()->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
7474
}
7575
}
7676
}

src/PageTypes/Forum.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ public function getLatestPost()
310310
*/
311311
public function getNumTopics()
312312
{
313-
return ForumThread::get()->filter(["ForumID" => $this->ID])->count();
313+
$threadIDs = Post::get()->filter([
314+
'ForumID' => $this->ID,
315+
'Author.ForumStatus' => 'Normal',
316+
])->columnUnique('ThreadID');
317+
318+
return count($threadIDs);
314319
}
315320

316321
/**
@@ -319,8 +324,8 @@ public function getNumTopics()
319324
public function getNumPosts()
320325
{
321326
return Post::get()->filter([
322-
"ForumID" => $this->ID,
323-
"Author.ForumStatus" => "Normal"
327+
'ForumID' => $this->ID,
328+
'Author.ForumStatus' => 'Normal',
324329
])->count();
325330
}
326331

@@ -330,10 +335,12 @@ public function getNumPosts()
330335
*/
331336
public function getNumAuthors(): int
332337
{
333-
return Post::get()->filter([
334-
"ForumID" => $this->ID,
335-
"Author.ForumStatus" => "Normal"
336-
])->distinct("AuthorID")->count();
338+
$authorIDs = Post::get()->filter([
339+
'ForumID' => $this->ID,
340+
'Author.ForumStatus' => 'Normal',
341+
])->columnUnique('AuthorID');
342+
343+
return count($authorIDs);
337344
}
338345

339346
/**
@@ -373,23 +380,26 @@ public function getTopics(): ?PaginatedList
373380
->addOrderBy(['"PostMax"."PostCreatedMax" DESC', '"PostMax"."PostIDMax" DESC'])
374381
->setDistinct(false);
375382

376-
// And return the results
383+
if (!$threads->exists()) {
384+
return null;
385+
}
386+
377387
return PaginatedList::create($threads);
378388
}
379389

380390

381391

382392
/*
383393
* Returns the Sticky Threads
384-
* @param boolean $include_global Include Global Sticky Threads in the results (default: true)
394+
* @param bool $include_global Include Global Sticky Threads in the results (default: true)
385395
* @return DataList
386396
*/
387-
public function getStickyTopics($include_global = true)
397+
public function getStickyTopics(bool $includeGlobalSticky = true)
388398
{
389399
// Get Threads that are sticky & in this forum
390400
$where = '("ForumThread"."ForumID" = ' . $this->ID . ' AND "ForumThread"."IsSticky" = 1)';
391401
// Get Threads that are globally sticky
392-
if ($include_global) {
402+
if ($includeGlobalSticky) {
393403
$where .= ' OR ("ForumThread"."IsGlobalSticky" = 1)';
394404
}
395405

0 commit comments

Comments
 (0)