From 43a2e75c0fba2f68cc760942d779e2a542f77f57 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 5 Nov 2013 11:57:54 +0100 Subject: [PATCH] Fix tests --- .../Phrasea/Authentication/ACLProvider.php | 2 +- lib/Alchemy/Phrasea/Controller/Prod/Feed.php | 2 +- lib/Alchemy/Phrasea/Controller/Prod/Upload.php | 11 ++++++----- templates/web/admin/users.html.twig | 2 +- templates/web/lightbox/validate.html.twig | 2 +- templates/web/prod/WorkZone/Basket.html.twig | 2 +- templates/web/prod/WorkZone/Story.html.twig | 2 +- templates/web/prod/preview/caption.html.twig | 2 +- templates/web/prod/preview/tools.html.twig | 2 +- .../Controller/Admin/AdminDashboardTest.php | 2 -- .../Tests/Phrasea/Controller/Prod/FeedTest.php | 8 +++----- .../Tests/Phrasea/Controller/Prod/UploadTest.php | 4 ++-- tests/classes/ACLTest.php | 15 +++++++++------ tests/classes/api/v1/api_v1_adapterTest.php | 2 +- 14 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/Alchemy/Phrasea/Authentication/ACLProvider.php b/lib/Alchemy/Phrasea/Authentication/ACLProvider.php index e3aa66ebef..420a290155 100644 --- a/lib/Alchemy/Phrasea/Authentication/ACLProvider.php +++ b/lib/Alchemy/Phrasea/Authentication/ACLProvider.php @@ -75,7 +75,7 @@ class ACLProvider */ private function hasCache(\User_Adapter $user) { - return array_key_exists($user->get_id(), self::$cache) && self::$cache[$user->get_id()] instanceof \ACL; + return isset(self::$cache[$user->get_id()]); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php index 63d5b7e4d7..36372043eb 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Feed.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Feed.php @@ -210,7 +210,7 @@ class Feed implements ControllerProviderInterface $page = (int) $request->query->get('page'); $page = $page > 0 ? $page : 1; - $feeds = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser($app['authentication']->getUser()); + $feeds = $app['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array( 'feeds' => $feeds, diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php index befcc00892..7486df99fb 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php @@ -78,7 +78,7 @@ class Upload implements ControllerProviderInterface return $app['twig']->render( 'prod/upload/upload-flash.html.twig', array( 'sessionId' => session_id(), - 'collections' => $this->getGrantedCollections($app['authentication']->getUser()), + 'collections' => $this->getGrantedCollections($app['acl']->get($app['authentication']->getUser())), 'maxFileSize' => $maxFileSize, 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) )); @@ -98,7 +98,7 @@ class Upload implements ControllerProviderInterface return $app['twig']->render( 'prod/upload/upload.html.twig', array( - 'collections' => $this->getGrantedCollections($app['authentication']->getUser()), + 'collections' => $this->getGrantedCollections($app['acl']->get($app['authentication']->getUser())), 'maxFileSize' => $maxFileSize, 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) )); @@ -269,14 +269,15 @@ class Upload implements ControllerProviderInterface /** * Get current user's granted collections where he can upload * - * @param \User_Adapter $user + * @param \ACL $acl The user's ACL. + * * @return array */ - private function getGrantedCollections(\User_Adapter $user) + private function getGrantedCollections(\ACL $acl) { $collections = array(); - foreach ($app['acl']->get($user)->get_granted_base(array('canaddrecord')) as $collection) { + foreach ($acl->get_granted_base(array('canaddrecord')) as $collection) { $databox = $collection->get_databox(); if ( ! isset($collections[$databox->get_sbas_id()])) { diff --git a/templates/web/admin/users.html.twig b/templates/web/admin/users.html.twig index e1d8be6afa..7bf3588ecc 100644 --- a/templates/web/admin/users.html.twig +++ b/templates/web/admin/users.html.twig @@ -130,7 +130,7 @@ {% if usr.is_template() %} {% else %} - {% if app['acl'].get(usr.).is_phantom() %} + {% if app['acl'].get(usr).is_phantom() %} {% endif %} {{usr.get_id()}} diff --git a/templates/web/lightbox/validate.html.twig b/templates/web/lightbox/validate.html.twig index a9e60c5ae2..9c4356f2cd 100644 --- a/templates/web/lightbox/validate.html.twig +++ b/templates/web/lightbox/validate.html.twig @@ -97,7 +97,7 @@
diff --git a/templates/web/prod/WorkZone/Basket.html.twig b/templates/web/prod/WorkZone/Basket.html.twig index 41a5f51d73..af94792856 100644 --- a/templates/web/prod/WorkZone/Basket.html.twig +++ b/templates/web/prod/WorkZone/Basket.html.twig @@ -22,7 +22,7 @@ {% endif %} - {% if app['acl'].get(app['authentication'].getUser()).has_right('deleterecord') and app['authentication'].getUser()).has_right('addrecord') %} + {% if app['acl'].get(app['authentication'].getUser()).has_right('deleterecord') and app['acl'].get(app['authentication'].getUser()).has_right('addrecord') %} diff --git a/templates/web/prod/WorkZone/Story.html.twig b/templates/web/prod/WorkZone/Story.html.twig index a24abf6ea2..be7fbd79d8 100644 --- a/templates/web/prod/WorkZone/Story.html.twig +++ b/templates/web/prod/WorkZone/Story.html.twig @@ -21,7 +21,7 @@ {% endif %} - {% if app['acl'].get(app['authentication'].getUser()).has_right('deleterecord') and app['authentication'].getUser()).has_right('addrecord') %} + {% if app['acl'].get(app['authentication'].getUser()).has_right('deleterecord') and app['acl'].get(app['authentication'].getUser()).has_right('addrecord') %} diff --git a/templates/web/prod/preview/caption.html.twig b/templates/web/prod/preview/caption.html.twig index ad0d622baa..98a226273d 100644 --- a/templates/web/prod/preview/caption.html.twig +++ b/templates/web/prod/preview/caption.html.twig @@ -11,7 +11,7 @@
{{record.get_status_icons()|raw}}
- {% set business = app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'canmodifrecord') %} + {% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'canmodifrecord') %} {% if record.is_from_reg() %} {{caption.format_caption(record, '', null, business)}} {% else %} diff --git a/templates/web/prod/preview/tools.html.twig b/templates/web/prod/preview/tools.html.twig index b407e56660..5f9c53d163 100644 --- a/templates/web/prod/preview/tools.html.twig +++ b/templates/web/prod/preview/tools.html.twig @@ -17,7 +17,7 @@
-{% if app['authentication'].getUser().ACL().has_right_on_base(record.get_base_id(), 'candwnldhd') or app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'candwnldpreview') %} +{% if app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'candwnldhd') or app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'candwnldpreview') %}
{% endif %} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php index 2adc9bb05e..6512fac74b 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -31,8 +31,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'email' => 'sent' )); - var_dump(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php index 56673d4691..035848f91b 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php @@ -25,7 +25,7 @@ class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $crawler = self::$DI['client']->request('POST', '/prod/feeds/requestavailable/'); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['app']['acl']->get(self::$DI['user'])); foreach ($feeds as $one_feed) { if ($one_feed->isPublisher(self::$DI['user'])) { $this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $one_feed->getId() . "' and @name='feed_proposal[]']")->count()); @@ -369,17 +369,15 @@ class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRoot() { - $crawler = self::$DI['client']->request('GET', '/prod/feeds/'); $pageContent = self::$DI['client']->getResponse()->getContent(); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['app']['acl']->get(self::$DI['user'])); foreach ($feeds as $one_feed) { - $path = CssSelector::toXPath("ul.submenu a[href='/prod/feeds/feed/" . $one_feed->getId() . "/']"); $msg = sprintf("user %s has access to feed %s", self::$DI['user']->getId(), $one_feed->getId()); @@ -396,7 +394,7 @@ class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $feed = $this->insertOneFeed(self::$DI['user']); - $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['app']['acl']->get(self::$DI['user'])); $crawler = self::$DI['client']->request('GET', '/prod/feeds/feed/' . $feed->getId() . "/"); $pageContent = self::$DI['client']->getResponse()->getContent(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php index 5e4966fda2..46e78d0781 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php @@ -77,10 +77,10 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->disableOriginalConstructor() ->getMock(); - $data = DataUri\Data::buildFromFile(__DIR__ . '/../../../../../files/cestlafete.jpg'); + $data = DataURI\Data::buildFromFile(__DIR__ . '/../../../../../files/cestlafete.jpg'); $params = array( 'base_id' => self::$DI['collection']->get_base_id(), - 'b64_image' => DataUri\Dumper::dump($data) + 'b64_image' => DataURI\Dumper::dump($data) ); $files = array( diff --git a/tests/classes/ACLTest.php b/tests/classes/ACLTest.php index dbbee50ee1..408396061e 100644 --- a/tests/classes/ACLTest.php +++ b/tests/classes/ACLTest.php @@ -9,12 +9,6 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract */ protected static $object; - public static function setUpBeforeClass() - { - parent::setUpBeforeClass(); - self::$object = self::$DI['app']['acl']->get(self::$DI['user']); - } - public static function tearDownAfterClass() { /** @@ -43,6 +37,15 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract parent::tearDownAfterClass(); } + public function setup() + { + parent::setUp(); + + if (null === self::$object) { + self::$object = self::$DI['app']['acl']->get(self::$DI['user']); + } + } + public function testHasAccesToRecord() { $this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1'])); diff --git a/tests/classes/api/v1/api_v1_adapterTest.php b/tests/classes/api/v1/api_v1_adapterTest.php index 3ce6531b57..d9331d8b09 100644 --- a/tests/classes/api/v1/api_v1_adapterTest.php +++ b/tests/classes/api/v1/api_v1_adapterTest.php @@ -677,7 +677,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract $feedItem = $this->insertOneFeedItem(self::$DI['user']); $feed = $feedItem->getEntry()->getFeed(); - $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['user']); + $feeds = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\Feed')->getAllForUser(self::$DI['app']['acl']->get(self::$DI['user'])); foreach ($feeds as $feed) { $result = $this->object->get_publication($request, $feed->getId(), self::$DI['user']); $this->checkResponseField($result, "feed", 'array');