diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Export.php b/lib/Alchemy/Phrasea/Controller/Prod/Export.php index 779666f9f2..f26d835b05 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Export.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Export.php @@ -238,7 +238,7 @@ class Export implements ControllerProviderInterface $list = $download->prepare_export( $app['phraseanet.user'], $app['filesystem'], - $request->request->get('obj'), + (array) $request->request->get('obj'), $request->request->get("type") == "title" ? : false, $request->request->get('businessfields') ); @@ -288,9 +288,9 @@ class Export implements ControllerProviderInterface $receiver = new Receiver(null, trim($mail)); $mail = MailRecordsExport::create($app, $receiver, $emitter, $request->request->get('textmail')); - $mail->setUrl($url); - $mail->setEnddate($endDateObject); - + $mail->setButtonUrl($url); + $mail->setExpiration($endDateObject); + try { $app['notification.deliverer']->deliver($mail); unset($remaingEmails[$key]); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php index eb82369388..2d26aef41f 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php @@ -21,7 +21,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; -use Symfony\Component\Serializer\Serializer; /** * Upload controller collection @@ -303,7 +302,7 @@ class Upload implements ControllerProviderInterface foreach ($user->ACL()->get_granted_base(array('canaddrecord')) as $collection) { $databox = $collection->get_databox(); - + if ( ! isset($collections[$databox->get_sbas_id()])) { $collections[$databox->get_sbas_id()] = array( 'databox' => $databox, diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index 91556f7f69..1451d23a33 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -296,13 +296,13 @@ class Account implements ControllerProviderInterface } try { - $date = new DateTime('1 day'); - $token = random::getUrlToken($app, \random::TYPE_EMAIL, $app['phraseanet.user']->get_id(), $date, $app['phraseanet.user']->get_email()); + $date = new \DateTime('1 day'); + $token = \random::getUrlToken($app, \random::TYPE_EMAIL, $app['phraseanet.user']->get_id(), $date, $app['phraseanet.user']->get_email()); $url = $app['phraseanet.registry']->get('GV_ServerName') . 'account/reset-email/?token=' . $token; $receiver = Receiver::fromUser($app['phraseanet.user']); $mail = MailRequestEmailUpdate::create($app, $receiver, null); - $mail->setUrl($url); + $mail->setButtonUrl($url); $mail->setExpiration($date); $app['notification.deliverer']->deliver($mail); diff --git a/lib/Alchemy/Phrasea/Controller/Root/Login.php b/lib/Alchemy/Phrasea/Controller/Root/Login.php index f28fdbfb19..b1c4e1984a 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Login.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Login.php @@ -287,17 +287,23 @@ class Login implements ControllerProviderInterface \random::removeToken($app, $code); - if (\Swift_Validate::email($user->get_email())) { - if (count($user->ACL()->get_granted_base()) > 0) { - $mail = MailSuccessEmailConfirmationRegistered::create($app, Receiver::fromUser($user)); - $app['notification.deliverer']->deliver($mail); - } + if (!\Swift_Validate::email($user->get_email())) { + return $app->redirect('/login/?redirect=prod¬ice=invalid-email'); + } - $user->set_mail_locked(false); - \random::removeToken($app, $code); + $user->set_mail_locked(false); + \random::removeToken($app, $code); + if (count($user->ACL()->get_granted_base()) > 0) { + $mail = MailSuccessEmailConfirmationRegistered::create($app, Receiver::fromUser($user)); + $app['notification.deliverer']->deliver($mail); + + return $app->redirect('/login/?redirect=prod¬ice=confirm-ok'); + } else { $mail = MailSuccessEmailConfirmationUnregistered::create($app, Receiver::fromUser($user)); $app['notification.deliverer']->deliver($mail); + + return $app->redirect('/login/?redirect=prod¬ice=confirm-ok-wait'); } } @@ -328,13 +334,9 @@ class Login implements ControllerProviderInterface $mail = MailRequestEmailConfirmation::create($app, Receiver::fromUser($user)); $mail->setButtonUrl($url); + $app['notification.deliverer']->deliver($mail); - try { - $app['notification.deliverer']->deliver($mail); - return $app->redirect($app['url_generator']->generate('login_forgot_password', array('sent' => 'ok'))); - } catch (\Exception $e) { - return $app->redirect($app['url_generator']->generate('login_forgot_password', array('sent' => 'ok'))); - } + return $app->redirect($app['url_generator']->generate('login_forgot_password', array('sent' => 'ok'))); } } @@ -632,82 +634,72 @@ class Login implements ControllerProviderInterface } } - try { - $user = \User_Adapter::create($app, $request->request->get('form_login'), $request->request->get("form_password"), $request->request->get("form_email"), false); + $user = \User_Adapter::create($app, $request->request->get('form_login'), $request->request->get("form_password"), $request->request->get("form_email"), false); - $user->set_gender($request->request->get('form_gender')) - ->set_firstname($request->request->get('form_firstname')) - ->set_lastname($request->request->get('form_lastname')) - ->set_address($request->request->get('form_address')) - ->set_zip($request->request->get('form_zip')) - ->set_tel($request->request->get('form_phone')) - ->set_fax($request->request->get('form_fax')) - ->set_job($request->request->get('form_job')) - ->set_company($request->request->get('form_company')) - ->set_position($request->request->get('form_activity')) - ->set_geonameid($request->request->get('form_geonameid')); + $user->set_gender($request->request->get('form_gender')) + ->set_firstname($request->request->get('form_firstname')) + ->set_lastname($request->request->get('form_lastname')) + ->set_address($request->request->get('form_address')) + ->set_zip($request->request->get('form_zip')) + ->set_tel($request->request->get('form_phone')) + ->set_fax($request->request->get('form_fax')) + ->set_job($request->request->get('form_job')) + ->set_company($request->request->get('form_company')) + ->set_position($request->request->get('form_activity')) + ->set_geonameid($request->request->get('form_geonameid')); - $demandOK = array(); + $demandOK = array(); - if (!!$app['phraseanet.registry']->get('GV_autoregister')) { + if (!!$app['phraseanet.registry']->get('GV_autoregister')) { - $template_user_id = \User_Adapter::get_usr_id_from_login($app, 'autoregister'); + $template_user_id = \User_Adapter::get_usr_id_from_login($app, 'autoregister'); - $template_user = \User_Adapter::getInstance($template_user_id, $app); + $template_user = \User_Adapter::getInstance($template_user_id, $app); - $base_ids = array(); + $base_ids = array(); - foreach (array_keys($inscOK) as $base_id) { - $base_ids[] = $base_id; - } - $user->ACL()->apply_model($template_user, $base_ids); + foreach (array_keys($inscOK) as $base_id) { + $base_ids[] = $base_id; } - - $autoReg = $user->ACL()->get_granted_base(); - - $appbox_register = new \appbox_register($app['phraseanet.appbox']); - - foreach ($demands as $base_id) { - if (false === $inscOK[$base_id] || $user->ACL()->has_access_to_base($base_id)) { - continue; - } - - $collection = \collection::get_from_base_id($app, $base_id); - $appbox_register->add_request($user, $collection); - unset($collection); - $demandOK[$base_id] = true; - } - - $params = array( - 'demand' => $demandOK, - 'autoregister' => $autoReg, - 'usr_id' => $user->get_id() - ); - - $app['events-manager']->trigger('__REGISTER_AUTOREGISTER__', $params); - $app['events-manager']->trigger('__REGISTER_APPROVAL__', $params); - - $user->set_mail_locked(true); - - try { - $expire = new \DateTime('+3 days'); - $token = \random::getUrlToken($app, \random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email()); - - $mail = MailRequestEmailConfirmation::create($app, Receiver::fromUser($user)); - $mail->setButtonUrl($app['phraseanet.registry']->get('GV_ServerName') . "register-confirm/?code=" . $token); - $mail->setExpiration($expire); - - $app['notification.deliverer']->deliver($mail); - - return $app->redirect('/login/?notice=mail-sent'); - } catch (\Exception $e) { - - } - - return $app->redirect(sprintf('/login/?usr=%d', $user->get_id())); - } catch (\Exception $e) { - return $app->redirect('/login/?error=unexpected'); + $user->ACL()->apply_model($template_user, $base_ids); } + + $autoReg = $user->ACL()->get_granted_base(); + + $appbox_register = new \appbox_register($app['phraseanet.appbox']); + + foreach ($demands as $base_id) { + if (false === $inscOK[$base_id] || $user->ACL()->has_access_to_base($base_id)) { + continue; + } + + $collection = \collection::get_from_base_id($app, $base_id); + $appbox_register->add_request($user, $collection); + unset($collection); + $demandOK[$base_id] = true; + } + + $params = array( + 'demand' => $demandOK, + 'autoregister' => $autoReg, + 'usr_id' => $user->get_id() + ); + + $app['events-manager']->trigger('__REGISTER_AUTOREGISTER__', $params); + $app['events-manager']->trigger('__REGISTER_APPROVAL__', $params); + + $user->set_mail_locked(true); + + $expire = new \DateTime('+3 days'); + $token = \random::getUrlToken($app, \random::TYPE_PASSWORD, $user->get_id(), $expire, $user->get_email()); + + $mail = MailRequestEmailConfirmation::create($app, Receiver::fromUser($user)); + $mail->setButtonUrl($app['phraseanet.registry']->get('GV_ServerName') . "register-confirm/?code=" . $token); + $mail->setExpiration($expire); + + $app['notification.deliverer']->deliver($mail); + + return $app->redirect('/login/?notice=mail-sent'); } /** diff --git a/lib/Alchemy/Phrasea/Core/Provider/NotificationDelivererServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/NotificationDelivererServiceProvider.php index c797361399..24d2d0f626 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/NotificationDelivererServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/NotificationDelivererServiceProvider.php @@ -3,6 +3,7 @@ namespace Alchemy\Phrasea\Core\Provider; use Alchemy\Phrasea\Notification\Deliverer; +use Alchemy\Phrasea\Notification\Emitter; use Silex\Application; use Silex\ServiceProviderInterface; @@ -10,8 +11,24 @@ class NotificationDelivererServiceProvider implements ServiceProviderInterface { public function register(Application $app) { + $app['notification.default.emitter'] = $app->share(function (Application $app) { + return new Emitter( + $app['phraseanet.registry']->get('GV_defaulmailsenderaddr', 'no-reply@phraseanet.com'), + $app['phraseanet.registry']->get('GV_homeTitle', 'Phraseanet') + ); + }); + + $app['notification.prefix'] = $app->share(function (Application $app) { + return $app['phraseanet.registry']->get('GV_email_prefix'); + }); + $app['notification.deliverer'] = $app->share(function($app) { - return new Deliverer($app['mailer'], $app['phraseanet.registry'], $app['dispatcher']); + return new Deliverer( + $app['mailer'], + $app['dispatcher'], + $app['notification.default.emitter'], + $app['notification.prefix'] + ); }); } diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 8b0f26047a..b5e94425dd 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -546,12 +546,8 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper $mailOldAddress = MailSuccessEmailUpdate::create($this->app, $oldReceiver, null, sprintf(_('You will now receive notifications at %s'), $new_email)); $mailNewAddress = MailSuccessEmailUpdate::create($this->app, $newReceiver, null, sprintf(_('You will no longer receive notifications at %s'), $old_email)); - try { - $this->app['notification.deliverer']->deliver($mailOldAddress); - $this->app['notification.deliverer']->deliver($mailNewAddress); - } catch (\Exception $e) { - - } + $this->app['notification.deliverer']->deliver($mailOldAddress); + $this->app['notification.deliverer']->deliver($mailNewAddress); } return $this; diff --git a/lib/Alchemy/Phrasea/Helper/User/Manage.php b/lib/Alchemy/Phrasea/Helper/User/Manage.php index 9d402ffb0d..dcec56b53e 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Manage.php +++ b/lib/Alchemy/Phrasea/Helper/User/Manage.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Helper\User; use Alchemy\Phrasea\Helper\Helper; use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup; +use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationUnregistered; /** * @@ -183,7 +184,7 @@ class Manage extends Helper if (false !== $urlToken) { $mail = MailSuccessEmailConfirmationUnregistered::create($this->app, Receiver::fromUser($createdUser)); - $mail->setUrl($this->app['url_generator']->generate('login_forgot_password', array('token' => $urlToken), true)); + $mail->setButtonUrl($this->app['url_generator']->generate('login_forgot_password', array('token' => $urlToken), true)); $this->app['notification.deliverer']->deliver($mail); } } diff --git a/lib/Alchemy/Phrasea/Notification/Emitter.php b/lib/Alchemy/Phrasea/Notification/Emitter.php index d09538bb6a..ecfe053602 100644 --- a/lib/Alchemy/Phrasea/Notification/Emitter.php +++ b/lib/Alchemy/Phrasea/Notification/Emitter.php @@ -50,7 +50,10 @@ class Emitter implements EmitterInterface public static function fromUser(\User_Adapter $user) { if (!\Swift_Validate::email($user->get_email())) { - throw new InvalidArgumentException(sprintf('User provided does not have a valid e-mail address')); + throw new InvalidArgumentException(sprintf( + 'User provided does not have a valid e-mail address (%s)', + $user->get_email() + )); } return new static($user->get_display_name(), $user->get_email()); diff --git a/lib/Alchemy/Phrasea/Notification/Receiver.php b/lib/Alchemy/Phrasea/Notification/Receiver.php index 95314fd968..31d97340e8 100644 --- a/lib/Alchemy/Phrasea/Notification/Receiver.php +++ b/lib/Alchemy/Phrasea/Notification/Receiver.php @@ -50,7 +50,10 @@ class Receiver implements ReceiverInterface public static function fromUser(\User_Adapter $user) { if (!\Swift_Validate::email($user->get_email())) { - throw new InvalidArgumentException(sprintf('User provided does not have a valid e-mail address')); + throw new InvalidArgumentException(sprintf( + 'User provided does not have a valid e-mail address (%s)', + $user->get_email() + )); } return new static($user->get_display_name(), $user->get_email()); diff --git a/lib/Alchemy/Phrasea/PhraseanetServiceProvider.php b/lib/Alchemy/Phrasea/PhraseanetServiceProvider.php index ea0c5b5c29..b20e6181f0 100644 --- a/lib/Alchemy/Phrasea/PhraseanetServiceProvider.php +++ b/lib/Alchemy/Phrasea/PhraseanetServiceProvider.php @@ -36,7 +36,7 @@ class PhraseanetServiceProvider implements ServiceProviderInterface $app['firewall'] = $app->share(function(SilexApplication $app) { return new Firewall($app); }); - + $app['events-manager'] = $app->share(function(SilexApplication $app) { $events = new \eventsmanager_broker($app); $events->start(); diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index f516977418..c47dcaf2be 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -1463,10 +1463,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface if (!$session->hasModuleId($app_id)) { $module = new \Entities\SessionModule(); + $module->setModuleId($app_id); $module->setSession($session); + $session->addSessionModule($module); + $app['EM']->persist($module); $app['EM']->persist($session); + + $app['EM']->flush(); } diff --git a/lib/classes/User/Query.php b/lib/classes/User/Query.php index e200873d92..2e54982834 100644 --- a/lib/classes/User/Query.php +++ b/lib/classes/User/Query.php @@ -110,6 +110,12 @@ class User_Query implements User_QueryInterface */ protected $only_templates = false; + /** + * + * @var boolean + */ + protected $email_not_null = false; + /** * * @var Array @@ -222,6 +228,10 @@ class User_Query implements User_QueryInterface $sql .= ' AND usr.invite=0 '; } + if ( ! $this->email_not_null) { + $sql .= ' AND usr.usr_mail IS NOT NULL '; + } + if ($this->only_templates === true) { $sql .= ' AND model_of = ' . $this->app['phraseanet.user']->get_id(); } elseif ($this->include_templates === false) { @@ -439,6 +449,18 @@ class User_Query implements User_QueryInterface return $this; } + /** + * + * @param boolean $boolean + * @return User_Query + */ + public function email_not_null($boolean) + { + $this->email_not_null = ! ! $boolean; + + return $this; + } + /** * * @param array $rights diff --git a/lib/classes/eventsmanager/notify/autoregister.php b/lib/classes/eventsmanager/notify/autoregister.php index 4f86daea2d..e92f771e30 100644 --- a/lib/classes/eventsmanager/notify/autoregister.php +++ b/lib/classes/eventsmanager/notify/autoregister.php @@ -197,17 +197,20 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->get_email()); $body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->get_company()); - $receiver = Receiver::fromUser($to); - $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body); - + $readyToSend = false; try { - $this->app['notification.deliverer']->deliver($mail); - - return true; - } catch (\Exception $e) { + $receiver = Receiver::fromUser($to); + $readyToSend = true; + } catch (Exception $e) { + } - return false; + if ($readyToSend) { + $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body); + $this->app['notification.deliverer']->deliver($mail); + } + + return true; } /** diff --git a/lib/classes/eventsmanager/notify/bridgeuploadfail.php b/lib/classes/eventsmanager/notify/bridgeuploadfail.php index 020fc9cfd9..98767a42db 100644 --- a/lib/classes/eventsmanager/notify/bridgeuploadfail.php +++ b/lib/classes/eventsmanager/notify/bridgeuploadfail.php @@ -82,19 +82,24 @@ class eventsmanager_notify_bridgeuploadfail extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($params['usr_id'])) { - $user = User_Adapter::getInstance($params['usr_id'], $this->app); + $readyToSend = false; try { + $user = User_Adapter::getInstance($params['usr_id'], $this->app); $account = Bridge_Account::load_account($this->app, $params['account_id']); + $readyToSend = true; + } catch (\Exception $e) { + } + + if ($readyToSend) { $receiver = Receiver::fromUser($user); + /** ADD MAIL TEST */ $mail = MailInfoBridgeUploadFailed::create($this->app, $receiver); $mail->setAdapter($account->get_api()->get_connector()->get_name()); $mail->setReason($params['reason']); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/feed.php b/lib/classes/eventsmanager/notify/feed.php index f194c09199..0f01a5222d 100644 --- a/lib/classes/eventsmanager/notify/feed.php +++ b/lib/classes/eventsmanager/notify/feed.php @@ -67,7 +67,10 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract $Query = new \User_Query($this->app); - $Query->include_phantoms(true)->include_invite(false)->include_templates(false); + $Query->include_phantoms(true) + ->include_invite(false) + ->include_templates(false) + ->email_not_null(true); if ($entry->get_feed()->get_collection()) { $Query->on_base_ids(array($entry->get_feed()->get_collection()->get_base_id())); @@ -83,32 +86,38 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract do { $results = $Query->limit($start, $perLoop)->execute()->get_results(); - + foreach ($results as $user_to_notif) { /* @var $user_to_notif \User_Adapter */ $mailed = false; if ($this->shouldSendNotificationFor($user_to_notif->get_id())) { - - $token = \random::getUrlToken( - $this->app, - \random::TYPE_FEED_ENTRY - , $user_to_notif->get_id() - , null - , $entry->get_id() - ); - - $url = $this->app['phraseanet.registry']->get('GV_ServerName') . 'lightbox/index.php?LOG=' . $token; - + $readyToSend = false; try { + $token = \random::getUrlToken( + $this->app, + \random::TYPE_FEED_ENTRY + , $user_to_notif->get_id() + , null + , $entry->get_id() + ); + + $url = $this->app['phraseanet.registry']->get('GV_ServerName') . 'lightbox/index.php?LOG=' . $token; + $receiver = Receiver::fromUser($user_to_notif); + $readyToSend = true; + } catch (\Exception $e) { + + } + + if ($readyToSend) { $mail = MailInfoNewPublication::create($this->app, $receiver); $mail->setButtonUrl($url); $mail->setAuthor($entry->get_author_name()); $mail->setTitle($entry->get_title()); - $mailed = true; - } catch (\Exception $e) { + $this->app['notification.deliverer']->deliver($mail); + $mailed = true; } } diff --git a/lib/classes/eventsmanager/notify/order.php b/lib/classes/eventsmanager/notify/order.php index 978364c9b2..b8e86020d3 100644 --- a/lib/classes/eventsmanager/notify/order.php +++ b/lib/classes/eventsmanager/notify/order.php @@ -111,15 +111,20 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($user->get_id())) { + $readyToSend = false; try { $receiver = Receiver::fromUser($user); + $readyToSend = true; + } catch (Exception $e) { + continue; + } + + if ($readyToSend) { $mail = MailInfoNewOrder::create($this->app, $receiver); $mail->setUser($orderInitiator); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/orderdeliver.php b/lib/classes/eventsmanager/notify/orderdeliver.php index 1d4a524fd0..89011ace50 100644 --- a/lib/classes/eventsmanager/notify/orderdeliver.php +++ b/lib/classes/eventsmanager/notify/orderdeliver.php @@ -96,30 +96,29 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($params['to'])) { + $readyToSend = false; try { $user_from = User_Adapter::getInstance($params['from'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app); - } catch (Exception $e) { - return false; - } - - try { - $repository = $this->app['EM']->getRepository('\Entities\Basket'); - - $basket = $repository->find($params['ssel_id']); $receiver = Receiver::fromUser($user_to); $emitter = Emitter::fromUser($user_from); + $repository = $this->app['EM']->getRepository('\Entities\Basket'); + $basket = $repository->find($params['ssel_id']); + + $readyToSend = true; + } catch (Exception $e) { + + } + + if ($readyToSend) { $mail = MailInfoOrderDelivered::create($this->app, $receiver, $emitter); $mail->setBasket($basket); $mail->setDeliverer($user_from); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - - } catch (Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/ordernotdelivered.php b/lib/classes/eventsmanager/notify/ordernotdelivered.php index ce98074f3e..e8adf56217 100644 --- a/lib/classes/eventsmanager/notify/ordernotdelivered.php +++ b/lib/classes/eventsmanager/notify/ordernotdelivered.php @@ -76,17 +76,22 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac $mailed = false; if ($this->shouldSendNotificationFor($params['to'])) { + + $readyToSend = false; + try { $user_from = User_Adapter::getInstance($params['from'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app); - } catch (Exception $e) { - return false; - } - try { $receiver = Receiver::fromUser($user_to); $emitter = Emitter::fromUser($user_from); + $readyToSend = true; + } catch (Exception $e) { + + } + + if ($readyToSend) { $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter); $mail->setQuantity($params['n']); $mail->setDeliverer($user_from); @@ -94,8 +99,6 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/push.php b/lib/classes/eventsmanager/notify/push.php index ecdf02eb66..8309208f4b 100644 --- a/lib/classes/eventsmanager/notify/push.php +++ b/lib/classes/eventsmanager/notify/push.php @@ -83,6 +83,8 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($params['to'])) { + + $readyToSend = false; try { $repository = $this->app['EM']->getRepository('\Entities\Basket'); $basket = $repository->find($params['ssel_id']); @@ -92,7 +94,12 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract $receiver = Receiver::fromUser($user_from); $emitter = Emitter::fromUser($user_to); + $readyToSend = true; + } catch (Exception $e) { + } + + if ($readyToSend) { $mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message']); $mail->setBasket($basket); $mail->setPusher($user_from); @@ -100,8 +107,6 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract $this->app['notification.deliverer']->deliver($mail, $params['accuse']); $mailed = true; - } catch (Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/register.php b/lib/classes/eventsmanager/notify/register.php index d69e8839a2..0b0518f288 100644 --- a/lib/classes/eventsmanager/notify/register.php +++ b/lib/classes/eventsmanager/notify/register.php @@ -119,18 +119,22 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($usr_id)) { + $readyToSend = false; try { $admin_user = User_Adapter::getInstance($usr_id, $this->app); - $receiver = Receiver::fromUser($admin_user); + $readyToSend = true; + } catch (Exception $e) { + continue; + } + + if ($readyToSend) { $mail = MailInfoUserRegistered::create($this->app, $receiver); $mail->setRegisteredUser($registeredUser); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (Exception $e) { - continue; } } diff --git a/lib/classes/eventsmanager/notify/uploadquarantine.php b/lib/classes/eventsmanager/notify/uploadquarantine.php index 86142721cd..3cef3a1455 100644 --- a/lib/classes/eventsmanager/notify/uploadquarantine.php +++ b/lib/classes/eventsmanager/notify/uploadquarantine.php @@ -110,13 +110,18 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($user->get_id())) { + $readyToSend = false; try { $receiver = Receiver::fromUser($user); + $readyToSend = true; + } catch (Exception $e) { + + } + + if ($readyToSend) { $mail = MailInfoRecordQuarantined::create($this->app, $receiver); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/validate.php b/lib/classes/eventsmanager/notify/validate.php index d810ed6280..6a02f99288 100644 --- a/lib/classes/eventsmanager/notify/validate.php +++ b/lib/classes/eventsmanager/notify/validate.php @@ -10,8 +10,9 @@ */ use Alchemy\Phrasea\Application; - use Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest; +use Alchemy\Phrasea\Notification\Emitter; +use Alchemy\Phrasea\Notification\Receiver; class eventsmanager_notify_validate extends eventsmanager_notifyAbstract { @@ -89,34 +90,32 @@ class eventsmanager_notify_validate extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($params['to'])) { + + $readyToSend = false; try { $user_from = User_Adapter::getInstance($params['from'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app); - } catch (Exception $e) { - return false; - } - try { $basket = $this->app['EM'] ->getRepository('\Entities\Basket') ->find($params['ssel_id']); $title = $basket->getName(); + + $receiver = Receiver::fromUser($user_to); + $emitter = Emitter::fromUser($user_from); + + $readyToSend = true; } catch (\Exception $e) { - $title = ''; + } - $receiver = Receiver::fromUser($user_to); - $emitter = Receiver::fromUser($user_from); - - try { + if ($readyToSend) { $mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']); $mail->setButtonUrl($params['url']); $mail->setTitle($title); $this->app['notification.deliverer']->deliver($mail, $params['accuse']); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notify/validationdone.php b/lib/classes/eventsmanager/notify/validationdone.php index b4e8cc0ad3..5270119301 100644 --- a/lib/classes/eventsmanager/notify/validationdone.php +++ b/lib/classes/eventsmanager/notify/validationdone.php @@ -10,8 +10,9 @@ */ use Alchemy\Phrasea\Application; - use Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone; +use Alchemy\Phrasea\Notification\Emitter; +use Alchemy\Phrasea\Notification\Receiver; class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract { @@ -85,34 +86,31 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract $mailed = false; if ($this->shouldSendNotificationFor($params['to'])) { + $readyToSend = false; try { $user_from = User_Adapter::getInstance($params['from'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app); - } catch (Exception $e) { - return false; - } - try { $basket = $this->app['EM'] ->getRepository('\Entities\Basket') ->find($params['ssel_id']); $title = $basket->getName(); + + $receiver = Receiver::fromUser($user_to); + $emitter = Emitter::fromUser($user_from); + + $readyToSend = true; } catch (\Exception $e) { - $title = ''; + } - $receiver = Receiver::fromUser($user_to); - $emitter = Receiver::fromUser($user_from); - - try { + if ($readyToSend) { $mail = MailInfoValidationDone::create($this->app, $receiver, $emitter); $mail->setButtonUrl($params['url']); $mail->setTitle($title); $this->app['notification.deliverer']->deliver($mail); $mailed = true; - } catch (\Exception $e) { - } } diff --git a/lib/classes/eventsmanager/notifyAbstract.php b/lib/classes/eventsmanager/notifyAbstract.php index 88e6c497eb..df9a1ef5d9 100644 --- a/lib/classes/eventsmanager/notifyAbstract.php +++ b/lib/classes/eventsmanager/notifyAbstract.php @@ -26,8 +26,9 @@ abstract class eventsmanager_notifyAbstract extends eventsmanager_eventAbstract protected function get_prefs($class, $usr_id) { $user = User_Adapter::getInstance($usr_id, $this->app); + $pref = $user->getPrefs('notification_' . $class); - return $user->getPrefs('notification_' . $class); + return null !== $pref ? $pref : 1; } protected function shouldSendNotificationFor($usr_id) diff --git a/lib/classes/set/order.php b/lib/classes/set/order.php index 5327d30e26..7e4f2b6e10 100644 --- a/lib/classes/set/order.php +++ b/lib/classes/set/order.php @@ -471,7 +471,7 @@ class set_order extends set_abstract $stmt->closeCursor(); $n ++; } - + if ($n > 0) { $params = array( 'from' => $this->app['phraseanet.user']->get_id(), diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index 373b304216..584679ddc0 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -1651,6 +1651,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testFeedsContent() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); $title = 'Yellow title'; $subtitle = 'Trololololo !'; @@ -1710,6 +1717,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testFeedEntry() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); $title = 'Yellow title'; $subtitle = 'Trololololo !'; @@ -1749,6 +1763,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testFeedEntryNoAccess() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); $title = 'Yellow title'; $subtitle = 'Trololololo !'; @@ -1786,6 +1807,14 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract */ public function testFeedContent() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + $title = 'Yellow title'; $subtitle = 'Trololololo !'; $entry_title = 'Superman'; diff --git a/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php b/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php index aec9f56097..f25aa99a09 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php @@ -14,6 +14,15 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function setUp() { parent::setUp(); + + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + $this->feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], "salut", 'coucou'); $publishers = $this->feed->get_publishers(); $publisher = array_shift($publishers); @@ -316,6 +325,8 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac { $basket = $this->insertOneBasket(); + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone'); + $crawler = self::$DI['client']->request('POST', '/lightbox/ajax/SET_RELEASE/' . $basket->getId() . '/'); $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('Content-type')); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php index 4c5dfcfc25..a4546377bb 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -54,6 +54,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->setAdmin(true); + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailTest'); + self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/', array( 'email' => self::$DI['user']->get_email() )); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php index b8b1d469e5..b7309ee945 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php @@ -48,6 +48,7 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteRightsApply() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate', 2); $username = uniqid('user_'); $user = \User_Adapter::create(self::$DI['app'], $username, "test", $username . "@email.com", false); @@ -241,12 +242,43 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($datas->error); } - public function testRouteCreateUser() + public function testRouteCreateUserAndValidateEmail() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup'); $username = uniqid('user_'); - $user = \User_Adapter::create(self::$DI['app'], $username, "test", $username . "@email.com", false); - self::$DI['client']->request('POST', '/admin/users/create/', array('value' => $username . "@email.com", 'template' => '0')); + self::$DI['client']->request('POST', '/admin/users/create/', array( + 'value' => $username . "@email.com", + 'template' => '0', + 'validate_mail' => true, + )); + + $response = self::$DI['client']->getResponse(); + + $this->assertTrue($response->isOK()); + $this->assertEquals("application/json", $response->headers->get("content-type")); + $datas = json_decode($response->getContent()); + $this->assertTrue(is_object($datas)); + $this->assertFalse($datas->error); + + try { + $user = \User_Adapter::getInstance((int) $datas->data, self::$DI['app']); + $user->delete(); + } catch (\Exception $e) { + $this->fail("could not delete created user " . $e->getMessage()); + } + } + + public function testRouteCreateUserAndSendCredentials() + { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationUnregistered'); + $username = uniqid('user_'); + + self::$DI['client']->request('POST', '/admin/users/create/', array( + 'value' => $username . "@email.com", + 'template' => '0', + 'send_credentials' => true, + )); $response = self::$DI['client']->getResponse(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php index 2d56cead5f..7d247486a9 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php @@ -174,6 +174,23 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract unset($response, $datas); } + /** + * @covers Alchemy\Phrasea\Controller\Prod\Export::exportMail + */ + public function testExportMail() + { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRecordsExport'); + + self::$DI['client']->request('POST', '/prod/export/mail/', array( + 'lst' => self::$DI['record_1']->get_serialize_key(), + 'destmail' => 'user@example.com', + 'obj' => array('preview'), + )); + + $response = self::$DI['client']->getResponse(); + $this->assertTrue($response->isOk()); + } + /** * @covers Alchemy\Phrasea\Controller\Prod\Export::connect * @covers Alchemy\Phrasea\Controller\Prod\Export::call diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php index 77df1b78ec..0647282934 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php @@ -42,6 +42,13 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract { parent::setUp(); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); $this->feed = \Feed_Adapter::create( self::$DI['app'], self::$DI['user'], $this->feed_title, $this->feed_subtitle diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php index 4c14b039c1..8aa4493da8 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php @@ -72,11 +72,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testSendOrder() { $order = $this->createOneOrder('I need this pictures'); + + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderDelivered'); + $parameters = array(); foreach ($order as $id => $element) { $parameters[] = $id; } - self::$DI['client']->request('POST', '/prod/order/' . $order->get_order_id() . '/send/', $parameters); + self::$DI['client']->request('POST', '/prod/order/' . $order->get_order_id() . '/send/', array('elements' => $parameters)); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $url = parse_url(self::$DI['client']->getResponse()->headers->get('location')); parse_str($url['query']); @@ -89,11 +92,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testSendOrderJson() { $order = $this->createOneOrder('I need this pictures'); + + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderDelivered'); + $parameters = array(); foreach ($order as $id => $element) { $parameters[] = $id; } - $this->XMLHTTPRequest('POST', '/prod/order/' . $order->get_order_id() . '/send/', $parameters); + $this->XMLHTTPRequest('POST', '/prod/order/' . $order->get_order_id() . '/send/', array('elements' => $parameters)); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); @@ -112,11 +118,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testDenyOrder() { $order = $this->createOneOrder('I need this pictures'); + + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderCancelled'); + $parameters = array(); foreach ($order as $id => $element) { $parameters[] = $id; } - self::$DI['client']->request('POST', '/prod/order/' . $order->get_order_id() . '/deny/', $parameters); + self::$DI['client']->request('POST', '/prod/order/' . $order->get_order_id() . '/deny/', array('elements' => $parameters)); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $url = parse_url(self::$DI['client']->getResponse()->headers->get('location')); parse_str($url['query']); @@ -129,11 +138,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testDenyOrderJson() { $order = $this->createOneOrder('I need this pictures'); + + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderCancelled'); + $parameters = array(); foreach ($order as $id => $element) { $parameters[] = $id; } - $this->XMLHTTPRequest('POST', '/prod/order/' . $order->get_order_id() . '/deny/', $parameters); + $this->XMLHTTPRequest('POST', '/prod/order/' . $order->get_order_id() . '/deny/', array('elements' => $parameters)); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); @@ -147,6 +159,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract private function createOneOrder($usage) { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewOrder'), $this->equalTo(null)); + $receveid = array(self::$DI['record_1']->get_serialize_key() => self::$DI['record_1']); return \set_order::create( diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php index 7f8a5f8444..97ebc09f73 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php @@ -35,6 +35,8 @@ class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRoutePOSTsend() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoPushReceived', 2); + $route = '/prod/push/send/'; $records = array( @@ -69,6 +71,8 @@ class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRoutePOSTvalidate() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest', 3); + $route = '/prod/push/validate/'; $records = array( diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index fa60fd8ba3..cc02e89fee 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -204,6 +204,14 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'toto' ); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + $feedEntry = \Feed_Entry_Adapter::create( self::$DI['app'], self::$feed, diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php index 16a7d45a06..7f90130732 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php @@ -72,7 +72,14 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testUpload() { - $params = array('base_id' => self::$DI['collection']->get_base_id()); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + $params = array( + 'base_id' => self::$DI['collection']->get_base_id() + ); + $files = array( 'files' => array( new UploadedFile( @@ -97,6 +104,36 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } } + /** + * @covers Alchemy\Phrasea\Controller\Prod\Upload::upload + * @covers Alchemy\Phrasea\Controller\Prod\Upload::getJsonResponse + */ + public function testUploadingTwiceTheSameRecordShouldSendToQuantantine() + { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoRecordQuarantined'); + + $params = array( + 'base_id' => self::$DI['collection']->get_base_id() + ); + + $files = array( + 'files' => array( + new UploadedFile( + $this->tmpFile, 'KIKOO.JPG' + ) + ) + ); + self::$DI['client']->request('POST', '/prod/upload/', $params, $files, array('HTTP_Accept' => 'application/json')); + + $response = self::$DI['client']->getResponse(); + + $this->checkJsonResponse($response); + + $datas = json_decode($response->getContent(), true); + + $this->assertTrue($datas['success']); + } + /** * @covers Alchemy\Phrasea\Controller\Prod\Upload::upload */ diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php index 8504ff73d1..83a62f38a8 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/AccountTest.php @@ -185,6 +185,8 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testPostResetMailEmail() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate'); + $password = \random::generatePassword(); self::$DI['app']['phraseanet.user']->set_password($password); self::$DI['client']->request('POST', '/account/reset-email/', array( @@ -311,7 +313,6 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testUpdateAccount() { - $register = new \appbox_register(self::$DI['app']['phraseanet.appbox']); $bases = $notifs = array(); foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) { @@ -360,9 +361,9 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals('minet', self::$DI['app']['phraseanet.user']->get_lastname()); $sql = 'SELECT base_id FROM demand WHERE usr_id = :usr_id AND en_cours="1" '; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':usr_id' => $user->get_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt->execute(array(':usr_id' => self::$DI['app']['phraseanet.user']->get_id())); + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); $this->assertCount(count($bases), $rs); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index 2d1bf18ddc..17462fb1a2 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -127,6 +127,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMail() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationRegistered'); + self::$DI['app']->closeAccount(); $email = $this->generateEmail(); $appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']); @@ -139,7 +141,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - $this->assertEquals('/login/?redirect=prod¬ice=confirm-ok-wait', $response->headers->get('location')); + $this->assertEquals('/login/?redirect=prod¬ice=confirm-ok', $response->headers->get('location')); $this->assertFalse(self::$DI['user']->get_mail_locked()); } @@ -148,11 +150,15 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMailNoCollAwait() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationUnregistered'); + + $user = \User_Adapter::create(self::$DI['app'], 'test'.mt_rand(), \random::generatePassword(), 'email-random'.mt_rand().'@phraseanet.com', false); + self::$DI['app']->closeAccount(); $email = $this->generateEmail(); - $token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email); + $token = \random::getUrlToken(self::$DI['app'], \random::TYPE_EMAIL, $user->get_id(), null, $email); - self::$DI['user']->set_mail_locked(true); + $user->set_mail_locked(true); $this->deleteRequest(); @@ -161,7 +167,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($response->isRedirect()); - $this->assertEquals('/login/?redirect=prod¬ice=confirm-ok', $response->headers->get('location')); + $this->assertEquals('/login/?redirect=prod¬ice=confirm-ok-wait', $response->headers->get('location')); + $user->delete(); } /** @@ -195,6 +202,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPasswordMail() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'); + self::$DI['app']->closeAccount(); self::$DI['client']->request('POST', '/login/forgot-password/', array('mail' => self::$DI['user']->get_email())); $response = self::$DI['client']->getResponse(); @@ -562,6 +571,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testPostRegister() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'); + self::$DI['app']->closeAccount(); $bases = array(); @@ -633,6 +644,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testSendConfirmMail() { + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'); + self::$DI['app']->closeAccount(); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => self::$DI['user']->get_id())); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php index f21dd581a9..8e631b6d74 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php @@ -71,9 +71,93 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract protected static $feed_4_public_subtitle = 'Feed 4 subtitle'; protected $client; + private static $initialized = false; + public function setUp() { parent::setUp(); + + if (!self::$initialized) { + + @unlink('/tmp/db.sqlite'); + copy(__DIR__ . '/../../../../../db-ref.sqlite', '/tmp/db.sqlite'); + + self::$DI['app']['session']->clear(); + self::$DI['app']['session']->set('usr_id', self::$DI['user']->get_id()); + + self::$feed_1_private = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_1_private_title, self::$feed_1_private_subtitle); + self::$feed_1_private->set_public(false); + self::$feed_1_private->set_icon(__DIR__ . '/../../../../../files/logocoll.gif'); + + self::$feed_2_private = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_2_private_title, self::$feed_2_private_subtitle); + self::$feed_2_private->set_public(false); + + self::$feed_3_public = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_3_public_title, self::$feed_3_public_subtitle); + self::$feed_3_public->set_public(true); + self::$feed_3_public->set_icon(__DIR__ . '/../../../../../files/logocoll.gif'); + + self::$feed_4_public = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_4_public_title, self::$feed_4_public_subtitle); + self::$feed_4_public->set_public(true); + + $publishers = self::$feed_4_public->get_publishers(); + $publisher = array_shift($publishers); + + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + + for ($i = 1; $i != 15; $i++) { + $entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed_4_public, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com'); + + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_6']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_7']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_8']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_9']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_10']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_13']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_15']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_16']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_19']); + + $entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed_1_private, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com'); + + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_6']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_7']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_8']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_9']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_10']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_13']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_15']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_16']); + $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_19']); + + self::$feed_4_entries[] = $entry; + } + + + self::$public_feeds = \Feed_Collection::load_public_feeds(self::$DI['app']); + self::$private_feeds = \Feed_Collection::load_all(self::$DI['app'], self::$DI['user']); + self::$DI['app']['session']->clear(); + + self::$initialized = true; + } + + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + self::$feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'title', 'subtitle'); self::$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']); self::$entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com"); @@ -102,65 +186,6 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract $application = new Application('test'); - @unlink('/tmp/db.sqlite'); - copy(__DIR__ . '/../../../../../db-ref.sqlite', '/tmp/db.sqlite'); - - $application['session']->clear(); - $application['session']->set('usr_id', self::$DI['user']->get_id()); - - self::$feed_1_private = \Feed_Adapter::create($application, self::$DI['user'], self::$feed_1_private_title, self::$feed_1_private_subtitle); - self::$feed_1_private->set_public(false); - self::$feed_1_private->set_icon(__DIR__ . '/../../../../../files/logocoll.gif'); - - self::$feed_2_private = \Feed_Adapter::create($application, self::$DI['user'], self::$feed_2_private_title, self::$feed_2_private_subtitle); - self::$feed_2_private->set_public(false); - - self::$feed_3_public = \Feed_Adapter::create($application, self::$DI['user'], self::$feed_3_public_title, self::$feed_3_public_subtitle); - self::$feed_3_public->set_public(true); - self::$feed_3_public->set_icon(__DIR__ . '/../../../../../files/logocoll.gif'); - - self::$feed_4_public = \Feed_Adapter::create($application, self::$DI['user'], self::$feed_4_public_title, self::$feed_4_public_subtitle); - self::$feed_4_public->set_public(true); - - $publishers = self::$feed_4_public->get_publishers(); - $publisher = array_shift($publishers); - - for ($i = 1; $i != 15; $i++) { - $entry = \Feed_Entry_Adapter::create($application, self::$feed_4_public, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com'); - - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_1']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_6']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_7']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_8']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_9']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_10']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_1']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_13']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_15']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_16']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_19']); - - $entry = \Feed_Entry_Adapter::create($application, self::$feed_1_private, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com'); - - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_1']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_6']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_7']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_8']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_9']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_10']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_1']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_13']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_15']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_16']); - $item = \Feed_Entry_Item::create($application['phraseanet.appbox'], $entry, self::$DI['record_19']); - - self::$feed_4_entries[] = $entry; - } - - - self::$public_feeds = \Feed_Collection::load_public_feeds($application); - self::$private_feeds = \Feed_Collection::load_all($application, self::$DI['user']); - $application['session']->clear(); } public static function tearDownAfterClass() diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/NotificationDelivererServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/NotificationDelivererServiceProviderTest.php index 7fce108fe4..539df52579 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/NotificationDelivererServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/NotificationDelivererServiceProviderTest.php @@ -5,12 +5,12 @@ namespace Alchemy\Tests\Phrasea\Core\Provider; /** * @covers Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider */ -class ConfigurationTesterServiceProvidertest extends ServiceProviderTestCase +class NotificationDelivererServiceProvidertest extends ServiceProviderTestCase { public function provideServiceDescription() { return array( - array('Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider', 'phraseanet.configuration-tester', 'Alchemy\\Phrasea\\Setup\\ConfigurationTester'), + array('Alchemy\Phrasea\Core\Provider\NotificationDelivererServiceProvider', 'notification.deliverer', 'Alchemy\\Phrasea\\Notification\\Deliverer'), ); } } diff --git a/tests/classes/Feed/Entry/Feed_Entry_AdapterTest.php b/tests/classes/Feed/Entry/Feed_Entry_AdapterTest.php index 32d2663f1a..d97404882f 100644 --- a/tests/classes/Feed/Entry/Feed_Entry_AdapterTest.php +++ b/tests/classes/Feed/Entry/Feed_Entry_AdapterTest.php @@ -95,6 +95,14 @@ class Feed_Entry_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testSetFeed() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); + $new_feed = Feed_Adapter::create(self::$DI['app'], self::$DI['user'], self::$feed_title, self::$feed_subtitle); $publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $new_feed, self::$DI['user']); diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index c3a2c2d45e..5d4e82804a 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -73,6 +73,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::generateRecords($application); + self::$DI['user']->set_email('valid@phraseanet.com'); + self::$updated = true; } } @@ -103,8 +105,9 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase \PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Notice::$enabled = true; + $phpunit = $this; - self::$DI['app'] = self::$DI->share(function($DI) { + self::$DI['app'] = self::$DI->share(function($DI) use ($phpunit) { $environment = 'test'; $app = require __DIR__ . '/../../lib/Alchemy/Phrasea/Application/Root.php'; @@ -124,6 +127,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase return $browser; })); + $app['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + $app['notification.deliverer']->expects($this->any()) + ->method('deliver') + ->will($this->returnCallback(function() use ($phpunit){ + $phpunit->fail('Notification deliverer must be mocked'); + })); + return $app; }); @@ -873,4 +885,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $this->assertTrue(is_array($data)); $this->assertFalse($data['success']); } + + protected function mockNotificationDeliverer($expectedMail, $qty = 1, $receipt = null) + { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->exactly($qty)) + ->method('deliver') + ->with($this->isInstanceOf($expectedMail), $this->equalTo($receipt)); + } } diff --git a/tests/classes/api/v1/api_v1_adapterTest.php b/tests/classes/api/v1/api_v1_adapterTest.php index 87b735b50f..0a87180101 100644 --- a/tests/classes/api/v1/api_v1_adapterTest.php +++ b/tests/classes/api/v1/api_v1_adapterTest.php @@ -618,6 +618,13 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testGet_publication() { + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewPublication'), $this->equalTo(null)); $date = new DateTime(); $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); diff --git a/tests/classes/record/adapterTest.php b/tests/classes/record/adapterTest.php index 0f4c74f613..c83346e080 100644 --- a/tests/classes/record/adapterTest.php +++ b/tests/classes/record/adapterTest.php @@ -63,6 +63,14 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract self::$DI['app']['phraseanet.user']->ACL()->update_rights_to_base(self::$DI['record_1']->get_base_id(), array('order_master' => true)); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') + ->disableOriginalConstructor() + ->getMock(); + + self::$DI['app']['notification.deliverer']->expects($this->atLeastOnce()) + ->method('deliver') + ->with($this->isInstanceOf('Alchemy\Phrasea\Notification\Mail\MailInfoNewOrder'), $this->equalTo(null)); + return \set_order::create( self::$DI['app'], new RecordsRequest($receveid, new ArrayCollection($receveid), $basket), self::$DI['user_alt2'], 'I need this photos', new \DateTime('+10 minutes') );