Fix unit tests

This commit is contained in:
Romain Neutron
2013-01-28 19:31:26 +01:00
parent 2fb0c60157
commit aa18c48306
43 changed files with 582 additions and 256 deletions

View File

@@ -238,7 +238,7 @@ class Export implements ControllerProviderInterface
$list = $download->prepare_export( $list = $download->prepare_export(
$app['phraseanet.user'], $app['phraseanet.user'],
$app['filesystem'], $app['filesystem'],
$request->request->get('obj'), (array) $request->request->get('obj'),
$request->request->get("type") == "title" ? : false, $request->request->get("type") == "title" ? : false,
$request->request->get('businessfields') $request->request->get('businessfields')
); );
@@ -288,8 +288,8 @@ class Export implements ControllerProviderInterface
$receiver = new Receiver(null, trim($mail)); $receiver = new Receiver(null, trim($mail));
$mail = MailRecordsExport::create($app, $receiver, $emitter, $request->request->get('textmail')); $mail = MailRecordsExport::create($app, $receiver, $emitter, $request->request->get('textmail'));
$mail->setUrl($url); $mail->setButtonUrl($url);
$mail->setEnddate($endDateObject); $mail->setExpiration($endDateObject);
try { try {
$app['notification.deliverer']->deliver($mail); $app['notification.deliverer']->deliver($mail);

View File

@@ -21,7 +21,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\Serializer\Serializer;
/** /**
* Upload controller collection * Upload controller collection

View File

@@ -296,13 +296,13 @@ class Account implements ControllerProviderInterface
} }
try { try {
$date = new DateTime('1 day'); $date = new \DateTime('1 day');
$token = random::getUrlToken($app, \random::TYPE_EMAIL, $app['phraseanet.user']->get_id(), $date, $app['phraseanet.user']->get_email()); $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; $url = $app['phraseanet.registry']->get('GV_ServerName') . 'account/reset-email/?token=' . $token;
$receiver = Receiver::fromUser($app['phraseanet.user']); $receiver = Receiver::fromUser($app['phraseanet.user']);
$mail = MailRequestEmailUpdate::create($app, $receiver, null); $mail = MailRequestEmailUpdate::create($app, $receiver, null);
$mail->setUrl($url); $mail->setButtonUrl($url);
$mail->setExpiration($date); $mail->setExpiration($date);
$app['notification.deliverer']->deliver($mail); $app['notification.deliverer']->deliver($mail);

View File

@@ -287,17 +287,23 @@ class Login implements ControllerProviderInterface
\random::removeToken($app, $code); \random::removeToken($app, $code);
if (\Swift_Validate::email($user->get_email())) { if (!\Swift_Validate::email($user->get_email())) {
if (count($user->ACL()->get_granted_base()) > 0) { return $app->redirect('/login/?redirect=prod&notice=invalid-email');
$mail = MailSuccessEmailConfirmationRegistered::create($app, Receiver::fromUser($user)); }
$app['notification.deliverer']->deliver($mail);
}
$user->set_mail_locked(false); $user->set_mail_locked(false);
\random::removeToken($app, $code); \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&notice=confirm-ok');
} else {
$mail = MailSuccessEmailConfirmationUnregistered::create($app, Receiver::fromUser($user)); $mail = MailSuccessEmailConfirmationUnregistered::create($app, Receiver::fromUser($user));
$app['notification.deliverer']->deliver($mail); $app['notification.deliverer']->deliver($mail);
return $app->redirect('/login/?redirect=prod&notice=confirm-ok-wait');
} }
} }
@@ -328,13 +334,9 @@ class Login implements ControllerProviderInterface
$mail = MailRequestEmailConfirmation::create($app, Receiver::fromUser($user)); $mail = MailRequestEmailConfirmation::create($app, Receiver::fromUser($user));
$mail->setButtonUrl($url); $mail->setButtonUrl($url);
$app['notification.deliverer']->deliver($mail);
try { return $app->redirect($app['url_generator']->generate('login_forgot_password', array('sent' => 'ok')));
$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')));
}
} }
} }
@@ -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')) $user->set_gender($request->request->get('form_gender'))
->set_firstname($request->request->get('form_firstname')) ->set_firstname($request->request->get('form_firstname'))
->set_lastname($request->request->get('form_lastname')) ->set_lastname($request->request->get('form_lastname'))
->set_address($request->request->get('form_address')) ->set_address($request->request->get('form_address'))
->set_zip($request->request->get('form_zip')) ->set_zip($request->request->get('form_zip'))
->set_tel($request->request->get('form_phone')) ->set_tel($request->request->get('form_phone'))
->set_fax($request->request->get('form_fax')) ->set_fax($request->request->get('form_fax'))
->set_job($request->request->get('form_job')) ->set_job($request->request->get('form_job'))
->set_company($request->request->get('form_company')) ->set_company($request->request->get('form_company'))
->set_position($request->request->get('form_activity')) ->set_position($request->request->get('form_activity'))
->set_geonameid($request->request->get('form_geonameid')); ->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) { foreach (array_keys($inscOK) as $base_id) {
$base_ids[] = $base_id; $base_ids[] = $base_id;
}
$user->ACL()->apply_model($template_user, $base_ids);
} }
$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);
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');
} }
$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');
} }
/** /**

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Phrasea\Core\Provider; namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Notification\Deliverer; use Alchemy\Phrasea\Notification\Deliverer;
use Alchemy\Phrasea\Notification\Emitter;
use Silex\Application; use Silex\Application;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
@@ -10,8 +11,24 @@ class NotificationDelivererServiceProvider implements ServiceProviderInterface
{ {
public function register(Application $app) 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) { $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']
);
}); });
} }

View File

@@ -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)); $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)); $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($mailOldAddress); $this->app['notification.deliverer']->deliver($mailNewAddress);
$this->app['notification.deliverer']->deliver($mailNewAddress);
} catch (\Exception $e) {
}
} }
return $this; return $this;

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Helper\User;
use Alchemy\Phrasea\Helper\Helper; use Alchemy\Phrasea\Helper\Helper;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup; use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup;
use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationUnregistered;
/** /**
* *
@@ -183,7 +184,7 @@ class Manage extends Helper
if (false !== $urlToken) { if (false !== $urlToken) {
$mail = MailSuccessEmailConfirmationUnregistered::create($this->app, Receiver::fromUser($createdUser)); $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); $this->app['notification.deliverer']->deliver($mail);
} }
} }

View File

@@ -50,7 +50,10 @@ class Emitter implements EmitterInterface
public static function fromUser(\User_Adapter $user) public static function fromUser(\User_Adapter $user)
{ {
if (!\Swift_Validate::email($user->get_email())) { 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()); return new static($user->get_display_name(), $user->get_email());

View File

@@ -50,7 +50,10 @@ class Receiver implements ReceiverInterface
public static function fromUser(\User_Adapter $user) public static function fromUser(\User_Adapter $user)
{ {
if (!\Swift_Validate::email($user->get_email())) { 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()); return new static($user->get_display_name(), $user->get_email());

View File

@@ -1463,10 +1463,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
if (!$session->hasModuleId($app_id)) { if (!$session->hasModuleId($app_id)) {
$module = new \Entities\SessionModule(); $module = new \Entities\SessionModule();
$module->setModuleId($app_id); $module->setModuleId($app_id);
$module->setSession($session); $module->setSession($session);
$session->addSessionModule($module);
$app['EM']->persist($module); $app['EM']->persist($module);
$app['EM']->persist($session); $app['EM']->persist($session);
$app['EM']->flush();
} }

View File

@@ -110,6 +110,12 @@ class User_Query implements User_QueryInterface
*/ */
protected $only_templates = false; protected $only_templates = false;
/**
*
* @var boolean
*/
protected $email_not_null = false;
/** /**
* *
* @var Array * @var Array
@@ -222,6 +228,10 @@ class User_Query implements User_QueryInterface
$sql .= ' AND usr.invite=0 '; $sql .= ' AND usr.invite=0 ';
} }
if ( ! $this->email_not_null) {
$sql .= ' AND usr.usr_mail IS NOT NULL ';
}
if ($this->only_templates === true) { if ($this->only_templates === true) {
$sql .= ' AND model_of = ' . $this->app['phraseanet.user']->get_id(); $sql .= ' AND model_of = ' . $this->app['phraseanet.user']->get_id();
} elseif ($this->include_templates === false) { } elseif ($this->include_templates === false) {
@@ -439,6 +449,18 @@ class User_Query implements User_QueryInterface
return $this; return $this;
} }
/**
*
* @param boolean $boolean
* @return User_Query
*/
public function email_not_null($boolean)
{
$this->email_not_null = ! ! $boolean;
return $this;
}
/** /**
* *
* @param array $rights * @param array $rights

View File

@@ -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", _('admin::compte-utilisateur email'), $registeredUser->get_email());
$body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->get_company()); $body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->get_company());
$receiver = Receiver::fromUser($to); $readyToSend = false;
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body);
try { try {
$this->app['notification.deliverer']->deliver($mail); $receiver = Receiver::fromUser($to);
$readyToSend = true;
} catch (Exception $e) {
return true;
} catch (\Exception $e) {
} }
return false; if ($readyToSend) {
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body);
$this->app['notification.deliverer']->deliver($mail);
}
return true;
} }
/** /**

View File

@@ -82,19 +82,24 @@ class eventsmanager_notify_bridgeuploadfail extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['usr_id'])) { if ($this->shouldSendNotificationFor($params['usr_id'])) {
$user = User_Adapter::getInstance($params['usr_id'], $this->app);
$readyToSend = false;
try { try {
$user = User_Adapter::getInstance($params['usr_id'], $this->app);
$account = Bridge_Account::load_account($this->app, $params['account_id']); $account = Bridge_Account::load_account($this->app, $params['account_id']);
$readyToSend = true;
} catch (\Exception $e) {
}
if ($readyToSend) {
$receiver = Receiver::fromUser($user); $receiver = Receiver::fromUser($user);
/** ADD MAIL TEST */
$mail = MailInfoBridgeUploadFailed::create($this->app, $receiver); $mail = MailInfoBridgeUploadFailed::create($this->app, $receiver);
$mail->setAdapter($account->get_api()->get_connector()->get_name()); $mail->setAdapter($account->get_api()->get_connector()->get_name());
$mail->setReason($params['reason']); $mail->setReason($params['reason']);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -67,7 +67,10 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
$Query = new \User_Query($this->app); $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()) { if ($entry->get_feed()->get_collection()) {
$Query->on_base_ids(array($entry->get_feed()->get_collection()->get_base_id())); $Query->on_base_ids(array($entry->get_feed()->get_collection()->get_base_id()));
@@ -89,26 +92,32 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($user_to_notif->get_id())) { if ($this->shouldSendNotificationFor($user_to_notif->get_id())) {
$readyToSend = false;
$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;
try { 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); $receiver = Receiver::fromUser($user_to_notif);
$readyToSend = true;
} catch (\Exception $e) {
}
if ($readyToSend) {
$mail = MailInfoNewPublication::create($this->app, $receiver); $mail = MailInfoNewPublication::create($this->app, $receiver);
$mail->setButtonUrl($url); $mail->setButtonUrl($url);
$mail->setAuthor($entry->get_author_name()); $mail->setAuthor($entry->get_author_name());
$mail->setTitle($entry->get_title()); $mail->setTitle($entry->get_title());
$mailed = true;
} catch (\Exception $e) {
$this->app['notification.deliverer']->deliver($mail);
$mailed = true;
} }
} }

