8

I am currently trying to write functional tests but i'm getting stuck after logging in and redirecting to a new page. Everything works ok until last assert. The redirect works ok,the content page after redirect is ok, but i get an error on last assert: failed asserting that false is true. I found nothing to help me from similar issues here.

Here's the code:

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
    $client = static::createClient(array(),
        array(
            'HTTP_HOST' => 'locahost'

        ));



    $crawler = $client->request('GET', '/login');
    echo $client->getRequest()->getUri();


    $form = $crawler->selectButton('Login')->form(array(
        '_username' => 'user',
        '_password' => 'pass',
    ),'POST');


    $client->submit($form);
    $this->assertTrue($client->getResponse()->isRedirect());
    $client->followRedirect();
    echo $client->getRequest()->getUri();

    print_r( $client->getResponse()->getContent());


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

}

Osmiumbin
  • 93
  • 1
  • 4
  • I managed to partially fix it by adding $crawler = $client->request('GET', '/'); before the last assert, but now the problem is that i cannot find all elements in the new page, just a few of them since the page is not well formatted or so.. – Osmiumbin Nov 17 '15 at 12:47
  • Did you gave a try ? – COil Nov 24 '15 at 10:53

1 Answers1

12

You must get the crawler returned by the followredirect() function:

$crawler = $client->followRedirect();
COil
  • 7,201
  • 2
  • 50
  • 98