I am trying to test my ajax scripts using codeception & PhpBrowser(which uses Mink with Goutte driver).
My ajax scripts require an authenticated session in order to execute, and the session is created via my log in page.
I am having issues with getting the PhpBrowser/Link sessions, to persist after login.
I created a PhpBrowser Helper function to overwrite _initialize so I could get https working with a self signed cert on my test server like this:
public function _initialize()
{
$client = new \Behat\Mink\Driver\Goutte\Client();
$driver = new \Behat\Mink\Driver\GoutteDriver($client);
$curl_config = array_merge($this->curl_defaults, $this->config['curl']);
array_walk($curl_config, function($a, &$b) { $b = "curl.$b"; });
$curl_config['ssl.certificate_authority']=false;
$client->setClient(new \Guzzle\Http\Client('', $curl_config));
$client->followRedirects(true);
$this->session = new \Behat\Mink\Session($driver);
\Codeception\Util\Mink::_initialize();
}
Now when I run my acceptance test it seems like the Login works correctly, and the redirect happens based on the apache access_logs, but the PHPSESSID cookie does not persist, so all of my access request after login are unauthorized.
I tried testing this in acceptance test by comparing the
$I->getCurrentUrl()
$I->getResponseHeaders()
before and after the redirect.
The currentUrl() return value never gets to the redirect destination, although apache access_logs say otherwise.
getResponseHeaders() returns a PHP_SESSID cookie after the form submission, but it does not exist for all requests after.
Any ideas/guesses why the session created during login is not persisting after the redirect?
Do I need to do any special configuration to Mink sessions to get them to follow the redirect, or am I doing something else wrong?
Thanks in advance for your help!
-Ed
I finally figured out the issue.
I had to explicitly set the cookie to be saved for the /Guzzle/Http/Client object in my overwritten _initialize function.
public function _initialize()
{
$client = new \Behat\Mink\Driver\Goutte\Client();
$driver = new \Behat\Mink\Driver\GoutteDriver($client);
$cookiePlugin = new \Guzzle\Plugin\Cookie\CookiePlugin(new \Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar());
$curl_config = array_merge($this->curl_defaults, $this->config['curl']);
array_walk($curl_config, function($a, &$b) { $b = "curl.$b"; });
$curl_config['ssl.certificate_authority']=false;
$guzzle_client = new \Guzzle\Http\Client('', $curl_config);
$guzzle_client->addSubscriber($cookiePlugin);
$client->setClient($guzzle_client);
$client->followRedirects(true);
$this->session = new \Behat\Mink\Session($driver);
\Codeception\Util\Mink::_initialize();
}