Fix tests

This commit is contained in:
Nicolas Le Goff
2013-11-05 11:57:54 +01:00
parent 1fdf30c6af
commit 43a2e75c0f
14 changed files with 29 additions and 29 deletions

View File

@@ -75,7 +75,7 @@ class ACLProvider
*/ */
private function hasCache(\User_Adapter $user) 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()]);
} }
/** /**

View File

@@ -210,7 +210,7 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $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( $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array(
'feeds' => $feeds, 'feeds' => $feeds,

View File

@@ -78,7 +78,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload-flash.html.twig', array( 'prod/upload/upload-flash.html.twig', array(
'sessionId' => session_id(), 'sessionId' => session_id(),
'collections' => $this->getGrantedCollections($app['authentication']->getUser()), 'collections' => $this->getGrantedCollections($app['acl']->get($app['authentication']->getUser())),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
)); ));
@@ -98,7 +98,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload.html.twig', array( 'prod/upload/upload.html.twig', array(
'collections' => $this->getGrantedCollections($app['authentication']->getUser()), 'collections' => $this->getGrantedCollections($app['acl']->get($app['authentication']->getUser())),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
)); ));
@@ -269,14 +269,15 @@ class Upload implements ControllerProviderInterface
/** /**
* Get current user's granted collections where he can upload * Get current user's granted collections where he can upload
* *
* @param \User_Adapter $user * @param \ACL $acl The user's ACL.
*
* @return array * @return array
*/ */
private function getGrantedCollections(\User_Adapter $user) private function getGrantedCollections(\ACL $acl)
{ {
$collections = array(); $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(); $databox = $collection->get_databox();
if ( ! isset($collections[$databox->get_sbas_id()])) { if ( ! isset($collections[$databox->get_sbas_id()])) {

View File

@@ -130,7 +130,7 @@
{% if usr.is_template() %} {% if usr.is_template() %}
<img title="{% trans 'This is a template' %}" src="/skins/icons/template.png"/> <img title="{% trans 'This is a template' %}" src="/skins/icons/template.png"/>
{% else %} {% else %}
{% if app['acl'].get(usr.).is_phantom() %} {% if app['acl'].get(usr).is_phantom() %}
<img title="{% trans 'This user has no rights' %}" src="/skins/admin/ghost.png"/> <img title="{% trans 'This user has no rights' %}" src="/skins/admin/ghost.png"/>
{% endif %} {% endif %}
{{usr.get_id()}} {{usr.get_id()}}

View File

@@ -97,7 +97,7 @@
<div id="record_infos" class="PNB"> <div id="record_infos" class="PNB">
<div class="lightbox_container PNB"> <div class="lightbox_container PNB">
{% if basket_element %} {% if basket_element %}
{% set business = app['authentication'].getUser().ACL().has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %} {% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
{{caption.format_caption(basket_element.getRecord(app), '', null, business)}} {{caption.format_caption(basket_element.getRecord(app), '', null, business)}}
{% endif %} {% endif %}
</div> </div>

View File

@@ -22,7 +22,7 @@
</button> </button>
{% endif %} {% 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') %}
<button class="ui-corner-all TOOL_chgcoll_btn basket_window" title="{% trans 'action : collection' %}"> <button class="ui-corner-all TOOL_chgcoll_btn basket_window" title="{% trans 'action : collection' %}">
<img src="/skins/prod/000000/images/chgcoll_history.gif"/> <img src="/skins/prod/000000/images/chgcoll_history.gif"/>
</button> </button>

View File

@@ -21,7 +21,7 @@
</button> </button>
{% endif %} {% 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') %}
<button class="ui-corner-all TOOL_chgcoll_btn story_window" title="{% trans 'action : collection' %}"> <button class="ui-corner-all TOOL_chgcoll_btn story_window" title="{% trans 'action : collection' %}">
<img src="/skins/prod/000000/images/chgcoll_history.gif"/> <img src="/skins/prod/000000/images/chgcoll_history.gif"/>
</button> </button>

View File

@@ -11,7 +11,7 @@
<div style="text-align:center;"> <div style="text-align:center;">
{{record.get_status_icons()|raw}} {{record.get_status_icons()|raw}}
</div> </div>
{% 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() %} {% if record.is_from_reg() %}
{{caption.format_caption(record, '', null, business)}} {{caption.format_caption(record, '', null, business)}}
{% else %} {% else %}

View File

@@ -17,7 +17,7 @@
<div class="printer" title="'{% trans 'action : print' %}" <div class="printer" title="'{% trans 'action : print' %}"
onclick="evt_print('{{record.get_sbas_id()}}_{{record.get_record_id()}}');return(false);"></div> onclick="evt_print('{{record.get_sbas_id()}}_{{record.get_record_id()}}');return(false);"></div>
{% 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') %}
<div class="downloader" title="{% trans 'action : exporter' %}" <div class="downloader" title="{% trans 'action : exporter' %}"
onclick="evt_dwnl('{{record.get_sbas_id()}}_{{record.get_record_id()}}');return(false);"></div> onclick="evt_dwnl('{{record.get_sbas_id()}}_{{record.get_record_id()}}');return(false);"></div>
{% endif %} {% endif %}

View File

@@ -31,8 +31,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
'email' => 'sent' 'email' => 'sent'
)); ));
var_dump(self::$DI['client']->getResponse()->getContent());
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
} }

View File

@@ -25,7 +25,7 @@ class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$crawler = self::$DI['client']->request('POST', '/prod/feeds/requestavailable/'); $crawler = self::$DI['client']->request('POST', '/prod/feeds/requestavailable/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $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) { foreach ($feeds as $one_feed) {
if ($one_feed->isPublisher(self::$DI['user'])) { if ($one_feed->isPublisher(self::$DI['user'])) {
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $one_feed->getId() . "' and @name='feed_proposal[]']")->count()); $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() public function testRoot()
{ {
$crawler = self::$DI['client']->request('GET', '/prod/feeds/'); $crawler = self::$DI['client']->request('GET', '/prod/feeds/');
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $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) { foreach ($feeds as $one_feed) {
$path = CssSelector::toXPath("ul.submenu a[href='/prod/feeds/feed/" . $one_feed->getId() . "/']"); $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()); $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']); $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() . "/"); $crawler = self::$DI['client']->request('GET', '/prod/feeds/feed/' . $feed->getId() . "/");
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();

View File

@@ -77,10 +77,10 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$data = DataUri\Data::buildFromFile(__DIR__ . '/../../../../../files/cestlafete.jpg'); $data = DataURI\Data::buildFromFile(__DIR__ . '/../../../../../files/cestlafete.jpg');
$params = array( $params = array(
'base_id' => self::$DI['collection']->get_base_id(), 'base_id' => self::$DI['collection']->get_base_id(),
'b64_image' => DataUri\Dumper::dump($data) 'b64_image' => DataURI\Dumper::dump($data)
); );
$files = array( $files = array(

View File

@@ -9,12 +9,6 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
*/ */
protected static $object; protected static $object;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$object = self::$DI['app']['acl']->get(self::$DI['user']);
}
public static function tearDownAfterClass() public static function tearDownAfterClass()
{ {
/** /**
@@ -43,6 +37,15 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
parent::tearDownAfterClass(); parent::tearDownAfterClass();
} }
public function setup()
{
parent::setUp();
if (null === self::$object) {
self::$object = self::$DI['app']['acl']->get(self::$DI['user']);
}
}
public function testHasAccesToRecord() public function testHasAccesToRecord()
{ {
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1'])); $this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));

View File

@@ -677,7 +677,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$feedItem = $this->insertOneFeedItem(self::$DI['user']); $feedItem = $this->insertOneFeedItem(self::$DI['user']);
$feed = $feedItem->getEntry()->getFeed(); $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) { foreach ($feeds as $feed) {
$result = $this->object->get_publication($request, $feed->getId(), self::$DI['user']); $result = $this->object->get_publication($request, $feed->getId(), self::$DI['user']);
$this->checkResponseField($result, "feed", 'array'); $this->checkResponseField($result, "feed", 'array');