Completed
Push — master ( 24a3d5...2d942e )
by Zac
14:11
created

ChangeAlertSettingTest::assertElementNotHasClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Overwatch\UserBundle\Tests\E2E;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverElement;
7
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase;
8
9
/**
10
 * ChangeAlertSettingTest
11
 * Tests Change Alert Settings Screen
12
 */
13
class ChangeAlertSettingTest extends WebDriverTestCase
14
{
15 View Code Duplication
    public function setUp()
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
        parent::setUp();
18
        
19
        $this->logInAsUser('user-1');
20
        $this->waitForLoadingAnimation();
21
        
22
        $this->webDriver->findElement(
23
            WebDriverBy::cssSelector('.sidebar li:nth-child(3) a')
24
        )->click();
25
        $this->waitForLoadingAnimation();
26
    }
27
    
28
    public function testChangeSetting()
29
    {
30
        $this->assertElementHasClass($this->getSettingRow(5), 'current-setting');
31
        
32
        $this->getSettingRow(1)->click();
33
        $this->waitForLoadingAnimation();
34
        $this->assertElementNotHasClass($this->getSettingRow(5), 'current-setting');
35
        $this->assertElementHasClass($this->getSettingRow(1), 'current-setting');
36
    }
37
    
38
    private function getSettingRow($number)
39
    {
40
        return $this->webDriver->findElement(
41
            WebDriverBy::cssSelector(".settings li:nth-child($number)")
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $number 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...
42
        );
43
    }
44
    
45
    private function assertElementHasClass(WebDriverElement $element, $class, $has = true) {
46
        $classes = $element->getAttribute('class');
47
        
48
        $this->assertNotNull($classes);
49
        $this->assertEquals(
50
            $has,
51
            in_array(
52
                strtolower($class),
53
                array_map(
54
                    'trim',
55
                    explode(" ", strtolower($classes))
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
56
                )
57
            )
58
        );
59
    }
60
    
61
    private function assertElementNotHasClass(WebDriverElement $element, $class) {
62
        $this->assertElementHasClass($element, $class, false);
63
    }
64
}
65