LocalizedRoutesAsPathTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
  11. class LocalizedRoutesAsPathTest extends WebTestCase
  12. {
  13. /**
  14. * @dataProvider getLocales
  15. */
  16. public function testLoginLogoutProcedure($locale)
  17. {
  18. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
  19. $crawler = $client->request('GET', '/'.$locale.'/login');
  20. $form = $crawler->selectButton('login')->form();
  21. $form['_username'] = 'johannes';
  22. $form['_password'] = 'test';
  23. $client->submit($form);
  24. $this->assertRedirect($client->getResponse(), '/'.$locale.'/profile');
  25. $this->assertEquals('Profile', $client->followRedirect()->text());
  26. $client->request('GET', '/'.$locale.'/logout');
  27. $this->assertRedirect($client->getResponse(), '/'.$locale.'/');
  28. $this->assertEquals('Homepage', $client->followRedirect()->text());
  29. }
  30. /**
  31. * @dataProvider getLocales
  32. */
  33. public function testLoginFailureWithLocalizedFailurePath($locale)
  34. {
  35. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_form_failure_handler.yml'));
  36. $crawler = $client->request('GET', '/'.$locale.'/login');
  37. $form = $crawler->selectButton('login')->form();
  38. $form['_username'] = 'johannes';
  39. $form['_password'] = 'foobar';
  40. $client->submit($form);
  41. $this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
  42. }
  43. /**
  44. * @dataProvider getLocales
  45. */
  46. public function testAccessRestrictedResource($locale)
  47. {
  48. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
  49. $client->request('GET', '/'.$locale.'/secure/');
  50. $this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
  51. }
  52. /**
  53. * @dataProvider getLocales
  54. */
  55. public function testAccessRestrictedResourceWithForward($locale)
  56. {
  57. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml'));
  58. $crawler = $client->request('GET', '/'.$locale.'/secure/');
  59. $this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
  60. }
  61. public function getLocales()
  62. {
  63. return array(array('en'), array('de'));
  64. }
  65. }