1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Context\Ui\Admin; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\Page\Admin\Customer\ShowPageInterface; |
16
|
|
|
use Sylius\Behat\Page\Admin\DashboardPageInterface; |
17
|
|
|
use Sylius\Behat\Page\Shop\HomePageInterface; |
18
|
|
|
use Sylius\Component\Customer\Model\CustomerInterface; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Jan Góralski <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class ImpersonatingCustomersContext implements Context |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ShowPageInterface |
28
|
|
|
*/ |
29
|
|
|
private $customerShowPage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DashboardPageInterface |
33
|
|
|
*/ |
34
|
|
|
private $dashboardPage; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var HomePageInterface |
38
|
|
|
*/ |
39
|
|
|
private $homePage; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ShowPageInterface $customerShowPage |
43
|
|
|
* @param DashboardPageInterface $dashboardPage |
44
|
|
|
* @param HomePageInterface $homePage |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
ShowPageInterface $customerShowPage, |
48
|
|
|
DashboardPageInterface $dashboardPage, |
49
|
|
|
HomePageInterface $homePage |
50
|
|
|
) { |
51
|
|
|
$this->customerShowPage = $customerShowPage; |
52
|
|
|
$this->dashboardPage = $dashboardPage; |
53
|
|
|
$this->homePage = $homePage; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Given I am impersonating the customer :customer |
58
|
|
|
*/ |
59
|
|
|
public function iAmImpersonatingCustomer(CustomerInterface $customer) |
60
|
|
|
{ |
61
|
|
|
$this->customerShowPage->open(['id' => $customer->getId()]); |
62
|
|
|
$this->customerShowPage->impersonate(); |
63
|
|
|
$this->homePage->open(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @When I visit the store |
68
|
|
|
*/ |
69
|
|
|
public function iVisitTheStore() |
70
|
|
|
{ |
71
|
|
|
$this->homePage->open(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @When I log out from the store |
76
|
|
|
*/ |
77
|
|
|
public function iLogOut() |
78
|
|
|
{ |
79
|
|
|
$this->homePage->logOut(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @When I log out from my admin account |
84
|
|
|
*/ |
85
|
|
|
public function iLogOutFromMyAdminAccount() |
86
|
|
|
{ |
87
|
|
|
$this->dashboardPage->open(); |
88
|
|
|
$this->dashboardPage->logOut(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @When I impersonate them |
93
|
|
|
*/ |
94
|
|
|
public function iTryToImpersonateThem() |
95
|
|
|
{ |
96
|
|
|
$this->customerShowPage->impersonate(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Then I should be unable to impersonate them |
101
|
|
|
*/ |
102
|
|
|
public function iShouldBeUnableToImpersonateThem() |
103
|
|
|
{ |
104
|
|
|
Assert::false( |
105
|
|
|
$this->customerShowPage->hasImpersonateButton(), |
106
|
|
|
'I should not be able to impersonate this user.' |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @Then I should still be able to access the administration dashboard |
112
|
|
|
*/ |
113
|
|
|
public function iShouldBeAbleToAccessAdministrationDashboard() |
114
|
|
|
{ |
115
|
|
|
$this->dashboardPage->open(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Then I should be logged in as :fullName |
120
|
|
|
*/ |
121
|
|
|
public function iShouldBeLoggedInAs($fullName) |
122
|
|
|
{ |
123
|
|
|
Assert::true( |
124
|
|
|
$this->homePage->hasLogoutButton(), |
125
|
|
|
'I should be able to sign out.' |
126
|
|
|
); |
127
|
|
|
Assert::contains( |
128
|
|
|
$this->homePage->getFullName(), |
129
|
|
|
$fullName, |
130
|
|
|
'The full name should be "%2$s", but is "%s" instead.' |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @Then I should not be logged in as :fullName |
136
|
|
|
*/ |
137
|
|
|
public function iShouldNotBeLoggedInAs($fullName) |
138
|
|
|
{ |
139
|
|
|
$this->homePage->open(); |
140
|
|
|
|
141
|
|
|
Assert::false( |
142
|
|
|
$this->homePage->hasLogoutButton(), |
143
|
|
|
'I should not be logged in.' |
144
|
|
|
); |
145
|
|
|
Assert::false( |
146
|
|
|
strpos($this->homePage->getFullName(), $fullName), |
147
|
|
|
sprintf('I should not be logged in as %s.', $fullName) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @Then I should see that impersonating :email was successful |
153
|
|
|
*/ |
154
|
|
|
public function iShouldSeeThatImpersonatingWasSuccessful($email) |
155
|
|
|
{ |
156
|
|
|
Assert::contains( |
157
|
|
|
$this->customerShowPage->getSuccessFlashMessage(), |
158
|
|
|
$email |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|