View File

@@ -111,15 +111,20 @@ class eventsmanager_notify_order extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($user->get_id())) { if ($this->shouldSendNotificationFor($user->get_id())) {
$readyToSend = false;
try { try {
$receiver = Receiver::fromUser($user); $receiver = Receiver::fromUser($user);
$readyToSend = true;
} catch (Exception $e) {
continue;
}
if ($readyToSend) {
$mail = MailInfoNewOrder::create($this->app, $receiver); $mail = MailInfoNewOrder::create($this->app, $receiver);
$mail->setUser($orderInitiator); $mail->setUser($orderInitiator);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -96,30 +96,29 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['to'])) { if ($this->shouldSendNotificationFor($params['to'])) {
$readyToSend = false;
try { try {
$user_from = User_Adapter::getInstance($params['from'], $this->app); $user_from = User_Adapter::getInstance($params['from'], $this->app);
$user_to = User_Adapter::getInstance($params['to'], $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); $receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from); $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 = MailInfoOrderDelivered::create($this->app, $receiver, $emitter);
$mail->setBasket($basket); $mail->setBasket($basket);
$mail->setDeliverer($user_from); $mail->setDeliverer($user_from);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (Exception $e) {
} }
} }

View File

@@ -76,17 +76,22 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['to'])) { if ($this->shouldSendNotificationFor($params['to'])) {
$readyToSend = false;
try { try {
$user_from = User_Adapter::getInstance($params['from'], $this->app); $user_from = User_Adapter::getInstance($params['from'], $this->app);
$user_to = User_Adapter::getInstance($params['to'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app);
} catch (Exception $e) {
return false;
}
try {
$receiver = Receiver::fromUser($user_to); $receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from); $emitter = Emitter::fromUser($user_from);
$readyToSend = true;
} catch (Exception $e) {
}
if ($readyToSend) {
$mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter); $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
$mail->setQuantity($params['n']); $mail->setQuantity($params['n']);
$mail->setDeliverer($user_from); $mail->setDeliverer($user_from);
@@ -94,8 +99,6 @@ class eventsmanager_notify_ordernotdelivered extends eventsmanager_notifyAbstrac
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -83,6 +83,8 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['to'])) { if ($this->shouldSendNotificationFor($params['to'])) {
$readyToSend = false;
try { try {
$repository = $this->app['EM']->getRepository('\Entities\Basket'); $repository = $this->app['EM']->getRepository('\Entities\Basket');
$basket = $repository->find($params['ssel_id']); $basket = $repository->find($params['ssel_id']);
@@ -92,7 +94,12 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
$receiver = Receiver::fromUser($user_from); $receiver = Receiver::fromUser($user_from);
$emitter = Emitter::fromUser($user_to); $emitter = Emitter::fromUser($user_to);
$readyToSend = true;
} catch (Exception $e) {
}
if ($readyToSend) {
$mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message']); $mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message']);
$mail->setBasket($basket); $mail->setBasket($basket);
$mail->setPusher($user_from); $mail->setPusher($user_from);
@@ -100,8 +107,6 @@ class eventsmanager_notify_push extends eventsmanager_notifyAbstract
$this->app['notification.deliverer']->deliver($mail, $params['accuse']); $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
$mailed = true; $mailed = true;
} catch (Exception $e) {
} }
} }

