mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Add tests to persistent cookie
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\BrowserKit\Cookie as BrowserCookie;
|
||||
use Symfony\Component\BrowserKit\CookieJar;
|
||||
|
||||
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
|
||||
|
||||
class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
@@ -38,4 +43,71 @@ class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_allow_search_engine', $original_value, \registry::TYPE_BOOLEAN);
|
||||
}
|
||||
|
||||
public function testNoPersistentCookie()
|
||||
{
|
||||
$app = self::$DI['app'];
|
||||
$app->closeAccount();
|
||||
|
||||
$boolean = false;
|
||||
|
||||
$app->get('/unit-test-route', function(Application $app) use (&$boolean) {
|
||||
$boolean = $app->isAuthenticated();
|
||||
});
|
||||
|
||||
$client = new Client($app);
|
||||
$client->request('GET', '/unit-test-route');
|
||||
|
||||
$this->assertFalse($boolean);
|
||||
}
|
||||
|
||||
public function testPersistentCookie()
|
||||
{
|
||||
$app = self::$DI['app'];
|
||||
$app->closeAccount();
|
||||
|
||||
$browser = $this->getMockBuilder('\Browser')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$browser->expects($this->any())
|
||||
->method('getBrowser')
|
||||
->will($this->returnValue('Un joli browser'));
|
||||
|
||||
$browser->expects($this->any())
|
||||
->method('getPlatform')
|
||||
->will($this->returnValue('Une belle version'));
|
||||
|
||||
$nonce = \random::generatePassword(16);
|
||||
$string = $browser->getBrowser() . '_' . $browser->getPlatform();
|
||||
|
||||
$token = \User_Adapter::salt_password($app, $string, $nonce);
|
||||
|
||||
$app['browser'] = $browser;
|
||||
|
||||
$session = new \Entities\Session();
|
||||
$session->setUser(self::$DI['user'])
|
||||
->setBrowserName($browser->getBrowser())
|
||||
->setBrowserVersion($browser->getVersion())
|
||||
->setUserAgent('Custom UA')
|
||||
->setNonce($nonce)
|
||||
->setToken($token);
|
||||
|
||||
$app['EM']->persist($session);
|
||||
$app['EM']->flush();
|
||||
|
||||
$boolean = false;
|
||||
|
||||
$app->get('/unit-test-route', function(Application $app) use (&$boolean) {
|
||||
$boolean = $app->isAuthenticated();
|
||||
});
|
||||
|
||||
$cookieJar = new CookieJar();
|
||||
$cookieJar->set(new BrowserCookie('persistent', $token));
|
||||
|
||||
$client = new Client($app, array(), null, $cookieJar);
|
||||
$client->request('GET', '/unit-test-route');
|
||||
|
||||
$this->assertTrue($boolean);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user