2

How to properly make assertion after redirection?

$crawler = $client->submit($form);
$client->followRedirect();
//$response = $client->getResponse()->getContent();
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);

Debugger show that $response have content that I expect, with a foo word, but assertion failed.

Matteo
  • 37,680
  • 11
  • 100
  • 115
user6827096
  • 1,186
  • 1
  • 11
  • 26

1 Answers1

3

Assign the redirect to the crawler. Try with this code:

    $crawler = $client->submit($form);
    $this->assertTrue($client->getResponse()->isRedirect(),'Submit ok');
    // Assign the redirect to the crawler 
    $crawler = $client->followRedirect();

    $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Correct redirect to page ok");

    $this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);

Hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115