Completed
Push — 1.7 ( 1627e8...895c05 )
by Kamil
73:45 queued 48:32
created

iTryToImpersonateThem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\Page\Admin\Administrator\ImpersonateUserPageInterface;
18
use Sylius\Behat\Page\Admin\Customer\ShowPageInterface;
19
use Sylius\Behat\Page\Admin\DashboardPageInterface;
20
use Sylius\Behat\Page\Shop\HomePageInterface;
21
use Sylius\Component\Customer\Model\CustomerInterface;
22
use Webmozart\Assert\Assert;
23
24
final class ImpersonatingCustomersContext implements Context
25
{
26
    /** @var ShowPageInterface */
27
    private $customerShowPage;
28
29
    /** @var DashboardPageInterface */
30
    private $dashboardPage;
31
32
    /** @var HomePageInterface */
33
    private $homePage;
34
35
    /** @var ImpersonateUserPageInterface */
36
    protected $impersonateUserPage;
37
38
    public function __construct(
39
        ShowPageInterface $customerShowPage,
40
        DashboardPageInterface $dashboardPage,
41
        HomePageInterface $homePage,
42
        ImpersonateUserPageInterface $impersonateUserPage
43
    ) {
44
        $this->customerShowPage = $customerShowPage;
45
        $this->dashboardPage = $dashboardPage;
46
        $this->homePage = $homePage;
47
        $this->impersonateUserPage = $impersonateUserPage;
48
    }
49
50
    /**
51
     * @Given I am impersonating the customer :customer
52
     */
53
    public function iAmImpersonatingCustomer(CustomerInterface $customer)
54
    {
55
        $this->customerShowPage->open(['id' => $customer->getId()]);
56
        $this->customerShowPage->impersonate();
57
        $this->homePage->open();
58
    }
59
60
    /**
61
     * @When I visit the store
62
     */
63
    public function iVisitTheStore()
64
    {
65
        $this->homePage->open();
66
    }
67
68
    /**
69
     * @When I log out from the store
70
     */
71
    public function iLogOut()
72
    {
73
        $this->homePage->logOut();
74
    }
75
76
    /**
77
     * @When I log out from my admin account
78
     */
79
    public function iLogOutFromMyAdminAccount()
80
    {
81
        $this->dashboardPage->open();
82
        $this->dashboardPage->logOut();
83
    }
84
85
    /**
86
     * @When I impersonate them
87
     */
88
    public function iTryToImpersonateThem()
89
    {
90
        $this->customerShowPage->impersonate();
91
    }
92
93
    /**
94
     * @When I impersonate the customer :customer
95
     */
96
    public function iImpersonateCustomer(CustomerInterface $customer)
97
    {
98
        $this->impersonateUserPage->tryToOpen(['username' => $customer->getEmail()]);
99
    }
100
101
    /**
102
     * @Then I should be unable to impersonate them
103
     */
104
    public function iShouldBeUnableToImpersonateThem()
105
    {
106
        Assert::false($this->customerShowPage->hasImpersonateButton());
107
    }
108
109
    /**
110
     * @Then I should still be able to access the administration dashboard
111
     */
112
    public function iShouldBeAbleToAccessAdministrationDashboard()
113
    {
114
        $this->dashboardPage->open();
115
    }
116
117
    /**
118
     * @Then I should be logged in as :fullName
119
     */
120
    public function iShouldBeLoggedInAs($fullName)
121
    {
122
        Assert::true($this->homePage->hasLogoutButton());
123
        Assert::contains($this->homePage->getFullName(), $fullName);
124
    }
125
126
    /**
127
     * @Then I should not be logged in as :fullName
128
     */
129
    public function iShouldNotBeLoggedInAs($fullName)
130
    {
131
        $this->homePage->open();
132
133
        Assert::false($this->homePage->hasLogoutButton());
134
        Assert::false(strpos($this->homePage->getFullName(), $fullName));
135
    }
136
137
    /**
138
     * @Then I should see that impersonating :email was successful
139
     */
140
    public function iShouldSeeThatImpersonatingWasSuccessful($email)
141
    {
142
        Assert::contains($this->customerShowPage->getSuccessFlashMessage(), $email);
143
    }
144
}
145