request('GET', '/login'); self::assertResponseIsSuccessful(); $buttonCrawlerNode = $crawler->selectButton('login'); $form = $buttonCrawlerNode->form(); $client->submit($form, [ '_username' => 'center a_social', '_password' => 'password', ]); // the response is a redirection $this->assertTrue($client->getResponse()->isRedirect()); // the response is not a login page, but on a new page $this->assertDoesNotMatchRegularExpression('/\/login$/', $client->getResponse() ->headers ->get('location')); // on the home page, there must be a logout link $client->followRedirects(true); $crawler = $client->request('GET', '/'); $this->assertMatchesRegularExpression('/center a_social/', $client->getResponse() ->getContent()); $logoutLinkFilter = $crawler->filter('a:contains("Se déconnecter")'); // check there is > 0 logout link $this->assertGreaterThan(0, $logoutLinkFilter->count(), 'check that a logout link is present'); // click on logout link $client->followRedirects(false); $client->click($crawler->selectLink('Se déconnecter')->link()); self::assertResponseRedirects('http://localhost/'); } }