diff --git a/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php b/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php index 6472ac7a05..d217689754 100644 --- a/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php +++ b/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php @@ -14,4 +14,32 @@ public function testIndex() $this->assertGreaterThan(0, $crawler->filter('html:contains("Hello Fabien")')->count()); } + + public function testSecureSection() + { + $client = static::createClient(); + + // goes to the secure page + $crawler = $client->request('GET', '/demo/secured/hello/World'); + + // redirects to the login page + $crawler = $client->followRedirect(); + + // submits the login form + $form = $crawler->selectButton('Login')->form(array('_username' => 'admin', '_password' => 'adminpass')); + $client->submit($form); + + // redirect to the original page (but now authenticated) + $crawler = $client->followRedirect(); + + // check that the page is the right one + $this->assertCount(1, $crawler->filter('h1.title:contains("Hello World!")')); + + // click on the secure link + $link = $crawler->selectLink('Hello resource secured')->link(); + $crawler = $client->click($link); + + // check that the page is the right one + $this->assertCount(1, $crawler->filter('h1.title:contains("secured for Admins only!")')); + } }