After successfully using the crawler to log in I can’t seem to stay authenticated. Once i’m authenticated I want to be able to run through each of my services and check the receive the correct response.
public function testGetClientsAction()
{
$client = static::createClient();
$client->followRedirects();
$cookie = new Cookie('locale2', 'en', time() + 3600 * 24 * 7, '/', null, false, false);
$client->getCookieJar()->set($cookie);
// Visit user login page and login
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('login')->form();
$crawler = $client->submit($form, array('_username' => 'greg', '_password' => 'greg'));
$client->insulate();
$client->request(
'GET',
'/clients/12345',
array(),
array(),
array('X-Requested-With' => "XMLHttpRequest")
);
print_r($client->getResponse()->getContent());
die();
}
The print_r returns the page redirected to after login.
I solved this by removing
$client->followRedirects();