mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
notification: add test for unread consistency
This commit is contained in:
parent
bd3919efcb
commit
700bb02374
@ -92,7 +92,7 @@ class Notification
|
||||
public function addUnreadBy(User $user): self
|
||||
{
|
||||
if (!$this->unreadBy->contains($user)) {
|
||||
$this->unreadBy->add($user);
|
||||
$this->unreadBy[] = $user;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -136,6 +136,11 @@ class Notification
|
||||
return $this->sender;
|
||||
}
|
||||
|
||||
public function getUnreadBy(): Collection
|
||||
{
|
||||
return $this->unreadBy;
|
||||
}
|
||||
|
||||
public function isReadBy(User $user): bool
|
||||
{
|
||||
return !$this->unreadBy->contains($user);
|
||||
@ -154,7 +159,7 @@ class Notification
|
||||
public function removeAddressee(User $addressee): self
|
||||
{
|
||||
$this->addressees->removeElement($addressee);
|
||||
$this->unreadBy->removeElement($addressee);
|
||||
$this->removeUnreadBy($addressee);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class NotificationType extends AbstractType
|
||||
'class' => User::class,
|
||||
'choice_label' => 'label',
|
||||
'multiple' => true,
|
||||
'by_reference' => true,
|
||||
])
|
||||
->add('message', ChillTextareaType::class, [
|
||||
'required' => false,
|
||||
|
23
src/Bundle/ChillMainBundle/Tests/Entity/NotificationTest.php
Normal file
23
src/Bundle/ChillMainBundle/Tests/Entity/NotificationTest.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
public function testAddAddresseeStoreAnUread()
|
||||
{
|
||||
$notification = new Notification();
|
||||
$notification->addAddressee($user1 = new User());
|
||||
$notification->addAddressee($user2 = new User());
|
||||
|
||||
$this->assertCount(2, $notification->getAddressees());
|
||||
$this->assertCount(2, $notification->getUnreadBy());
|
||||
$this->assertContains($user1, $notification->getUnreadBy()->toArray());
|
||||
$this->assertContains($user2, $notification->getUnreadBy()->toArray());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user