From 8cdd19bcf7ecd44293fa9722a92fa32d197948c4 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Feb 2014 12:15:17 +0100 Subject: [PATCH 1/5] Fix #1689 : Discard wrong XML errors --- lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php index e4b5b75f0d..05628d3949 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php @@ -425,7 +425,7 @@ class Xmlhttp implements ControllerProviderInterface $stmt->closeCursor(); $fields = array(); - if ($row && ($sx = simplexml_load_string($row['xml']))) { + if ($row && ($sx = @simplexml_load_string($row['xml']))) { foreach ($sx->fields->children() as $fn => $fv) { if (!array_key_exists($fn, $fields)) { $fields[$fn] = array(); @@ -460,7 +460,7 @@ class Xmlhttp implements ControllerProviderInterface $stmt->closeCursor(); foreach ($rs as $row) { - if (!($sx = simplexml_load_string($row['xml']))) { + if (!($sx = @simplexml_load_string($row['xml']))) { continue; } $t_desc = array(); From 68e775dfd30a991bff65f71308d5998a2149cb9d Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Feb 2014 14:08:01 +0100 Subject: [PATCH 2/5] Fix #1693 : Guest users should be able to access detailed view --- .../Phrasea/Controller/Prod/Records.php | 14 +++--- .../Phrasea/Controller/Prod/RecordsTest.php | 45 +++++++++++++++++++ tests/classes/PhraseanetPHPUnitAbstract.php | 8 ++-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Records.php b/lib/Alchemy/Phrasea/Controller/Prod/Records.php index ecd35008ba..aae7f085eb 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Records.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Records.php @@ -30,10 +30,6 @@ class Records implements ControllerProviderInterface $app['firewall']->addMandatoryAuthentication($controllers); - $controllers->before(function (Request $request) use ($app) { - $app['firewall']->requireNotGuest(); - }); - /** * Get the record detailed view * @@ -65,7 +61,10 @@ class Records implements ControllerProviderInterface * return : JSON Response */ $controllers->post('/delete/', $this->call('doDeleteRecords')) - ->bind('record_delete'); + ->bind('record_delete') + ->before(function (Request $request) use ($app) { + $app['firewall']->requireNotGuest(); + }); /** * Verify if I can delete records @@ -81,7 +80,10 @@ class Records implements ControllerProviderInterface * return : HTML Response */ $controllers->post('/delete/what/', $this->call('whatCanIDelete')) - ->bind('record_what_can_i_delete'); + ->bind('record_what_can_i_delete') + ->before(function (Request $request) use ($app) { + $app['firewall']->requireNotGuest(); + }); /** * Renew a record URL diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index 696c8d5435..8bb54fa474 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -4,6 +4,8 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod; use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; +use Entities\Basket; +use Entities\BasketElement; /** * @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail @@ -78,6 +80,49 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertBadResponse(self::$DI['client']->getResponse()); } + public function testGetRecordDetailAsGuest() + { + $inviteUsrid = \User_Adapter::get_usr_id_from_login(self::$DI['app'], 'invite'); + $invite_user = \User_Adapter::getInstance($inviteUsrid, self::$DI['app']); + + $this->authenticate(self::$DI['app'], $invite_user); + + $basket = new Basket(); + $basket->setUsrId($inviteUsrid); + $basket->setName('test'); + + self::$DI['app']['EM']->persist($basket); + + $element = new BasketElement(); + $element->setRecord(self::$DI['record_24']); + $element->setBasket($basket); + $basket->addElement($element); + + self::$DI['app']['EM']->persist($element); + self::$DI['app']['EM']->flush(); + + $this->XMLHTTPRequest('POST', '/prod/records/', array( + 'env' => 'BASK', + 'pos' => 0, + 'query' => '', + 'cont' => $basket->getId(), + )); + $response = self::$DI['client']->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($response->getContent(), true); + + $this->assertArrayHasKey('desc', $data); + $this->assertArrayHasKey('html_preview', $data); + $this->assertArrayHasKey('current', $data); + $this->assertArrayHasKey('others', $data); + $this->assertArrayHasKey('history', $data); + $this->assertArrayHasKey('popularity', $data); + $this->assertArrayHasKey('tools', $data); + $this->assertArrayHasKey('pos', $data); + $this->assertArrayHasKey('title', $data); + } + /** * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord */ diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index 782db2a7b7..2742a90043 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -917,12 +917,14 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase return; } - protected function authenticate(Application $app) + protected function authenticate(Application $app, $user = null) { + $user = $user ?: self::$DI['user']; + $app['session']->clear(); - $app['session']->set('usr_id', self::$DI['user']->get_id()); + $app['session']->set('usr_id', $user->get_id()); $session = new \Entities\Session(); - $session->setUsrId(self::$DI['user']->get_id()); + $session->setUsrId($user->get_id()); $session->setUserAgent(''); self::$DI['app']['EM']->persist($session); self::$DI['app']['EM']->flush(); From 28d1ea014239e758e4f62473273f85de2e795400 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Feb 2014 23:19:02 +0100 Subject: [PATCH 3/5] Fix #1690 : Avoid tests failure because a second --- tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index 46e30434b8..4a8b36f024 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -2223,7 +2223,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertArrayHasKey("label", $permalink); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']); $this->assertArrayHasKey("updated_on", $permalink); - $this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['updated_on']); + + $expected = $subdef->get_permalink()->get_last_modified(); + $found = \DateTime::createFromFormat(DATE_ATOM, $permalink['updated_on']); + + $this->assertLessThanOrEqual(1, $expected->diff($found)->format('U')); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']); $this->assertDateAtom($permalink['updated_on']); $this->assertArrayHasKey("page_url", $permalink); From b56edae725897cba09a3eaa5bd2071219723f05a Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Feb 2014 23:30:23 +0100 Subject: [PATCH 4/5] Fix #1686 : Fix jquery ui usage --- templates/web/common/dialog_export.html.twig | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index c508595447..5f3bd9b5a0 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -601,9 +601,6 @@ $(document).ready(function(){ var dialog = p4.Dialog.get(1); var tabs = $('.tabs', dialog.getDomElement()); - if (tabs.data('ui-tabs')) { - tabs.tabs('active',1); - } $('a.TOUview').bind('click', function(){ var options = { @@ -666,9 +663,7 @@ $('input[name="destmail"]', $('#sendmail')).val("{{app['authentication'].getUser().get_email()}}"); var tabs = $('.tabs', dialog.getDomElement()); - if (tabs.data('ui-tabs')) { - tabs.tabs('active',1); - } + tabs.tabs("option", "active", 1); } return; From 66b3ad00229ffcb3fd79358c7df9b671ce2aabdf Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 10 Feb 2014 23:33:25 +0100 Subject: [PATCH 5/5] Fix #1691 : Avoid exception message for users --- lib/Alchemy/Phrasea/Controller/Admin/Users.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 8769e3a82d..990aa13f94 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -271,7 +271,11 @@ class Users implements ControllerProviderInterface $datas['data'] = $user->get_id(); } catch (\Exception $e) { $datas['error'] = true; - $datas['message'] = $e->getMessage(); + if ($request->request->get('template') == '1') { + $datas['message'] = _('Unable to create template, the name is already used.'); + } else { + $datas['message'] = _('Unable to create the user.'); + } } return $app->json($datas);