mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00

Conflicts: lib/Alchemy/Phrasea/Controller/Prod/Push.php lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php lib/conf.d/migrations.yml Conflicts: lib/Alchemy/Phrasea/ACL/BasketACL.php lib/Alchemy/Phrasea/Authentication/Authenticator.php lib/Alchemy/Phrasea/Controller/Prod/Order.php lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php lib/Alchemy/Phrasea/Controller/Root/Session.php lib/Alchemy/Phrasea/Model/Entities/Basket.php lib/Alchemy/Phrasea/Model/Entities/BasketElement.php lib/Alchemy/Phrasea/Model/Entities/Feed.php lib/Alchemy/Phrasea/Model/Entities/FeedEntry.php lib/Alchemy/Phrasea/Model/Entities/FtpExport.php lib/Alchemy/Phrasea/Model/Entities/Session.php lib/Alchemy/Phrasea/Model/Entities/StoryWZ.php lib/Alchemy/Phrasea/Model/Entities/UsrList.php lib/Alchemy/Phrasea/Model/Entities/UsrListEntry.php lib/Alchemy/Phrasea/Model/Entities/UsrListOwner.php lib/Alchemy/Phrasea/Model/Entities/ValidationParticipant.php lib/Alchemy/Phrasea/Model/Entities/ValidationSession.php lib/Alchemy/Phrasea/Model/Repositories/StoryWZRepository.php lib/classes/API/V1/adapter.php templates/mobile/lightbox/sc_note.html.twig templates/web/admin/connected-users.html.twig templates/web/admin/publications/fiche.html.twig templates/web/lightbox/IE6/agreement_box.html.twig templates/web/lightbox/agreement_box.html.twig templates/web/lightbox/basket_content_report.html.twig templates/web/lightbox/sc_note.html.twig templates/web/prod/WorkZone/Browser/Basket.html.twig templates/web/prod/WorkZone/Browser/Results.html.twig templates/web/prod/WorkZone/Macros.html.twig templates/web/prod/actions/Feedback/List-Share.html.twig templates/web/prod/actions/Feedback/ListsMacros.html.twig templates/web/prod/orders/order_box.html.twig templates/web/prod/orders/order_item.html.twig templates/web/prod/upload/lazaret.html.twig tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php
151 lines
5.1 KiB
PHP
151 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Controller\Root;
|
|
|
|
use Symfony\Component\HttpKernel\Client;
|
|
|
|
class SessionTest extends \PhraseanetAuthenticatedWebTestCase
|
|
{
|
|
/**
|
|
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
|
|
*/
|
|
public function testUpdSessionLogout()
|
|
{
|
|
$this->logout(self::$DI['app']);
|
|
$this->XMLHTTPRequest('POST', '/session/update/');
|
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
|
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
|
$this->checkSessionReturn($datas);
|
|
$this->assertEquals('disconnected', $datas->status);
|
|
}
|
|
|
|
/**
|
|
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
|
|
*/
|
|
public function testUpdSessionChangeUser()
|
|
{
|
|
$this->XMLHTTPRequest('POST', '/session/update/', [
|
|
'usr' => self::$DI['user_alt1']->getId()
|
|
]);
|
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
|
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
|
$this->checkSessionReturn($datas);
|
|
$this->assertEquals('disconnected', $datas->status);
|
|
}
|
|
|
|
/**
|
|
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
|
|
*/
|
|
public function testUpdSession()
|
|
{
|
|
$this->authenticate(self::$DI['app']);
|
|
|
|
$this->XMLHTTPRequest('POST', '/session/update/', [
|
|
'usr' => self::$DI['user']->getId(),
|
|
'module' => 1
|
|
]);
|
|
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
|
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
|
$this->checkSessionReturn($datas);
|
|
$this->assertEquals('ok', $datas->status);
|
|
}
|
|
|
|
/**
|
|
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
|
|
*/
|
|
public function testUpdSessionBadRequestMissingModuleArgument()
|
|
{
|
|
$this->authenticate(self::$DI['app']);
|
|
|
|
$this->XMLHTTPRequest('POST', '/session/update/', [
|
|
'usr' => self::$DI['user']->getId()
|
|
]);
|
|
|
|
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
|
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
|
$this->checkSessionReturn($datas);
|
|
$this->assertEquals('unknown', $datas->status);
|
|
}
|
|
|
|
/**
|
|
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
|
|
*/
|
|
public function testUpdSessionBadRequest()
|
|
{
|
|
self::$DI['client']->request('POST', '/session/update/');
|
|
|
|
$this->assertBadResponse(self::$DI['client']->getResponse());
|
|
}
|
|
|
|
private function checkSessionReturn(\stdClass $data)
|
|
{
|
|
$this->assertObjectHasAttribute('status', $data);
|
|
$this->assertObjectHasAttribute('message', $data);
|
|
$this->assertObjectHasAttribute('notifications', $data);
|
|
$this->assertObjectHasAttribute('changed', $data);
|
|
}
|
|
|
|
public function testDeleteSession()
|
|
{
|
|
$originalEm = self::$DI['app']['EM'];
|
|
|
|
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
|
|
|
|
$session->expects($this->once())
|
|
->method('getUser')
|
|
->will($this->returnValue(self::$DI['app']['authentication']->getUser()));
|
|
|
|
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$em->expects($this->once())
|
|
->method('find')
|
|
->will($this->returnValue($session));
|
|
$em->expects($this->once())
|
|
->method('remove')
|
|
->will($this->returnValue(null));
|
|
$em->expects($this->once())
|
|
->method('flush')
|
|
->will($this->returnValue(null));
|
|
|
|
self::$DI['app']['EM'] = $em;
|
|
self::$DI['client'] = new Client(self::$DI['app'], []);
|
|
$this->XMLHTTPRequest('POST', '/session/delete/1');
|
|
$this->assertTrue(self::$DI['client']->getResponse()->isOK());
|
|
self::$DI['app']['EM'] = $originalEm;
|
|
self::$DI['client'] = new Client(self::$DI['app'], []);
|
|
|
|
$em = null;
|
|
}
|
|
|
|
public function testDeleteSessionUnauthorized()
|
|
{
|
|
$originalEm = self::$DI['app']['EM'];
|
|
|
|
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
|
|
|
|
$session->expects($this->once())
|
|
->method('getUsrId')
|
|
->will($this->returnValue(self::$DI['app']['authentication']->getUser()->getId() + 1));
|
|
|
|
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$em->expects($this->once())
|
|
->method('find')
|
|
->will($this->returnValue($session));
|
|
|
|
self::$DI['app']['EM'] = $em;
|
|
self::$DI['client'] = new Client(self::$DI['app'], []);
|
|
self::$DI['client']->request('POST', '/session/delete/1');
|
|
$this->assertFalse(self::$DI['client']->getResponse()->isOK());
|
|
$this->assertEquals(self::$DI['client']->getResponse()->getStatusCode(), 403);
|
|
self::$DI['app']['EM'] = $originalEm;
|
|
self::$DI['client'] = new Client(self::$DI['app'], []);
|
|
|
|
$em = null;
|
|
}
|
|
}
|