View File

@@ -119,18 +119,22 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($usr_id)) { if ($this->shouldSendNotificationFor($usr_id)) {
$readyToSend = false;
try { try {
$admin_user = User_Adapter::getInstance($usr_id, $this->app); $admin_user = User_Adapter::getInstance($usr_id, $this->app);
$receiver = Receiver::fromUser($admin_user); $receiver = Receiver::fromUser($admin_user);
$readyToSend = true;
} catch (Exception $e) {
continue;
}
if ($readyToSend) {
$mail = MailInfoUserRegistered::create($this->app, $receiver); $mail = MailInfoUserRegistered::create($this->app, $receiver);
$mail->setRegisteredUser($registeredUser); $mail->setRegisteredUser($registeredUser);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (Exception $e) {
continue;
} }
} }

View File

@@ -110,13 +110,18 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($user->get_id())) { if ($this->shouldSendNotificationFor($user->get_id())) {
$readyToSend = false;
try { try {
$receiver = Receiver::fromUser($user); $receiver = Receiver::fromUser($user);
$readyToSend = true;
} catch (Exception $e) {
}
if ($readyToSend) {
$mail = MailInfoRecordQuarantined::create($this->app, $receiver); $mail = MailInfoRecordQuarantined::create($this->app, $receiver);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -10,8 +10,9 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest; use Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest;
use Alchemy\Phrasea\Notification\Emitter;
use Alchemy\Phrasea\Notification\Receiver;
class eventsmanager_notify_validate extends eventsmanager_notifyAbstract class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
{ {
@@ -89,34 +90,32 @@ class eventsmanager_notify_validate extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['to'])) { if ($this->shouldSendNotificationFor($params['to'])) {
$readyToSend = false;
try { try {
$user_from = User_Adapter::getInstance($params['from'], $this->app); $user_from = User_Adapter::getInstance($params['from'], $this->app);
$user_to = User_Adapter::getInstance($params['to'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app);
} catch (Exception $e) {
return false;
}
try {
$basket = $this->app['EM'] $basket = $this->app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->find($params['ssel_id']); ->find($params['ssel_id']);
$title = $basket->getName(); $title = $basket->getName();
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$readyToSend = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$title = '';
} }
$receiver = Receiver::fromUser($user_to); if ($readyToSend) {
$emitter = Receiver::fromUser($user_from);
try {
$mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']); $mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']);
$mail->setButtonUrl($params['url']); $mail->setButtonUrl($params['url']);
$mail->setTitle($title); $mail->setTitle($title);
$this->app['notification.deliverer']->deliver($mail, $params['accuse']); $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -10,8 +10,9 @@
*/ */
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone; use Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone;
use Alchemy\Phrasea\Notification\Emitter;
use Alchemy\Phrasea\Notification\Receiver;
class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
{ {
@@ -85,34 +86,31 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
$mailed = false; $mailed = false;
if ($this->shouldSendNotificationFor($params['to'])) { if ($this->shouldSendNotificationFor($params['to'])) {
$readyToSend = false;
try { try {
$user_from = User_Adapter::getInstance($params['from'], $this->app); $user_from = User_Adapter::getInstance($params['from'], $this->app);
$user_to = User_Adapter::getInstance($params['to'], $this->app); $user_to = User_Adapter::getInstance($params['to'], $this->app);
} catch (Exception $e) {
return false;
}
try {
$basket = $this->app['EM'] $basket = $this->app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->find($params['ssel_id']); ->find($params['ssel_id']);
$title = $basket->getName(); $title = $basket->getName();
$receiver = Receiver::fromUser($user_to);
$emitter = Emitter::fromUser($user_from);
$readyToSend = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$title = '';
} }
$receiver = Receiver::fromUser($user_to); if ($readyToSend) {
$emitter = Receiver::fromUser($user_from);
try {
$mail = MailInfoValidationDone::create($this->app, $receiver, $emitter); $mail = MailInfoValidationDone::create($this->app, $receiver, $emitter);
$mail->setButtonUrl($params['url']); $mail->setButtonUrl($params['url']);
$mail->setTitle($title); $mail->setTitle($title);
$this->app['notification.deliverer']->deliver($mail); $this->app['notification.deliverer']->deliver($mail);
$mailed = true; $mailed = true;
} catch (\Exception $e) {
} }
} }

View File

@@ -26,8 +26,9 @@ abstract class eventsmanager_notifyAbstract extends eventsmanager_eventAbstract
protected function get_prefs($class, $usr_id) protected function get_prefs($class, $usr_id)
{ {
$user = User_Adapter::getInstance($usr_id, $this->app); $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) protected function shouldSendNotificationFor($usr_id)

View File

@@ -1651,6 +1651,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testFeedsContent() 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'; $title = 'Yellow title';
$subtitle = 'Trololololo !'; $subtitle = 'Trololololo !';
@@ -1710,6 +1717,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testFeedEntry() 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'; $title = 'Yellow title';
$subtitle = 'Trololololo !'; $subtitle = 'Trololololo !';
@@ -1749,6 +1763,13 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testFeedEntryNoAccess() 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'; $title = 'Yellow title';
$subtitle = 'Trololololo !'; $subtitle = 'Trololololo !';
@@ -1786,6 +1807,14 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testFeedContent() 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'; $title = 'Yellow title';
$subtitle = 'Trololololo !'; $subtitle = 'Trololololo !';
$entry_title = 'Superman'; $entry_title = 'Superman';

View File

@@ -14,6 +14,15 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function setUp() public function setUp()
{ {
parent::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'); $this->feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], "salut", 'coucou');
$publishers = $this->feed->get_publishers(); $publishers = $this->feed->get_publishers();
$publisher = array_shift($publishers); $publisher = array_shift($publishers);
@@ -316,6 +325,8 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
{ {
$basket = $this->insertOneBasket(); $basket = $this->insertOneBasket();
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone');
$crawler = self::$DI['client']->request('POST', '/lightbox/ajax/SET_RELEASE/' . $basket->getId() . '/'); $crawler = self::$DI['client']->request('POST', '/lightbox/ajax/SET_RELEASE/' . $basket->getId() . '/');
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
$this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('Content-type'));

View File

@@ -54,6 +54,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailTest');
self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/', array( self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/', array(
'email' => self::$DI['user']->get_email() 'email' => self::$DI['user']->get_email()
)); ));

View File

@@ -48,6 +48,7 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRouteRightsApply() public function testRouteRightsApply()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate', 2);
$username = uniqid('user_'); $username = uniqid('user_');
$user = \User_Adapter::create(self::$DI['app'], $username, "test", $username . "@email.com", false); $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); $this->assertTrue($datas->error);
} }
public function testRouteCreateUser() public function testRouteCreateUserAndValidateEmail()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup');
$username = uniqid('user_'); $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(); $response = self::$DI['client']->getResponse();

View File

@@ -174,6 +174,23 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
unset($response, $datas); 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::connect
* @covers Alchemy\Phrasea\Controller\Prod\Export::call * @covers Alchemy\Phrasea\Controller\Prod\Export::call

View File

@@ -42,6 +42,13 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
parent::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( $this->feed = \Feed_Adapter::create(
self::$DI['app'], self::$DI['user'], $this->feed_title, $this->feed_subtitle self::$DI['app'], self::$DI['user'], $this->feed_title, $this->feed_subtitle

View File

@@ -72,11 +72,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testSendOrder() public function testSendOrder()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderDelivered');
$parameters = array(); $parameters = array();
foreach ($order as $id => $element) { foreach ($order as $id => $element) {
$parameters[] = $id; $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()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
$url = parse_url(self::$DI['client']->getResponse()->headers->get('location')); $url = parse_url(self::$DI['client']->getResponse()->headers->get('location'));
parse_str($url['query']); parse_str($url['query']);
@@ -89,11 +92,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testSendOrderJson() public function testSendOrderJson()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderDelivered');
$parameters = array(); $parameters = array();
foreach ($order as $id => $element) { foreach ($order as $id => $element) {
$parameters[] = $id; $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()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
@@ -112,11 +118,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testDenyOrder() public function testDenyOrder()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderCancelled');
$parameters = array(); $parameters = array();
foreach ($order as $id => $element) { foreach ($order as $id => $element) {
$parameters[] = $id; $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()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
$url = parse_url(self::$DI['client']->getResponse()->headers->get('location')); $url = parse_url(self::$DI['client']->getResponse()->headers->get('location'));
parse_str($url['query']); parse_str($url['query']);
@@ -129,11 +138,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testDenyOrderJson() public function testDenyOrderJson()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoOrderCancelled');
$parameters = array(); $parameters = array();
foreach ($order as $id => $element) { foreach ($order as $id => $element) {
$parameters[] = $id; $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(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
@@ -147,6 +159,14 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
private function createOneOrder($usage) 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']); $receveid = array(self::$DI['record_1']->get_serialize_key() => self::$DI['record_1']);
return \set_order::create( return \set_order::create(

View File

@@ -35,6 +35,8 @@ class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRoutePOSTsend() public function testRoutePOSTsend()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoPushReceived', 2);
$route = '/prod/push/send/'; $route = '/prod/push/send/';
$records = array( $records = array(
@@ -69,6 +71,8 @@ class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRoutePOSTvalidate() public function testRoutePOSTvalidate()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationRequest', 3);
$route = '/prod/push/validate/'; $route = '/prod/push/validate/';
$records = array( $records = array(

View File

@@ -204,6 +204,14 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
'toto' '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( $feedEntry = \Feed_Entry_Adapter::create(
self::$DI['app'], self::$DI['app'],
self::$feed, self::$feed,

View File

@@ -72,7 +72,14 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testUpload() 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(
'files' => array( 'files' => array(
new UploadedFile( 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 * @covers Alchemy\Phrasea\Controller\Prod\Upload::upload
*/ */

View File

@@ -185,6 +185,8 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testPostResetMailEmail() public function testPostResetMailEmail()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate');
$password = \random::generatePassword(); $password = \random::generatePassword();
self::$DI['app']['phraseanet.user']->set_password($password); self::$DI['app']['phraseanet.user']->set_password($password);
self::$DI['client']->request('POST', '/account/reset-email/', array( self::$DI['client']->request('POST', '/account/reset-email/', array(
@@ -311,7 +313,6 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testUpdateAccount() public function testUpdateAccount()
{ {
$register = new \appbox_register(self::$DI['app']['phraseanet.appbox']);
$bases = $notifs = array(); $bases = $notifs = array();
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) { 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()); $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" '; $sql = 'SELECT base_id FROM demand WHERE usr_id = :usr_id AND en_cours="1" ';
$stmt = $this->appbox->get_connection()->prepare($sql); $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id())); $stmt->execute(array(':usr_id' => self::$DI['app']['phraseanet.user']->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->assertCount(count($bases), $rs); $this->assertCount(count($bases), $rs);

View File

@@ -127,6 +127,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMail() public function testRegisterConfirmMail()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationRegistered');
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
$email = $this->generateEmail(); $email = $this->generateEmail();
$appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']); $appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']);
@@ -139,7 +141,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isRedirect()); $this->assertTrue($response->isRedirect());
$this->assertEquals('/login/?redirect=prod&notice=confirm-ok-wait', $response->headers->get('location')); $this->assertEquals('/login/?redirect=prod&notice=confirm-ok', $response->headers->get('location'));
$this->assertFalse(self::$DI['user']->get_mail_locked()); $this->assertFalse(self::$DI['user']->get_mail_locked());
} }
@@ -148,11 +150,15 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMailNoCollAwait() 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(); self::$DI['app']->closeAccount();
$email = $this->generateEmail(); $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(); $this->deleteRequest();
@@ -161,7 +167,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue($response->isRedirect()); $this->assertTrue($response->isRedirect());
$this->assertEquals('/login/?redirect=prod&notice=confirm-ok', $response->headers->get('location')); $this->assertEquals('/login/?redirect=prod&notice=confirm-ok-wait', $response->headers->get('location'));
$user->delete();
} }
/** /**
@@ -195,6 +202,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRenewPasswordMail() public function testRenewPasswordMail()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation');
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('POST', '/login/forgot-password/', array('mail' => self::$DI['user']->get_email())); self::$DI['client']->request('POST', '/login/forgot-password/', array('mail' => self::$DI['user']->get_email()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -562,6 +571,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testPostRegister() public function testPostRegister()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation');
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
$bases = array(); $bases = array();
@@ -633,6 +644,8 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testSendConfirmMail() public function testSendConfirmMail()
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation');
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => self::$DI['user']->get_id())); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => self::$DI['user']->get_id()));

View File

@@ -71,9 +71,93 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
protected static $feed_4_public_subtitle = 'Feed 4 subtitle'; protected static $feed_4_public_subtitle = 'Feed 4 subtitle';
protected $client; protected $client;
private static $initialized = false;
public function setUp() public function setUp()
{ {
parent::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::$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::$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"); 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'); $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() public static function tearDownAfterClass()

View File

@@ -5,12 +5,12 @@ namespace Alchemy\Tests\Phrasea\Core\Provider;
/** /**
* @covers Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider * @covers Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider
*/ */
class ConfigurationTesterServiceProvidertest extends ServiceProviderTestCase class NotificationDelivererServiceProvidertest extends ServiceProviderTestCase
{ {
public function provideServiceDescription() public function provideServiceDescription()
{ {
return array( 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'),
); );
} }
} }

View File

@@ -95,6 +95,14 @@ class Feed_Entry_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSetFeed() 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); $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']); $publisher = Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $new_feed, self::$DI['user']);

View File

@@ -73,6 +73,8 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
self::generateRecords($application); self::generateRecords($application);
self::$DI['user']->set_email('valid@phraseanet.com');
self::$updated = true; self::$updated = true;
} }
} }
@@ -103,8 +105,9 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
\PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Warning::$enabled = true;
\PHPUnit_Framework_Error_Notice::$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'; $environment = 'test';
$app = require __DIR__ . '/../../lib/Alchemy/Phrasea/Application/Root.php'; $app = require __DIR__ . '/../../lib/Alchemy/Phrasea/Application/Root.php';
@@ -124,6 +127,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
return $browser; 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; return $app;
}); });
@@ -873,4 +885,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$this->assertTrue(is_array($data)); $this->assertTrue(is_array($data));
$this->assertFalse($data['success']); $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));
}
} }

View File

@@ -618,6 +618,13 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_publication() 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(); $date = new DateTime();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));

View File

@@ -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']['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( 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') self::$DI['app'], new RecordsRequest($receveid, new ArrayCollection($receveid), $basket), self::$DI['user_alt2'], 'I need this photos', new \DateTime('+10 minutes')
); );