1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

update test send

This commit is contained in:
Baptiste Lemoine 2020-04-16 16:43:30 +02:00
parent 84f271ff5a
commit 8f8eda6109
2 changed files with 17 additions and 8 deletions

View File

@ -257,11 +257,18 @@ class PollController extends AbstractController {
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) { // public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_vote' ) { public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_vote' ) {
$em = $this->getDoctrine()->getRepository( Owner::class ); $em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->find( 1 ); $foundOwner = $em->findOneByEmail( $emailChoice );
$poll = $foundOwner->getPolls()[ 0 ]; if($foundOwner){
$comment = $foundOwner->getComments()[ 0 ]; $poll = $foundOwner->getPolls()[ 0 ];
$comment = $foundOwner->getComments()[ 0 ];
$sent = $mail_service->sendCreationMailAction( $foundOwner, $poll );
if($sent){
return $this->json(["message"=>"test email sent!"],200);
}
}
return $this->json(["message"=>"user with this email was not found"],400);
$mail_service->sendCreationMailAction( $foundOwner, $poll );
} }

View File

@ -32,12 +32,11 @@ class MailService {
/** /**
* @param Owner $foundOwner * @param Owner $foundOwner
* @param Poll $poll * @param Poll|null $poll
* @param Mailer $mailer
* *
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
*/ */
public function sendCreationMailAction( Owner $foundOwner, Poll $poll) { public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null) {
// anti spam , limit to every minute TODO // anti spam , limit to every minute TODO
@ -45,7 +44,7 @@ class MailService {
'owner' => $foundOwner, 'owner' => $foundOwner,
'from' => 'ne-pas-repondre@framadate-api.cipherbliss.com', 'from' => 'ne-pas-repondre@framadate-api.cipherbliss.com',
'poll' => $poll, 'poll' => $poll,
'title' => 'Création de sondage - ' . $poll->getTitle(), 'title' => 'Création de sondage - ' . ($poll? $poll->getTitle() : $poll),
'email_template' => 'emails/creation-mail.html.twig', 'email_template' => 'emails/creation-mail.html.twig',
]; ];
@ -103,6 +102,9 @@ class MailService {
*/ */
public function sendMailWithVars( $config ) { public function sendMailWithVars( $config ) {
if(!$config['poll']){
$config['poll'] = new Poll();
}
$emailChoicesTemplates = [ $emailChoicesTemplates = [
'creation_poll' => 'creation-mail.html.twig', 'creation_poll' => 'creation-mail.html.twig',
'edit_poll' => 'modification-notification-mail.html.twig', 'edit_poll' => 'modification-notification-mail.html.twig',