BaseTestCase.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace JMS\SecurityExtraBundle\Tests\Functional;
  3. use Symfony\Component\Filesystem\Filesystem;
  4. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  5. class BaseTestCase extends WebTestCase
  6. {
  7. protected static function createKernel(array $options = array())
  8. {
  9. return new AppKernel(
  10. isset($options['config']) ? $options['config'] : 'default.yml'
  11. );
  12. }
  13. protected function setUp()
  14. {
  15. parent::setUp();
  16. $fs = new Filesystem();
  17. $fs->remove(sys_get_temp_dir().'/JMSSecurityExtraBundle');
  18. }
  19. protected function tearDown()
  20. {
  21. parent::tearDown();
  22. $fs = new Filesystem();
  23. $fs->remove(sys_get_temp_dir().'/JMSSecurityExtraBundle');
  24. }
  25. protected function login($client, $username = null, $password = null)
  26. {
  27. if (empty($username) || empty($password)) {
  28. $username = 'johannes';
  29. $password = 'test';
  30. }
  31. $crawler = $client->request('get', '/login')->selectButton('login');
  32. $form = $crawler->form();
  33. $form['_username'] = $username;
  34. $form['_password'] = $password;
  35. $client->submit($form);
  36. $security = $client->getProfile()->getCollector('security');
  37. $this->assertTrue(is_string($security->getUser()) && strlen($security->getUser()) > 0);
  38. $this->assertTrue($security->isAuthenticated(), 'Logged in user is not authenticated.');
  39. }
  40. final protected function importDatabaseSchema()
  41. {
  42. $em = self::$kernel->getContainer()->get('em');
  43. $metadata = $em->getMetadataFactory()->getAllMetadata();
  44. if (!empty($metadata)) {
  45. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
  46. $schemaTool->createSchema($metadata);
  47. }
  48. }
  49. }