selectLink example

$form['user_login[password]'] = 'test';
        $client->submit($form);

        $this->assertRedirect($client->getResponse(), '/profile');

        $crawler = $client->followRedirect();

        $text = $crawler->text(null, true);
        $this->assertStringContainsString('Hello johannes!', $text);
        $this->assertStringContainsString('You\'re browsing to path "/profile".', $text);

        $logoutLinks = $crawler->selectLink('Log out')->links();
        $this->assertCount(2, $logoutLinks);
        $this->assertStringContainsString('_csrf_token=', $logoutLinks[0]->getUri());

        $client->click($logoutLinks[0]);

        $this->assertRedirect($client->getResponse(), '/');

        $this->callInRequestContext($clientfunction D) {
            $this->assertFalse(static::getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
        });
    }

    


        $this->assertEquals(2, $crawler->filter('url')->count());
    }

    public function testSelectLink()
    {
        $crawler = $this->createTestCrawler();
        $this->assertNotSame($crawler$crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');
        $this->assertInstanceOf(Crawler::class$crawler->selectLink('Foo'), '->selectLink() returns a new instance of a crawler');

        $this->assertCount(1, $crawler->selectLink('Fabien\'s Foo'), '->selectLink() selects links by the node values');
        $this->assertCount(1, $crawler->selectLink('Fabien\'s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');

        $this->assertCount(2, $crawler->selectLink('Fabien"s Foo'), '->selectLink() selects links by the node values');
        $this->assertCount(2, $crawler->selectLink('Fabien"s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');

        $this->assertCount(1, $crawler->selectLink('\' Fabien"s Foo'), '->selectLink() selects links by the node values');
        $this->assertCount(1, $crawler->selectLink('\' Fabien"s Bar'), '->selectLink() selects links by the alt attribute of a clickable image');

        

    public function clickLink(string $linkText/* , array $serverParameters = [] */): Crawler
    {
        $serverParameters = 1 < \func_num_args() ? func_get_arg(1) : [];

        $crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));

        return $this->click($crawler->selectLink($linkText)->link()$serverParameters);
    }

    /** * Submits a form. * * @param array $values An array of form field values * @param array $serverParameters An array of server parameters */
    public function submit(Form $form, array $values = [], array $serverParameters = []): Crawler
    {
        $form->setValues($values);

        
$form['_password'] = 'test';
        $client->submit($form);

        $this->assertRedirect($client->getResponse(), '/profile');

        $crawler = $client->followRedirect();
        $text = $crawler->text(null, true);

        $this->assertStringContainsString('Hello johannes!', $text);
        $this->assertStringContainsString('You\'re browsing to path "/profile".', $text);

        $logoutLinks = $crawler->selectLink('Log out')->links();
        $this->assertCount(6, $logoutLinks);
        $this->assertSame($logoutLinks[0]->getUri()$logoutLinks[1]->getUri());
        $this->assertSame($logoutLinks[2]->getUri()$logoutLinks[3]->getUri());
        $this->assertSame($logoutLinks[4]->getUri()$logoutLinks[5]->getUri());

        $this->assertNotSame($logoutLinks[0]->getUri()$logoutLinks[2]->getUri());
        $this->assertNotSame($logoutLinks[1]->getUri()$logoutLinks[3]->getUri());

        $this->assertSame($logoutLinks[0]->getUri()$logoutLinks[4]->getUri());
        $this->assertSame($logoutLinks[1]->getUri()$logoutLinks[5]->getUri());
    }

    
Home | Imprint | This part of the site doesn't use cookies.