Files
Phraseanet/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php
2013-05-29 14:22:51 +02:00

88 lines
2.9 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\Controller\Root;
class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* @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/', array(
'usr' => self::$DI['user_alt1']->get_id()
));
$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()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->XMLHTTPRequest('POST', '/session/update/', array(
'usr' => self::$DI['user']->get_id(),
'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()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->XMLHTTPRequest('POST', '/session/update/', array(
'usr' => self::$DI['user']->get_id()
));
$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);
}
}