Fix #1630 : Fix user registration management

This commit is contained in:
Nicolas Le Goff
2013-12-17 13:42:42 +01:00
parent a82c9cc449
commit 3f54fb3f20
4 changed files with 95 additions and 11 deletions

View File

@@ -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 .= '<li>' . \phrasea::bas_labels($bas, $app) . "</li>\n";
$acceptColl[] = \phrasea::bas_labels($bas, $app);
} else {
$deny .= '<li>' . \phrasea::bas_labels($bas, $app) . "</li>\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);
}
}
}

View File

@@ -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/');

25
tests/classes/PDOMock.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* This class is used to mock PDO object with PHPUNIT mock system.
*
* Because __wakeup and __sleep methods are defined as final methods
* We can not serialize a PDO object and therefore we can not mock
* This object using PHPUnit.
*
* To get a mocked PDO object use it as follow :
*
* $mock = $this->getMock('PDOMock')
*/
class PDOMock extends \PDO
{
public function __construct() {}
}

View File

@@ -1001,3 +1001,8 @@ class CsrfTestProvider implements CsrfProviderInterface
return true;
}
}
class PDOMock extends \PDO
{
public function __construct() {}
}