本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Client::getCookieJar方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getCookieJar方法的具体用法?PHP Client::getCookieJar怎么用?PHP Client::getCookieJar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bundle\FrameworkBundle\Client
的用法示例。
在下文中一共展示了Client::getCookieJar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logout
public function logout()
{
$this->client->setServerParameters(array());
$this->client->getCookieJar()->clear();
$this->user = null;
$this->pageEleveur = null;
}
示例2: signInAsAdmin
/**
*
*/
protected function signInAsAdmin()
{
$session = $this->client->getContainer()->get('session');
$firewall = 'main';
$token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN'));
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例3: logIn
/**
* @param User $user
*/
protected function logIn(User $user)
{
$session = $this->client->getContainer()->get('session');
$firewall = 'main';
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例4: logIn
protected function logIn()
{
$session = $this->client->getContainer()->get('session');
$userManager = $this->client->getContainer()->get('fos_user.user_manager');
$user = $userManager->findUserByUsername('admin');
$firewall = 'main';
$token = new UsernamePasswordToken($user, null, $firewall, array('ROLE_ADMIN'));
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例5: iAmAuthenticatedAs
/**
* @Given I am authenticated as :login
*/
public function iAmAuthenticatedAs($login)
{
/** @var User $user */
$user = $this->getContainer()->get('fos_user.user_manager')->findUserByUsername($login);
$session = $this->client->getContainer()->get('session');
$this->client->getCookieJar()->set(new Cookie($session->getName(), true));
$firewall = 'main';
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$this->getContainer()->get('security.context')->setToken($token);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例6: authenticateUser
/**
* Authenticate selected user.
* If you want to test another firewall, look name for it
* in the security.yml file for "context" value.
*
* @param $userName
* @param $roles
* @param null $firewallName
* @return \FOS\UserBundle\Model\UserInterface
*/
protected function authenticateUser($userName, $roles, $firewallName = null)
{
$session = $this->client->getContainer()->get('session');
if (!$firewallName) {
$firewallName = $this->getFirewallName();
}
$user = $this->container->get('fos_user.user_manager')->findUserByUsername($userName);
$token = new UsernamePasswordToken($user, null, $firewallName, $roles);
$session->set('_security_' . $firewallName, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
return $user;
}
示例7: logIn
/**
* Log user with username
*/
protected function logIn()
{
$container = $this->client->getContainer();
$userManager = $container->get('fos_user.user_manager');
$user = $userManager->findUserByUsername($this->username);
$session = $this->client->getContainer()->get('session');
$firewall = 'openorchestra';
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$container->get('fos_user.security.login_manager')->logInUser($firewall, $user);
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例8: setSettingsCookie
/**
* Create settings cookies and set it in the cookie jar.
*
* @param Client $client
* @param array $cookies
*/
public static function setSettingsCookie(Client $client, array $cookies)
{
foreach ($cookies as $name => $cookieSettings) {
$cookie = new Cookie($name, json_encode($cookieSettings));
$client->getCookieJar()->set($cookie);
}
}
示例9: expireAuthentication
/**
* Expires the authentication if these has been created
*
* @param Url $url Url
*
* @return $this Self object
*/
protected function expireAuthentication(Url $url)
{
$session = $this->session;
$session->remove('_security_' . $url->getOption('firewall'));
$session->save();
$this->client->getCookieJar()->expire($session->getName());
return $this;
}
示例10: logIn
/**
* Do not use this method in dataProvider since they are called before setUp !
*/
protected function logIn($nick)
{
$repo = $this->getService('social.netizen.repository');
$user = $repo->findByNickname($nick);
if (!is_null($user)) {
$session = $this->client->getContainer()->get('session');
$firewall = 'secured_area';
$cred = $user->getCredential();
$token = new Token($firewall, $cred->getProviderKey(), $cred->getUid(), $user->getRoles());
$token->setUser($user);
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
$this->getService('security.context')->setToken($token);
}
}
示例11: logIn
/**
*
* @param string $username
* @param array $role
*/
protected function logIn($username = null, $role = null)
{
$session = $this->client->getContainer()->get('session');
$firewall = 'main';
$user = $this->em->getRepository('OjsUserBundle:User')->findOneByUsername($username ? $username : 'admin');
if (!$user) {
$_role = $this->em->getRepository('OjsUserBundle:Role')->findOneByRole($role[0]);
$user = $this->em->getRepository('OjsUserBundle:User')->findOneByRole($_role);
}
if (!$user instanceof UserInterface) {
throw new \Exception("User not find. " . get_class($user));
}
$token = new UsernamePasswordToken($user, null, $firewall, $role ? $role : array('ROLE_SUPER_ADMIN'));
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
示例12: adminLogIn
protected function adminLogIn(Client $client)
{
$session = $client->getContainer()->get('session');
$firewall = 'secured_area';
$token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN'));
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
}
示例13: setCookieAndAssertFail
/**
* @param mixed $cookieValue
* @param Cookie $oldCookie
*/
private function setCookieAndAssertFail($cookieValue, $oldCookie)
{
// Set cookie.
$newCookie = new \Symfony\Component\BrowserKit\Cookie('ongr_settings_user_auth', json_encode($cookieValue), $oldCookie->getExpiresTime(), $oldCookie->getPath(), $oldCookie->getDomain());
$this->client->getCookieJar()->set($newCookie);
// Visit login page.
$crawler = $this->client->request('GET', '/settings/login');
// Assert there is a form.
$buttonNode = $crawler->selectButton('login_submit');
$this->assertSame(1, $buttonNode->count(), 'There should be a form');
}
示例14: loginIn
/**
* @param Client $client
* @param string $token
*/
public function loginIn(Client $client, $token)
{
$session = $client->getContainer()->get('session');
$user = new User(new UserId('$token'), $token);
$token = new BlockCypherUserToken($user, $token, 'blockcypher', array('ROLE_USER'));
$firewall = 'secured_area';
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
}
示例15: login
/**
* @param Client $client
* @param string $username
* @param string $password
*/
protected function login($client, $username = null, $password = null)
{
$session = $client->getContainer()->get('session');
// the firewall context (defaults to the firewall name)
$firewall = 'secured_area';
$token = new UsernamePasswordToken('root', "root", $firewall, array('ROLE_ADMIN'));
$session->set('_security_' . $firewall, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
}