3 namespace Acme\DemoBundle\Tests\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
7 class DemoControllerTest
extends WebTestCase
9 public function testIndex()
11 $client = static::createClient();
13 $crawler = $client->request('GET', '/demo/hello/Fabien');
15 $this->assertGreaterThan(0, $crawler->filter('html:contains("Hello Fabien")')->count());
18 public function testSecureSection()
20 $client = static::createClient();
22 // goes to the secure page
23 $crawler = $client->request('GET', '/demo/secured/hello/World');
25 // redirects to the login page
26 $crawler = $client->followRedirect();
28 // submits the login form
29 $form = $crawler->selectButton('Login')->form(array('_username' => 'admin', '_password' => 'adminpass'));
30 $client->submit($form);
32 // redirect to the original page (but now authenticated)
33 $crawler = $client->followRedirect();
35 // check that the page is the right one
36 $this->assertCount(1, $crawler->filter('h1.title:contains("Hello World!")'));
38 // click on the secure link
39 $link = $crawler->selectLink('Hello resource secured')->link();
40 $crawler = $client->click($link);
42 // check that the page is the right one
43 $this->assertCount(1, $crawler->filter('h1.title:contains("secured for Admins only!")'));