mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Merge remote-tracking branch 'origin/master' into rector/rules-symfony
# Conflicts: # src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php # src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php
This commit is contained in:
@@ -78,6 +78,8 @@ class CenterController extends AbstractController
|
||||
|
||||
$entities = $em->getRepository(\Chill\MainBundle\Entity\Center::class)->findAll();
|
||||
|
||||
usort($entities, fn (Center $a, Center $b) => $a->getName() <=> $b->getName());
|
||||
|
||||
return $this->render('@ChillMain/Center/index.html.twig', [
|
||||
'entities' => $entities,
|
||||
]);
|
||||
|
@@ -73,7 +73,6 @@ final readonly class CronManager implements CronManagerInterface
|
||||
foreach ($orderedJobs as $job) {
|
||||
if ($job->canRun($lasts[$job->getKey()] ?? null)) {
|
||||
if (array_key_exists($job->getKey(), $lasts)) {
|
||||
|
||||
$executionData = $lasts[$job->getKey()]->getLastExecutionData();
|
||||
|
||||
$this->entityManager
|
||||
|
@@ -122,7 +122,6 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
foreach ($helper->getUserPickers() as $name => [
|
||||
'label' => $label, 'options' => $opts
|
||||
]) {
|
||||
|
||||
$userPickersBuilder->add(
|
||||
$name,
|
||||
PickUserDynamicType::class,
|
||||
@@ -136,7 +135,6 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
|
||||
$builder->add($userPickersBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function buildCheckboxChoices(array $choices, array $trans = []): array
|
||||
|
@@ -31,13 +31,18 @@ class NotificationMailer
|
||||
|
||||
public function postPersistComment(NotificationComment $comment, PostPersistEventArgs $eventArgs): void
|
||||
{
|
||||
foreach (
|
||||
array_merge(
|
||||
$comment->getNotification()->getAddressees()->toArray(),
|
||||
[$comment->getNotification()->getSender()]
|
||||
) as $dest
|
||||
) {
|
||||
if (null === $dest->getEmail() || $comment->getCreatedBy() !== $dest) {
|
||||
$dests = [$comment->getNotification()->getSender(), ...$comment->getNotification()->getAddressees()->toArray()];
|
||||
|
||||
$uniqueDests = [];
|
||||
foreach ($dests as $dest) {
|
||||
// avoid duplication
|
||||
if (in_array(spl_object_hash($dest), $uniqueDests, true)) {
|
||||
continue;
|
||||
}
|
||||
$uniqueDests[] = spl_object_hash($dest);
|
||||
|
||||
// do not send if the sender does not have any email, nor to the creator of the comment
|
||||
if (null === $dest->getEmail() || $comment->getCreatedBy() === $dest) {
|
||||
continue;
|
||||
}
|
||||
$email = new TemplatedEmail();
|
||||
|
@@ -76,7 +76,6 @@ class CronJobDatabaseInteractionTest extends KernelTestCase
|
||||
// run a second time
|
||||
$manager->run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JobWithReturn implements CronJobInterface
|
||||
|
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Notification\Email;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\NotificationComment;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Notification\Email\NotificationMailer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class NotificationMailerTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testPostPersistComment(): void
|
||||
{
|
||||
$user1 = (new User())->setEmail('user1@foo.com');
|
||||
$user2 = (new User())->setEmail('user2@foo.com');
|
||||
$user3 = (new User())->setEmail('user3@foo.com');
|
||||
|
||||
$notification = new Notification();
|
||||
$notification
|
||||
->setTitle('test notification')
|
||||
->setSender($user1)
|
||||
->addAddressee($user2)
|
||||
->addAddressee($user3)
|
||||
;
|
||||
|
||||
$comment = (new NotificationComment())
|
||||
->setContent("foo bar baz")
|
||||
->setCreatedBy($user2)
|
||||
;
|
||||
$notification->addComment($comment);
|
||||
|
||||
$mailer = $this->prophesize(MailerInterface::class);
|
||||
|
||||
// a mail only to user1 and user3 should have been sent
|
||||
$mailer->send(Argument::that(function (Email $email) {
|
||||
foreach ($email->getTo() as $address) {
|
||||
if ($address->getAddress() === 'user1@foo.com' || $address->getAddress() === 'user3@foo.com') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}))->shouldBeCalledTimes(2);
|
||||
|
||||
$objectManager = $this->prophesize(EntityManagerInterface::class);
|
||||
|
||||
$mailer = $this->buildNotificationMailer($mailer->reveal());
|
||||
$mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal()));
|
||||
}
|
||||
|
||||
public function testPostPersistCommentDestWithNullEmail(): void
|
||||
{
|
||||
$user1 = (new User())->setEmail('user1@foo.com');
|
||||
$user2 = (new User())->setEmail('user2@foo.com');
|
||||
$user3 = (new User())->setEmail(null);
|
||||
|
||||
$notification = new Notification();
|
||||
$notification
|
||||
->setTitle('test notification')
|
||||
->setSender($user1)
|
||||
->addAddressee($user2)
|
||||
->addAddressee($user3)
|
||||
;
|
||||
|
||||
$comment = (new NotificationComment())
|
||||
->setContent("foo bar baz")
|
||||
->setCreatedBy($user2)
|
||||
;
|
||||
$notification->addComment($comment);
|
||||
|
||||
$mailer = $this->prophesize(MailerInterface::class);
|
||||
|
||||
// a mail only to user1 and user3 should have been sent
|
||||
$mailer->send(Argument::that(function (Email $email) {
|
||||
foreach ($email->getTo() as $address) {
|
||||
if ($address->getAddress() === 'user1@foo.com') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}))->shouldBeCalledTimes(1);
|
||||
|
||||
$objectManager = $this->prophesize(EntityManagerInterface::class);
|
||||
|
||||
$mailer = $this->buildNotificationMailer($mailer->reveal());
|
||||
$mailer->postPersistComment($comment, new PostPersistEventArgs($comment, $objectManager->reveal()));
|
||||
}
|
||||
|
||||
private function buildNotificationMailer(
|
||||
MailerInterface $mailer = null,
|
||||
): NotificationMailer {
|
||||
return new NotificationMailer(
|
||||
$mailer,
|
||||
new NullLogger(),
|
||||
new Translator('fr')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -64,5 +64,4 @@ class CollateAddressWithReferenceOrPostalCodeCronJobTest extends TestCase
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), new \DateTimeImmutable('2023-07-01T12:00:00'), true];
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), null, true];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user