mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00
Merge branch '3.8'
Conflicts: lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Controller/Admin/Users.php lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php tests/classes/PhraseanetPHPUnitAbstract.php tests/classes/unitTestsTest.php
This commit is contained in:
@@ -639,7 +639,7 @@ class Application extends SilexApplication
|
||||
}));
|
||||
$twig->addFilter(new \Twig_SimpleFilter('thesaurus', function (\Twig_Environment $twig, $value) {
|
||||
if (!$value instanceof \ThesaurusValue) {
|
||||
return twig_escape_filter($twig, str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], $value));
|
||||
return str_replace(array('[[em]]', '[[/em]]'), array('<em>', '</em>'), twig_escape_filter($twig, $value));
|
||||
}
|
||||
|
||||
return "<a class=\"bounce\" onclick=\"bounce('" . $value->getField()->get_databox()->get_sbas_id() . "','"
|
||||
@@ -647,7 +647,7 @@ class Application extends SilexApplication
|
||||
. "', '"
|
||||
. str_replace("'", "\\'", $value->getField()->get_name())
|
||||
. "');return(false);\">"
|
||||
. twig_escape_filter($twig, str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], $value->getValue()))
|
||||
. str_replace(array('[[em]]', '[[/em]]'), array('<em>', '</em>'), twig_escape_filter($twig, $value->getValue()))
|
||||
. "</a>";
|
||||
}, ['needs_environment' => true, 'is_safe' => ['html']]));
|
||||
|
||||
|
@@ -17,6 +17,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;
|
||||
|
||||
class Users implements ControllerProviderInterface
|
||||
{
|
||||
@@ -543,31 +545,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" . $app->trans('login::register:email: Vous avez ete accepte sur les collections suivantes :') . implode(', ', $accept). "\n";
|
||||
if (0 !== count($acceptColl)) {
|
||||
$message .= "\n" . $app->trans('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $acceptColl). "\n";
|
||||
}
|
||||
if ($deny != '') {
|
||||
$message .= "\n" . $app->trans('login::register:email: Vous avez ete refuse sur les collections suivantes :') . implode(', ', $deny) . "\n";
|
||||
if (0 !== count($denyColl)) {
|
||||
$message .= "\n" . $app->trans('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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ class LocalesRequirements extends RequirementCollection implements RequirementIn
|
||||
if (defined('INTL_ICU_VERSION')) {
|
||||
$version = INTL_ICU_VERSION;
|
||||
} else {
|
||||
$reflector = new ReflectionExtension('intl');
|
||||
$reflector = new \ReflectionExtension('intl');
|
||||
|
||||
ob_start();
|
||||
$reflector->info();
|
||||
|
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Setup\Version\Migration;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
|
||||
class Migration38 implements MigrationInterface
|
||||
{
|
||||
@@ -58,12 +59,12 @@ class Migration38 implements MigrationInterface
|
||||
|
||||
$app['configuration.store']->setConfig($conf);
|
||||
|
||||
foreach ([
|
||||
foreach (array(
|
||||
$this->configYaml,
|
||||
$this->connexionsYaml,
|
||||
$this->binariesYaml,
|
||||
$this->servicesYaml
|
||||
] as $file) {
|
||||
) as $file) {
|
||||
if (is_file($file)) {
|
||||
rename($file, $file.'.bkp');
|
||||
}
|
||||
@@ -86,7 +87,8 @@ class Migration38 implements MigrationInterface
|
||||
|
||||
if (is_file($this->configYaml)) {
|
||||
$data = $this->yaml->parse($this->configYaml);
|
||||
$conf['main']['key'] = $data['key'];
|
||||
$key = isset($data['key']) ? $data['key'] : $this->fetchInstanceKey();
|
||||
$conf['main']['key'] = $key;
|
||||
$env = $data['environment'];
|
||||
if (isset($data[$env])) {
|
||||
$conf['main']['servername'] = $data[$env]['phraseanet']['servername'];
|
||||
@@ -114,9 +116,11 @@ class Migration38 implements MigrationInterface
|
||||
$conf['main']['cache']['options'] = [];
|
||||
}
|
||||
}
|
||||
if (isset($services['Border'])) {
|
||||
$conf['border-manager'] = $services['Border']['border_manager']['options'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function migrateConnexions(array &$conf)
|
||||
{
|
||||
@@ -127,4 +131,18 @@ class Migration38 implements MigrationInterface
|
||||
$conf['main']['database-test'] = $data['test_connexion'];
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchInstanceKey()
|
||||
{
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare('SELECT `value` FROM registry WHERE `key` = "GV_SIT"');
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$rs) {
|
||||
throw new RuntimeException('Unable to fetch GV_SIT key from registry table.');
|
||||
}
|
||||
|
||||
return $rs['key'];
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,6 @@ class databox extends base
|
||||
assert($sbas_id > 0);
|
||||
|
||||
$this->app = $app;
|
||||
$this->connection = connection::getPDOConnection($app, $sbas_id);
|
||||
$this->id = $sbas_id;
|
||||
|
||||
$connection_params = phrasea::sbas_params($this->app);
|
||||
@@ -120,6 +119,8 @@ class databox extends base
|
||||
throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id));
|
||||
}
|
||||
|
||||
$this->connection = connection::getPDOConnection($app, $sbas_id);
|
||||
|
||||
$this->host = $connection_params[$sbas_id]['host'];
|
||||
$this->port = $connection_params[$sbas_id]['port'];
|
||||
$this->user = $connection_params[$sbas_id]['user'];
|
||||
|
@@ -198,7 +198,7 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract
|
||||
}
|
||||
|
||||
if ($readyToSend) {
|
||||
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body);
|
||||
$mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, null, $body);
|
||||
$this->app['notification.deliverer']->deliver($mail);
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<div style="padding: 4px;">
|
||||
<div style="height:40px; position: relative; z-index: 95;">
|
||||
<div class="title">
|
||||
{{record.get_title(highlight, searchEngine)|raw}}
|
||||
{{record.get_title(highlight, searchEngine)|thesaurus}}
|
||||
</div>
|
||||
<div class="status">
|
||||
{{record.get_status_icons|raw}}
|
||||
|
@@ -412,6 +412,54 @@ class ControllerUsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$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->getMock('PDOStatement');
|
||||
|
||||
$stmt->expects($this->any())
|
||||
->method('fetchAll')
|
||||
->will($this->returnValue([
|
||||
'usr_id' => $id,
|
||||
'base_id' => $baseId,
|
||||
'en_cours' => 1,
|
||||
'refuser' => 0,
|
||||
]));
|
||||
|
||||
$pdo = $this->getMock('PDOMock');
|
||||
|
||||
$pdo->expects($this->any())
|
||||
->method('prepare')
|
||||
->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/');
|
||||
|
19
tests/classes/CsrfTestProvider.php
Normal file
19
tests/classes/CsrfTestProvider.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||
|
||||
/**
|
||||
* This class is used to provide CRSF token in PHPUNIT test suite.
|
||||
*/
|
||||
class CsrfTestProvider implements CsrfProviderInterface
|
||||
{
|
||||
public function generateCsrfToken($intention)
|
||||
{
|
||||
return mt_rand();
|
||||
}
|
||||
|
||||
public function isCsrfTokenValid($intention, $token)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
17
tests/classes/PDOMock.php
Normal file
17
tests/classes/PDOMock.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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() {}
|
||||
}
|
@@ -529,16 +529,3 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
||||
class CsrfTestProvider implements CsrfProviderInterface
|
||||
{
|
||||
public function generateCsrfToken($intention)
|
||||
{
|
||||
return mt_rand();
|
||||
}
|
||||
|
||||
public function isCsrfTokenValid($intention, $token)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,8 @@ class unitTestsTest extends \PhraseanetTestCase
|
||||
"PhraseanetAuthenticatedTestCase.php",
|
||||
"PhraseanetAuthenticatedWebTestCase.php",
|
||||
"PhraseanetPHPUnitListener.php",
|
||||
"PDOMock.php",
|
||||
"CsrfTestProvider.php",
|
||||
];
|
||||
|
||||
$testDir = __DIR__ . '/';
|
||||
|
Reference in New Issue
Block a user