Completed
Push — master ( 799620...8a5869 )
by Kamil
116:02 queued 102:30
created

Context/Ui/Admin/ManagingCustomerGroupsContext.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Crud\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\CustomerGroup\CreatePageInterface;
19
use Sylius\Behat\Page\Admin\CustomerGroup\UpdatePageInterface;
20
use Sylius\Component\Customer\Model\CustomerGroupInterface;
21
use Webmozart\Assert\Assert;
22
23
final class ManagingCustomerGroupsContext implements Context
24
{
25
    /**
26
     * @var CreatePageInterface
27
     */
28
    private $createPage;
29
30
    /**
31
     * @var IndexPageInterface
32
     */
33
    private $indexPage;
34
35
    /**
36
     * @var UpdatePageInterface
37
     */
38
    private $updatePage;
39
40
    /**
41
     * @param CreatePageInterface $createPage
42
     * @param IndexPageInterface $indexPage
43
     * @param UpdatePageInterface $updatePage
44
     */
45
    public function __construct(
46
        CreatePageInterface $createPage,
47
        IndexPageInterface $indexPage,
48
        UpdatePageInterface $updatePage
49
    ) {
50
        $this->createPage = $createPage;
51
        $this->indexPage = $indexPage;
52
        $this->updatePage = $updatePage;
53
    }
54
55
    /**
56
     * @Given I want to create a new customer group
57
     */
58
    public function iWantToCreateANewCustomerGroup()
59
    {
60
        $this->createPage->open();
61
    }
62
63
    /**
64
     * @When I specify its code as :code
65
     * @When I do not specify its code
66
     */
67
    public function iSpecifyItsCodeAs($code = null)
68
    {
69
        $this->createPage->specifyCode($code);
70
    }
71
72
    /**
73
     * @When I specify its name as :name
74
     * @When I remove its name
75
     */
76
    public function iSpecifyItsNameAs($name = null)
77
    {
78
        $this->createPage->nameIt($name);
79
    }
80
81
    /**
82
     * @When I add it
83
     * @When I try to add it
84
     */
85
    public function iAddIt()
86
    {
87
        $this->createPage->create();
88
    }
89
90
    /**
91
     * @Then the customer group :customerGroup should appear in the store
92
     */
93
    public function theCustomerGroupShouldAppearInTheStore(CustomerGroupInterface $customerGroup)
94
    {
95
        $this->indexPage->open();
96
97
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]));
98
    }
99
100
    /**
101
     * @When /^I want to edit (this customer group)$/
102
     */
103
    public function iWantToEditThisCustomerGroup(CustomerGroupInterface $customerGroup)
104
    {
105
        $this->updatePage->open(['id' => $customerGroup->getId()]);
106
    }
107
108
    /**
109
     * @When I save my changes
110
     * @When I try to save my changes
111
     */
112
    public function iSaveMyChanges()
113
    {
114
        $this->updatePage->saveChanges();
115
    }
116
117
    /**
118
     * @When I check (also) the :customerGroupName customer group
119
     */
120
    public function iCheckTheCustomerGroup(string $customerGroupName): void
121
    {
122
        $this->indexPage->checkResourceOnPage(['name' => $customerGroupName]);
123
    }
124
125
    /**
126
     * @When I delete them
127
     */
128
    public function iDeleteThem(): void
129
    {
130
        $this->indexPage->bulkDelete();
131
    }
132
133
    /**
134
     * @Then this customer group with name :name should appear in the store
135
     * @Then I should see the customer group :name in the list
136
     */
137
    public function thisCustomerGroupWithNameShouldAppearInTheStore($name)
138
    {
139
        $this->indexPage->open();
140
141
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name]));
142
    }
143
144
    /**
145
     * @When I browse customer groups
146
     * @When I want to browse customer groups
147
     */
148
    public function iWantToBrowseCustomerGroups()
149
    {
150
        $this->indexPage->open();
151
    }
152
153
    /**
154
     * @Then I should see a single customer group in the list
155
     * @Then I should see :amountOfCustomerGroups customer groups in the list
156
     */
157
    public function iShouldSeeCustomerGroupsInTheList(int $amountOfCustomerGroups = 1): void
158
    {
159
        $this->indexPage->open();
160
161
        Assert::same($this->indexPage->countItems(), (int) $amountOfCustomerGroups);
162
    }
163
164
    /**
165
     * @Then /^(this customer group) should still be named "([^"]+)"$/
166
     */
167
    public function thisCustomerGroupShouldStillBeNamed(CustomerGroupInterface $customerGroup, $customerGroupName)
0 ignored issues
show
The parameter $customerGroup is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
    {
169
        $this->iWantToBrowseCustomerGroups();
170
171
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroupName]));
172
    }
173
174
    /**
175
     * @Then I should be notified that name is required
176
     */
177
    public function iShouldBeNotifiedThatNameIsRequired()
178
    {
179
        Assert::same(
180
            $this->updatePage->getValidationMessage('name'),
181
            'Please enter a customer group name.'
182
        );
183
    }
184
185
    /**
186
     * @Then I should be notified that customer group with this code already exists
187
     */
188
    public function iShouldBeNotifiedThatCustomerGroupWithThisCodeAlreadyExists()
189
    {
190
        Assert::same($this->createPage->getValidationMessage('code'), 'Customer group code has to be unique.');
191
    }
192
193
    /**
194
     * @Then the code field should be disabled
195
     */
196
    public function theCodeFieldShouldBeDisabled()
197
    {
198
        Assert::true($this->updatePage->isCodeDisabled());
199
    }
200
201
    /**
202
     * @When I delete the :customerGroup customer group
203
     */
204
    public function iDeleteTheCustomerGroup(CustomerGroupInterface $customerGroup)
205
    {
206
        $this->iWantToBrowseCustomerGroups();
207
208
        $this->indexPage->deleteResourceOnPage(['name' => $customerGroup->getName()]);
209
    }
210
211
    /**
212
     * @Then /^(this customer group) should no longer exist in the registry$/
213
     */
214
    public function thisCustomerGroupShouldNoLongerExistInTheRegistry(CustomerGroupInterface $customerGroup)
215
    {
216
        Assert::false(
217
            $this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]),
218
            sprintf(
219
                'Customer group %s should no longer exist in the registry',
220
                $customerGroup->getName()
221
            )
222
        );
223
    }
224
}
225