Merge branch '3.8'

Conflicts:
	lib/Alchemy/Phrasea/Controller/Prod/Records.php
	lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php
	tests/Alchemy/Tests/Phrasea/Application/ApiTestCase.php
	tests/classes/PhraseanetPHPUnitAbstract.php
This commit is contained in:
Nicolas Le Goff
2014-02-11 09:02:29 +01:00
7 changed files with 64 additions and 17 deletions

View File

@@ -268,7 +268,11 @@ class Users implements ControllerProviderInterface
$datas['data'] = $user->get_id(); $datas['data'] = $user->get_id();
} catch (\Exception $e) { } catch (\Exception $e) {
$datas['error'] = true; $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); return $app->json($datas);

View File

@@ -31,10 +31,6 @@ class Records implements ControllerProviderInterface
$app['firewall']->addMandatoryAuthentication($controllers); $app['firewall']->addMandatoryAuthentication($controllers);
$controllers->before(function (Request $request) use ($app) {
$app['firewall']->requireNotGuest();
});
$controllers->match('/', 'controller.prod.records:getRecord') $controllers->match('/', 'controller.prod.records:getRecord')
->bind('record_details') ->bind('record_details')
->method('GET|POST'); ->method('GET|POST');

View File

@@ -427,7 +427,7 @@ class Xmlhttp implements ControllerProviderInterface
$stmt->closeCursor(); $stmt->closeCursor();
$fields = []; $fields = [];
if ($row && ($sx = simplexml_load_string($row['xml']))) { if ($row && ($sx = @simplexml_load_string($row['xml']))) {
foreach ($sx->fields->children() as $fn => $fv) { foreach ($sx->fields->children() as $fn => $fv) {
if (!array_key_exists($fn, $fields)) { if (!array_key_exists($fn, $fields)) {
$fields[$fn] = []; $fields[$fn] = [];
@@ -462,7 +462,7 @@ class Xmlhttp implements ControllerProviderInterface
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($rs as $row) { foreach ($rs as $row) {
if (!($sx = simplexml_load_string($row['xml']))) { if (!($sx = @simplexml_load_string($row['xml']))) {
continue; continue;
} }
$t_desc = []; $t_desc = [];

View File

@@ -593,9 +593,6 @@
$(document).ready(function(){ $(document).ready(function(){
var dialog = p4.Dialog.get(1); var dialog = p4.Dialog.get(1);
var tabs = $('.tabs', dialog.getDomElement()); var tabs = $('.tabs', dialog.getDomElement());
if (tabs.data('ui-tabs')) {
tabs.tabs('active',1);
}
$('a.TOUview').bind('click', function(){ $('a.TOUview').bind('click', function(){
var options = { var options = {
@@ -658,9 +655,7 @@
$('input[name="destmail"]', $('#sendmail')).val("{{app['authentication'].getUser().get_email()}}"); $('input[name="destmail"]', $('#sendmail')).val("{{app['authentication'].getUser().get_email()}}");
var tabs = $('.tabs', dialog.getDomElement()); var tabs = $('.tabs', dialog.getDomElement());
if (tabs.data('ui-tabs')) { tabs.tabs("option", "active", 1);
tabs.tabs('active',1);
}
} }
return; return;

View File

@@ -2104,7 +2104,11 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey("label", $permalink); $this->assertArrayHasKey("label", $permalink);
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']);
$this->assertArrayHasKey("updated_on", $permalink); $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->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['updated_on']);
$this->assertDateAtom($permalink['updated_on']); $this->assertDateAtom($permalink['updated_on']);
$this->assertArrayHasKey("page_url", $permalink); $this->assertArrayHasKey("page_url", $permalink);

View File

@@ -4,6 +4,8 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Entities\Basket;
use Entities\BasketElement;
/** /**
* @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail * @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail
@@ -73,6 +75,49 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertBadResponse(self::$DI['client']->getResponse()); $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 * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord
*/ */

View File

@@ -499,13 +499,16 @@ abstract class PhraseanetTestCase extends WebTestCase
* Authenticates self::['user'] against application. * Authenticates self::['user'] against application.
* *
* @param Application $app * @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']->clear();
$app['session']->set('usr_id', self::$DI['user']->get_id()); $app['session']->set('usr_id', $user->get_id());
$session = new Session(); $session = new Session();
$session->setUsrId(self::$DI['user']->get_id()); $session->setUsrId($user->get_id());
$session->setUserAgent(''); $session->setUserAgent('');
self::$DI['app']['EM']->persist($session); self::$DI['app']['EM']->persist($session);
self::$DI['app']['EM']->flush(); self::$DI['app']['EM']->flush();