Skip to content

Commit

Permalink
Fix Reminder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh4 committed Feb 18, 2021
1 parent d3f7c87 commit 6ae39c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion models/CalendarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ public function getReminderUserQuery()
case static::PARTICIPATION_MODE_ALL:
return $this->participation->findParticipants([
CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED,
CalendarEntryParticipant::PARTICIPATION_STATE_MAYBE])->union(User::find()->where(['id' => $this->content->container->id]));
CalendarEntryParticipant::PARTICIPATION_STATE_MAYBE])
->union(User::find()->where(['id' => $this->content->container->id]));

}
}
Expand Down
20 changes: 19 additions & 1 deletion tests/codeception/unit/reminder/ReminderProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace humhub\modules\calendar\tests\codeception\unit\reminder;

use humhub\modules\calendar\interfaces\CalendarService;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\models\reminder\ReminderService;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\notifications\Remind;
use humhub\modules\content\models\Content;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
Expand Down Expand Up @@ -92,6 +94,7 @@ public function testDisableUserEntryLevelReminderLevel()

// Entry begins exactly in one hour
$entry = $this->createEntry((new DateTime)->add(new DateInterval('PT1H')), null, 'Test', $space);
$entry->updateAttributes(['participation_mode' => CalendarEntryParticipation::PARTICIPATION_MODE_NONE]);

// Set a global reminder
$globalReminder = CalendarReminder::initGlobalDefault(CalendarReminder::UNIT_HOUR, 1);
Expand Down Expand Up @@ -119,6 +122,13 @@ public function testDisableUserEntryLevelReminderLevel()
$this->assertHasNoNotification(Remind::class, $entry, $entry->content->createdBy->id, 1);
}

protected function createEntry($from, $days, $title, $container = null, $visibility = Content::VISIBILITY_PUBLIC)
{
$entry = parent::createEntry($from, $days, $title, $container, $visibility);
$entry->updateAttributes(['participation_mode' => CalendarEntryParticipation::PARTICIPATION_MODE_NONE]);
return $entry;
}

/**
* This test makes sure that if there are two matching user entry reminder only one will sent out a reminder, but both will
* be invalidated.
Expand Down Expand Up @@ -435,6 +445,9 @@ public function testSentReminderToNonSpaceMemberParticipant()
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

$entry->setParticipationStatus(User::findOne(['id' => 1]));
$entry->setParticipationStatus(User::findOne(['id' => 2]));
$entry->setParticipationStatus(User::findOne(['id' => 3]));
$entry->setParticipationStatus(User::findOne(['id' => 4]));

// Check Only sent to not declined user
Expand Down Expand Up @@ -481,6 +494,10 @@ public function testSingleGlobalReminderOnSpaceParticipationAll()
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

$entry->setParticipationStatus(User::findOne(['id' => 1]));
$entry->setParticipationStatus(User::findOne(['id' => 2]));
$entry->setParticipationStatus(User::findOne(['id' => 3]));

// Check Only sent to not declined user
(new ReminderService())->sendAllReminder();

Expand Down Expand Up @@ -516,7 +533,8 @@ public function testSingleGlobalReminderOnSpaceParticipationAllDeclined()
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

// User2 declines
$entry->setParticipationStatus(User::findOne(['id' => 1]));
$entry->setParticipationStatus(User::findOne(['id' => 2]));
$entry->setParticipationStatus(User::findOne(['id' => 3]), CalendarEntryParticipant::PARTICIPATION_STATE_DECLINED);

(new ReminderService())->sendAllReminder();
Expand Down
10 changes: 0 additions & 10 deletions tests/codeception/unit/reminder/ReminderUserQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

namespace humhub\modules\calendar\tests\codeception\unit\reminder;

use humhub\modules\calendar\interfaces\CalendarService;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\models\reminder\ReminderService;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\notifications\Remind;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use Yii;
use calendar\CalendarUnitTest;
use DateInterval;
use DateTime;
use humhub\modules\calendar\Events;
use humhub\modules\calendar\models\reminder\CalendarReminder;
use humhub\modules\calendar\models\reminder\CalendarReminderSent;

class ReminderUserQueryTest extends CalendarUnitTest
{
Expand Down

0 comments on commit 6ae39c2

Please sign in to comment.