Пример #1
0
 public function testDeleteSetMailToNullAndRemovesSessions()
 {
     if (null === ($user = self::$DI['app']['repo.users']->findByLogin('test_phpunit_sessions'))) {
         $user = self::$DI['app']['manipulator.user']->createUser('test_phpunit_sessions', self::$DI['app']['random.low']->generateString(8));
     }
     $session = new \Alchemy\Phrasea\Model\Entities\Session();
     $session->setUser($user)->setUserAgent('');
     self::$DI['app']['orm.em']->persist($session);
     self::$DI['app']['orm.em']->flush();
     self::$DI['app']['manipulator.user']->delete($user);
     $repo = self::$DI['app']['orm.em']->getRepository('Phraseanet:Session');
     $this->assertCount(0, $repo->findByUser($user));
 }
Пример #2
0
 public function testPersistentCookie()
 {
     $app = self::$DI['app'];
     $this->logout(self::$DI['app']);
     $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 = self::$DI['app']['random.low']->generateString(16);
     $string = $browser->getBrowser() . '_' . $browser->getPlatform();
     $token = self::$DI['app']['auth.password-encoder']->encodePassword($string, $nonce);
     $app['browser'] = $browser;
     $session = new \Alchemy\Phrasea\Model\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['authentication']->isAuthenticated();
         return new Response();
     });
     $cookieJar = new CookieJar();
     $cookieJar->set(new BrowserCookie('persistent', $token));
     $client = new Client($app, [], null, $cookieJar);
     $client->request('GET', '/unit-test-route');
     $this->assertTrue($boolean);
 }