diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php
index efa0131990..cee6b6544f 100644
--- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php
+++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php
@@ -16,6 +16,8 @@ use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
+use Alchemy\Phrasea\Notification\Receiver;
+use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate;
/**
*
@@ -546,31 +548,30 @@ class Users implements ControllerProviderInterface
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
- $accept = $deny = '';
+ $acceptColl = $denyColl = [];
if ($row) {
-
if (\Swift_Validate::email($row['usr_mail'])) {
foreach ($bases as $bas => $isok) {
if ($isok) {
- $accept .= '
' . \phrasea::bas_labels($bas, $app) . "\n";
+ $acceptColl[] = \phrasea::bas_labels($bas, $app);
} else {
- $deny .= '' . \phrasea::bas_labels($bas, $app) . "\n";
+ $denyColl[] = \phrasea::bas_labels($bas, $app);
}
}
- if (($accept != '' || $deny != '')) {
+ if (0 !== count($acceptColl) || 0 !== count($denyColl)) {
$message = '';
- if ($accept != '') {
- $message .= "\n" . _('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $accept). "\n";
+ if (0 !== count($acceptColl)) {
+ $message .= "\n" . _('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $acceptColl). "\n";
}
- if ($deny != '') {
- $message .= "\n" . _('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $deny) . "\n";
+ if (0 !== count($denyColl)) {
+ $message .= "\n" . _('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $denyColl) . "\n";
}
$receiver = new Receiver(null, $row['usr_mail']);
- $mail = MailSuccessEmailUpdate::create($this->app, $receiver, null, $message);
+ $mail = MailSuccessEmailUpdate::create($app, $receiver, null, $message);
- $this->app['notification.deliverer']->deliver($mail);
+ $app['notification.deliverer']->deliver($mail);
}
}
}
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php
index 5b4ea7abfc..9d6c52c3f7 100644
--- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php
@@ -408,6 +408,59 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
}
+ public function testPostDemands()
+ {
+ $id = self::$DI['user_alt1']->get_id();
+ $baseId = self::$DI['collection']->get_base_id();
+ $param = sprintf('%s_%s', $id, $baseId);
+
+ $appbox = self::$DI['app']['phraseanet.appbox'];
+
+ $stmt = $this->getMockBuilder('\mysqli_stmt')
+ ->setMethods(['fetch'])
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stmt->expects($this->any())
+ ->method('fetch')
+ ->will($this->returnValue([
+ 'usr_id' => $id,
+ 'base_id' => $baseId,
+ 'en_cours' => 1,
+ 'refuser' => 0,
+ ]));
+
+ $pdo = $this->getMockBuilder('PDOMock')
+ ->setMethods(['prepare'])
+ ->getMock();
+
+ $pdo->expects($this->any())
+ ->method('get_connection')
+ ->will($this->returnValue($stmt));
+
+ $appbox = $this->getMockBuilder('\appbox')
+ ->setMethods(['get_connection'])
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $appbox->expects($this->any())
+ ->method('get_connection')
+ ->will($this->returnValue($pdo));
+
+ $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate');
+
+ self::$DI['client']->request('POST', '/admin/users/demands/', [
+ 'template' => [],
+ 'accept' => [$param],
+ 'accept_hd' => [$param],
+ 'watermark' => [$param],
+ ]);
+
+ self::$DI['app']['phraseanet.appbox'] = $appbox;
+
+ $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
+ }
+
public function testRenderImportFile()
{
self::$DI['client']->request('GET', '/admin/users/import/file/');
diff --git a/tests/classes/PDOMock.php b/tests/classes/PDOMock.php
new file mode 100644
index 0000000000..698319d844
--- /dev/null
+++ b/tests/classes/PDOMock.php
@@ -0,0 +1,25 @@
+getMock('PDOMock')
+ */
+class PDOMock extends \PDO
+{
+ public function __construct() {}
+}
\ No newline at end of file
diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php
index bfbd6f5d73..749ac916ec 100644
--- a/tests/classes/PhraseanetPHPUnitAbstract.php
+++ b/tests/classes/PhraseanetPHPUnitAbstract.php
@@ -1001,3 +1001,8 @@ class CsrfTestProvider implements CsrfProviderInterface
return true;
}
}
+
+class PDOMock extends \PDO
+{
+ public function __construct() {}
+}