Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

AppControllerTest::testIndexPageAsSuperAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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('<i class="icon-users"></i> Manage Users', $this->getResponseContent(true));
23
    }
24
    
25 View Code Duplication
    public function testIndexPageAsSuperAdmin()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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('<i class="icon-users"></i> 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