diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 53a06c6d31..a0112059de 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -268,7 +268,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); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Records.php b/lib/Alchemy/Phrasea/Controller/Prod/Records.php index 7f404f6ad6..b7c5c4e25f 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Records.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Records.php @@ -31,10 +31,6 @@ class Records implements ControllerProviderInterface $app['firewall']->addMandatoryAuthentication($controllers); - $controllers->before(function (Request $request) use ($app) { - $app['firewall']->requireNotGuest(); - }); - $controllers->match('/', 'controller.prod.records:getRecord') ->bind('record_details') ->method('GET|POST'); diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php index 9a11922000..1586ed4169 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php @@ -427,7 +427,7 @@ class Xmlhttp implements ControllerProviderInterface $stmt->closeCursor(); $fields = []; - 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] = []; @@ -462,7 +462,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 = []; diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index b39419c4f5..a7bea94bef 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -593,9 +593,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 = { @@ -658,9 +655,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; diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiTestCase.php b/tests/Alchemy/Tests/Phrasea/Application/ApiTestCase.php index 864c1b3a3a..ba38ba649c 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiTestCase.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiTestCase.php @@ -2104,7 +2104,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase $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); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index 990a79e0d2..3a64f141d3 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 @@ -73,6 +75,49 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $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/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 7934f5f958..92fd49310a 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -499,13 +499,16 @@ abstract class PhraseanetTestCase extends WebTestCase * Authenticates self::['user'] against application. * * @param Application $app + * @param User_Adapter $user */ - 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 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();