From 6485b64e683d75f816761ca2f26c7bb8fa4482c1 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 20 Aug 2014 15:13:41 +0200 Subject: [PATCH] Fix latest merge --- lib/Alchemy/Phrasea/Controller/Api/V1.php | 22 ++++++------ .../Subscriber/PhraseaLocaleSubscriber.php | 34 +++++-------------- .../SphinxSearch/ConfigurationPanel.php | 2 +- .../web/prod/actions/Tools/index.html.twig | 6 ++-- .../Alchemy/Tests/Phrasea/ApplicationTest.php | 2 +- .../Setup/XSendFileMappingGeneratorTest.php | 5 +++ .../Phrasea/Controller/Api/ApiTestCase.php | 14 ++++---- .../Tests/Phrasea/Controller/SetupTest.php | 3 -- .../Fixtures/configuration-setup.yml | 1 - .../PhraseaLocaleSubscriberTest.php | 15 +++++++- 10 files changed, 50 insertions(+), 54 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1.php b/lib/Alchemy/Phrasea/Controller/Api/V1.php index f708600465..86949afa44 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1.php @@ -1036,8 +1036,8 @@ class V1 implements ControllerProviderInterface $devices = $request->get('devices', []); $mimes = $request->get('mimes', []); - $ret = array_filter(array_map(function ($media) use ($record) { - if (null !== $embed = $this->list_embedable_media($record, $media)) { + $ret = array_filter(array_map(function ($media) use ($record, $app) { + if (null !== $embed = $this->list_embedable_media($app, $record, $media)) { return $embed; } }, $record->get_embedable_medias($devices, $mimes))); @@ -1063,8 +1063,8 @@ class V1 implements ControllerProviderInterface $devices = $request->get('devices', []); $mimes = $request->get('mimes', []); - $ret = array_filter(array_map(function ($media) use ($record) { - if (null !== $embed = $this->list_embedable_media($record, $media)) { + $ret = array_filter(array_map(function ($media) use ($record, $app) { + if (null !== $embed = $this->list_embedable_media($app, $record, $media)) { return $embed; } }, $record->get_embedable_medias($devices, $mimes))); @@ -1555,19 +1555,19 @@ class V1 implements ControllerProviderInterface * @param media_subdef $media * @return array */ - private function list_embedable_media(\record_adapter $record, \media_subdef $media) + private function list_embedable_media(Application $app, \record_adapter $record, \media_subdef $media) { if (!$media->is_physically_present()) { return null; } - if ($this->app['authentication']->isAuthenticated()) { - if ($media->get_name() !== 'document' && false === $this->app['acl']->get($this->app['authentication']->getUser())->has_access_to_subdef($record, $media->get_name())) { + if ($app['authentication']->isAuthenticated()) { + if ($media->get_name() !== 'document' && false === $app['acl']->get($app['authentication']->getUser())->has_access_to_subdef($record, $media->get_name())) { return null; } if ($media->get_name() === 'document' - && !$this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'candwnldhd') - && !$this->app['acl']->get($this->app['authentication']->getUser())->has_hd_grant($record)) { + && !$app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'candwnldhd') + && !$app['acl']->get($app['authentication']->getUser())->has_hd_grant($record)) { return null; } } @@ -1757,7 +1757,7 @@ class V1 implements ControllerProviderInterface 'created_on' => $record->get_creation_date()->format(DATE_ATOM), 'collection_id' => \phrasea::collFromBas($app, $record->get_base_id()), 'sha256' => $record->get_sha256(), - 'thumbnail' => $this->list_embedable_media($record, $record->get_thumbnail()), + 'thumbnail' => $this->list_embedable_media($app, $record, $record->get_thumbnail()), 'technical_informations' => $technicalInformation, 'phrasea_type' => $record->get_type(), 'uuid' => $record->get_uuid(), @@ -1802,7 +1802,7 @@ class V1 implements ControllerProviderInterface 'updated_on' => $story->get_modification_date()->format(DATE_ATOM), 'created_on' => $story->get_creation_date()->format(DATE_ATOM), 'collection_id' => \phrasea::collFromBas($app, $story->get_base_id()), - 'thumbnail' => $this->list_embedable_media($story, $story->get_thumbnail()), + 'thumbnail' => $this->list_embedable_media($app, $story, $story->get_thumbnail()), 'uuid' => $story->get_uuid(), 'metadatas' => [ '@entity@' => self::OBJECT_TYPE_STORY_METADATA_BAG, diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriber.php index d7b2d239a2..efadff7a38 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriber.php @@ -59,39 +59,21 @@ class PhraseaLocaleSubscriber implements EventSubscriberInterface return; } - $confLocale = $this->app['locale']; - - $this->app['locale'] = $this->app->share(function (Application $app) use ($event, $confLocale) { - if (!$app['configuration.store']->isSetup()) { - $event->getRequest()->setDefaultLocale($confLocale); - $event->getRequest()->setLocale($confLocale); - } - - $languages = $app['locales.available']; - if ($event->getRequest()->cookies->has('locale') - && isset($languages[$event->getRequest()->cookies->get('locale')])) { - $event->getRequest()->setLocale($event->getRequest()->cookies->get('locale')); - - return $event->getRequest()->getLocale(); - } + $event->getRequest()->setLocale($this->app['locale']); + if ($event->getRequest()->cookies->has('locale') + && isset($this->app['locales.available'][$event->getRequest()->cookies->get('locale')])) { + $event->getRequest()->setLocale($event->getRequest()->cookies->get('locale')); + } else { foreach ($event->getRequest()->getLanguages() as $code) { $data = preg_split('/[-_]/', $code); - if (in_array($data[0], array_keys($app['locales.available']), true)) { + if (in_array($data[0], array_keys($this->app['locales.available']), true)) { $event->getRequest()->setLocale($data[0]); - $localeSet = true; - break; } } + } - if (!$event->getRequest()->getLocale()) { - $event->getRequest()->setLocale($confLocale); - } - - return $event->getRequest()->getLocale(); - }); - - $this->locale = $this->app['locale']; + $this->locale = $this->app['locale'] = $event->getRequest()->getLocale(); } public function addLocaleCookie(FilterResponseEvent $event) diff --git a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php index af0e7882c1..2264e6875f 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/ConfigurationPanel.php @@ -49,7 +49,7 @@ class ConfigurationPanel extends AbstractConfigurationPanel 'configuration' => $configuration, 'configfile' => $this->generateSphinxConf($app['phraseanet.appbox']->get_databoxes(), $configuration), 'charsets' => $this->getAvailableCharsets(), - 'date_fields' => $this->RecordgetAvailableDateFields($app['phraseanet.appbox']->get_databoxes()), + 'date_fields' => $this->getAvailableDateFields($app['phraseanet.appbox']->get_databoxes()), ]; return $app['twig']->render('admin/search-engine/sphinx-search.html.twig', $params); diff --git a/templates/web/prod/actions/Tools/index.html.twig b/templates/web/prod/actions/Tools/index.html.twig index c0eb82f68c..da9d7676fd 100644 --- a/templates/web/prod/actions/Tools/index.html.twig +++ b/templates/web/prod/actions/Tools/index.html.twig @@ -238,7 +238,7 @@
-  {% trans "image rotation" %}  +  {{ "image rotation" | trans }} 
- - + +
diff --git a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php index 5ecec74c0c..9c01ff1686 100644 --- a/tests/Alchemy/Tests/Phrasea/ApplicationTest.php +++ b/tests/Alchemy/Tests/Phrasea/ApplicationTest.php @@ -109,7 +109,7 @@ class ApplicationTest extends \PhraseanetTestCase public function testCookieLocale() { foreach (array_keys(Application::getAvailableLanguages()) as $locale) { - $client = $this->getClientWithCookie( $this->getAppThatReturnLocale(), $locale); + $client = $this->getClientWithCookie($this->getAppThatReturnLocale(), $locale); $client->request('GET', '/'); $this->assertEquals($locale, $client->getResponse()->getContent()); diff --git a/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php b/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php index 23fc16cc5a..f30a0b4897 100644 --- a/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php @@ -19,6 +19,11 @@ class XSendFileMappingGeneratorTest extends \PhraseanetTestCase ->with('type') ->will($this->returnValue('nginx')); + $input->expects($this->any()) + ->method('getOption') + ->with($this->isType('string')) + ->will($this->returnValue($option)); + $command = new XSendFileMappingGenerator(); self::$DI['cli']['monolog'] = self::$DI['cli']->share(function () { diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php index ecadd9a31b..7ddc4dab83 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php @@ -903,7 +903,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase { $this->setToken($this->userAccessToken); - self::$DI['acl']->get(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( + self::$DI['app']['acl']->get(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( 'candwnldpreview' => 1, 'candwnldhd' => 1 )); @@ -939,14 +939,14 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase public function testRecordsEmbedRouteNoHdRights() { - $this->setToken(self::$token); + $this->setToken($this->userAccessToken); - self::$DI['acl']->get(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( + self::$DI['app']['acl']->get(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( 'candwnldpreview' => 1, 'candwnldhd' => 0 )); - $route = '/api/v1/records/' . $this->record->get_sbas_id() . '/' . $this->record->get_record_id() . '/embed/'; + $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; self::$DI['client']->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); @@ -963,14 +963,14 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase public function testRecordsEmbedRouteNoPreviewAndHdRights() { - $this->setToken(self::$token); + $this->setToken($this->userAccessToken); - self::$DI['user_notAdmin']->ACL()->update_rights_to_base(self::$DI['collection']->get_base_id(), array( + self::$DI['app']['acl']->get(self::$DI['user_notAdmin'])->update_rights_to_base(self::$DI['collection']->get_base_id(), array( 'candwnldpreview' => 0, 'candwnldhd' => 0 )); - $route = '/api/v1/records/' . $this->record->get_sbas_id() . '/' . $this->record->get_record_id() . '/embed/'; + $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; self::$DI['client']->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php index bcc3d0b75c..ea0c4aa01c 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php @@ -103,9 +103,6 @@ class SetupTest extends \PhraseanetWebTestCase ->getMock(); $user = $this->createUserMock(); - $user->expects($this->once()) - ->method('getId') - ->will($this->returnValue(self::$DI['user']->getId())); $this->app['phraseanet.installer']->expects($this->once()) ->method('install') diff --git a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml index ca7352a1a7..2121849d12 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml +++ b/tests/Alchemy/Tests/Phrasea/Core/Configuration/Fixtures/configuration-setup.yml @@ -30,7 +30,6 @@ main: options: [] task-manager: status: started - enabled: started enabled: true logger: max-files: 10 diff --git a/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriberTest.php b/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriberTest.php index a91567e1fa..ff9e003c81 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriberTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Event/Subscriber/PhraseaLocaleSubscriberTest.php @@ -108,6 +108,9 @@ class PhraseaLocaleSubscriberTest extends \PhraseanetTestCase $app['debug'] = true; $app->register(new LocaleServiceProvider()); $app['configuration.store'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface'); + $app['configuration.store']->expects($this->any()) + ->method('isSetup') + ->will($this->returnValue(true)); $app['conf'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\PropertyAccess') ->disableOriginalConstructor() ->getMock(); @@ -125,7 +128,17 @@ class PhraseaLocaleSubscriberTest extends \PhraseanetTestCase { $app['conf']->expects($this->any()) ->method('get') - ->will($this->returnValue($locale)); + ->will($this->returnCallback(function ($param) use ($locale) { + + switch ($param) { + case ['languages', 'default']: + return $locale; + break; + case ['languages', 'available']: + return []; + break; + } + })); } private function getClientWithCookie(Application $app, $locale = 'fr')