public function testEncodedValues()
 {
     $cookieJar = new CookieJar();
     $cookieJar->set($cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true));
     $this->assertEquals(array('foo' => 'bar=baz'), $cookieJar->allValues('/'));
     $this->assertEquals(array('foo' => 'bar%3Dbaz'), $cookieJar->allRawValues('/'));
 }
Beispiel #2
0
 /**
  * @dataProvider provideGetValuesValues
  */
 public function testGetValues($uri, $values)
 {
     $cookieJar = new CookieJar();
     $cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
     $cookieJar->set($cookie2 = new Cookie('foo_expired', 'foo', time() - 86400));
     $cookieJar->set($cookie3 = new Cookie('foo_path', 'foo', null, '/foo'));
     $cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', 'example.com'));
     $cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));
     $this->assertEquals($values, array_keys($cookieJar->getValues($uri)), '->getValues() returns the cookie for a given URI');
 }
 private function getClientWithCookie(SilexApp $app, $locale = 'fr')
 {
     $cookieJar = new CookieJar();
     if ($locale) {
         $cookieJar->set(new BrowserCookie('locale', $locale));
     }
     return new Client($app, [], null, $cookieJar);
 }
Beispiel #4
0
 public function testCookieWithWildcardDomain()
 {
     $cookieJar = new CookieJar();
     $cookieJar->set(new Cookie('foo', 'bar', null, '/', '.example.com'));
     $this->assertEquals(array('foo' => 'bar'), $cookieJar->allValues('http://www.example.com'));
     $this->assertEmpty($cookieJar->allValues('http://wwwexample.com'));
 }
Beispiel #5
0
 public function testCookieWithSameNameButDifferentDomains()
 {
     $cookieJar = new CookieJar();
     $cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/', 'foo.example.com'));
     $cookieJar->set($cookie2 = new Cookie('foo', 'bar2', null, '/', 'bar.example.com'));
     $this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
     $this->assertEquals(array('foo' => 'bar1'), $cookieJar->allValues('http://foo.example.com/'));
     $this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://bar.example.com/'));
 }
 private function getClientWithCookie(Application $app, $locale = null)
 {
     $cookieJar = new CookieJar();
     if (null !== $locale) {
         $cookieJar->set(new BrowserCookie('locale', $locale));
     }
     return new Client($app, [], null, $cookieJar);
 }
Beispiel #7
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);
 }
Beispiel #8
0
 /**
  * @return WordPress
  */
 private function make_instance()
 {
     return new WordPress($this->server, $this->history->reveal(), $this->cookieJar->reveal(), $this->uriToIndexMapper->reveal());
 }
 private function getClientWithCookie(Application $app)
 {
     $cookieJar = new CookieJar();
     $cookieJar->set(new BrowserCookie('test-cookie', 'cookievalue'));
     return new Client($app, [], null, $cookieJar);
 }