1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overwatch\UserBundle\Tests\E2E; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverBy; |
6
|
|
|
use Overwatch\UserBundle\DataFixtures\ORM\UserFixtures; |
7
|
|
|
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* MyAccountTest |
11
|
|
|
* |
12
|
|
|
* @author Zac Sturgess <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class MyAccountTest extends WebDriverTestCase |
15
|
|
|
{ |
16
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
$this->logInAsUser('user-1'); |
21
|
|
|
$this->waitForLoadingAnimation(); |
22
|
|
|
|
23
|
|
|
$this->webDriver->findElement( |
24
|
|
|
WebDriverBy::cssSelector('.header-nav .nav-profile') |
25
|
|
|
)->click(); |
26
|
|
|
|
27
|
|
|
$this->webDriver->findElement( |
28
|
|
|
WebDriverBy::cssSelector('.header-nav .nav-profile .sub-menu li.first a') |
29
|
|
|
)->click(); |
30
|
|
|
$this->waitForLoadingAnimation(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testProfileDetails() |
34
|
|
|
{ |
35
|
|
|
$newDetails = [ |
36
|
|
|
'telephoneNumber' => '+4401628813588' |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
$profileItems = $this->webDriver->findElements( |
40
|
|
|
WebDriverBy::cssSelector('.profile-details input') |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertEquals( |
44
|
|
|
UserFixtures::$users['user-1']->getTelephoneNumber(), |
45
|
|
|
$profileItems[0]->getAttribute('value') |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$profileItems[0]->clear(); |
49
|
|
|
$profileItems[0]->sendKeys($newDetails['telephoneNumber']); |
50
|
|
|
|
51
|
|
|
$profileItems[count($profileItems) - 1]->click(); |
52
|
|
|
$this->waitForLoadingAnimation(); |
53
|
|
|
|
54
|
|
|
$this->assertEquals($newDetails['telephoneNumber'], $profileItems[0]->getAttribute('value')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testApiKeyHidden() |
58
|
|
|
{ |
59
|
|
|
$this->assertEquals( |
60
|
|
|
'password', |
61
|
|
|
$this->getApiKeyField()->getAttribute('type') |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testApiKeyVisibilityCanBeToggled() |
66
|
|
|
{ |
67
|
|
|
$this->webDriver->findElement( |
68
|
|
|
WebDriverBy::cssSelector(".password-toggle .toggle-btn") |
|
|
|
|
69
|
|
|
)->click(); |
70
|
|
|
$this->assertEquals( |
71
|
|
|
'text', |
72
|
|
|
$this->getApiKeyField()->getAttribute('type') |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$this->webDriver->findElement( |
76
|
|
|
WebDriverBy::cssSelector(".password-toggle .toggle-btn") |
|
|
|
|
77
|
|
|
)->click(); |
78
|
|
|
$this->assertEquals( |
79
|
|
|
'password', |
80
|
|
|
$this->getApiKeyField()->getAttribute('type') |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testApiKeyCanBeReset() |
85
|
|
|
{ |
86
|
|
|
$value = $this->getApiKeyField()->getAttribute('value'); |
87
|
|
|
|
88
|
|
|
$this->webDriver->findElement( |
89
|
|
|
WebDriverBy::cssSelector(".reset-api .btn-warning") |
|
|
|
|
90
|
|
|
)->click(); |
91
|
|
|
$this->waitForLoadingAnimation(); |
92
|
|
|
|
93
|
|
|
$this->assertNotEquals( |
94
|
|
|
$this->getApiKeyField()->getAttribute('value'), |
95
|
|
|
$value |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function getApiKeyField() |
100
|
|
|
{ |
101
|
|
|
return $this->webDriver->findElement( |
102
|
|
|
WebDriverBy::id('api-key') |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.