1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overwatch\UserBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Overwatch\UserBundle\Tests\Base\FunctionalTestCase; |
6
|
|
|
use Symfony\Component\BrowserKit\Cookie; |
7
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* AppControllerTest |
11
|
|
|
* Functional test for the index route provided by AppController |
12
|
|
|
*/ |
13
|
|
|
class AppControllerTest extends FunctionalTestCase |
14
|
|
|
{ |
15
|
|
View Code Duplication |
public function testIndexPage() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->logIn('ROLE_USER'); |
18
|
|
|
$this->client->request('GET', '/'); |
19
|
|
|
|
20
|
|
|
$this->assertTrue($this->client->getResponse()->isSuccessful()); |
21
|
|
|
$this->assertContains('<div data-ng-view>', $this->getResponseContent(true)); |
22
|
|
|
$this->assertNotContains('Manage Users', $this->getResponseContent(true)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
public function testIndexPageAsSuperAdmin() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->logIn('ROLE_SUPER_ADMIN'); |
28
|
|
|
$this->client->request('GET', '/'); |
29
|
|
|
|
30
|
|
|
$this->assertTrue($this->client->getResponse()->isSuccessful()); |
31
|
|
|
$this->assertContains('<div data-ng-view>', $this->getResponseContent(true)); |
32
|
|
|
$this->assertContains('Manage Users', $this->getResponseContent(true)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testApiDocPage() |
36
|
|
|
{ |
37
|
|
|
$this->logIn('ROLE_SUPER_ADMIN'); |
38
|
|
|
$this->client->request('GET', '/api/doc'); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($this->client->getResponse()->isSuccessful()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function logIn($role) |
44
|
|
|
{ |
45
|
|
|
$session = $this->client->getContainer()->get('session'); |
46
|
|
|
$firewall = 'overwatch'; |
47
|
|
|
|
48
|
|
|
$token = new UsernamePasswordToken('testUser', null, $firewall, [$role]); |
49
|
|
|
$session->set('_security_' . $firewall, serialize($token)); |
50
|
|
|
$session->save(); |
51
|
|
|
$cookie = new Cookie($session->getName(), $session->getId()); |
52
|
|
|
$this->client->getCookieJar()->set($cookie); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.