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

AppNavigationTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 82
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 20 4
A testFirstBreadcrumbLinksHome() 0 16 2
A testCountBreadcrumbs() 0 9 2
A testLastBreadcrumbMatchesPageTitle() 0 17 2
A getBreadcrumbs() 0 6 1
1
<?php
2
3
namespace Overwatch\UserBundle\Tests\E2E;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures;
7
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures;
8
use Overwatch\UserBundle\DataFixtures\ORM\UserFixtures;
9
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase;
10
11
/**
12
 * MyAccountTest
13
 *
14
 * @author Zac Sturgess <[email protected]>
15
 */
16
class AppNavigationTest extends WebDriverTestCase
17
{
18
    private $pages = [
19
        '#/',
20
        '#/users',
21
        '#/alerts',
22
        '#/my-account'
23
    ];
24
    
25
    public function setUp()
26
    {
27
        parent::setUp();
28
        
29
        $groupId = TestGroupFixtures::$groups['group-1']->getId();
30
        if (!in_array("#/group/$groupId", $this->pages)) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $groupId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
31
            $this->pages[] = "#/group/$groupId";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $groupId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
32
        }
33
        if (!in_array("#/group/$groupId/add-test", $this->pages)) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $groupId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
34
            $this->pages[] = "#/group/$groupId/add-test";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $groupId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
35
        }
36
        
37
        $testId = TestFixtures::$tests['test-1']->getId();
38
        if (!in_array("#/test/$testId", $this->pages)) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $testId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
39
            $this->pages[] = "#/test/$testId";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $testId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
40
        }
41
        
42
        $this->logInAsUser('user-1');
43
        $this->waitForLoadingAnimation();
44
    }
45
    
46
    public function testFirstBreadcrumbLinksHome()
47
    {
48
        foreach ($this->pages as $page) {
49
            $this->webDriver->get('http://127.0.0.1:8000/' . $page);
50
            $this->waitForLoadingAnimation();
51
            
52
            $this->assertEquals('Overwatch', $this->getBreadcrumbs()[0]->getText(), "The breadcrumb text on $page does not equal 'Overwatch'");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
53
            $this->assertEquals(
54
                'http://127.0.0.1:8000/#/',
55
                $this->getBreadcrumbs()[0]->findElement(
56
                    WebDriverBy::cssSelector('a')
57
                )->getAttribute('href'),
58
                "The breadcrumb link on $page does not equal '#/'"
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
59
            );
60
        }
61
    }
62
    
63
    public function testCountBreadcrumbs()
64
    {
65
        foreach ($this->pages as $page) {
66
            $this->webDriver->get('http://127.0.0.1:8000/' . $page);
67
            $this->waitForLoadingAnimation();
68
            
69
            $this->assertEquals(2, count($this->getBreadcrumbs()), "Breadcrumb count on $page does not equal 2");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
70
        }
71
    }
72
    
73
    public function testLastBreadcrumbMatchesPageTitle()
74
    {
75
        foreach ($this->pages as $page) {
76
            $this->webDriver->get('http://127.0.0.1:8000/' . $page);
77
            $this->waitForLoadingAnimation();
78
            
79
            $breadcrumbs = $this->getBreadcrumbs();
80
            
81
            $this->assertContains(
82
                $this->webDriver->findElement(
83
                    WebDriverBy::cssSelector('#page h1')
84
                )->getText(),
85
                end($breadcrumbs)->getText(),
86
                "Final breadcrumb text on $page does not match the page's title"
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
87
            );
88
        }
89
    }
90
    
91
    private function getBreadcrumbs()
92
    {
93
        return $this->webDriver->findElements(
94
            WebDriverBy::cssSelector('ul.breadcrumbs li:not(.ng-hide)')
95
        );
96
    }
97
}
98