Completed
Push — api ( cecea0...116a36 )
by Kamil
29:57 queued 30s
created

theCodeFieldShouldBeDisabled()   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\Crud\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\CustomerGroup\CreatePageInterface;
19
use Sylius\Behat\Page\Admin\CustomerGroup\UpdatePageInterface;
20
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
21
use Sylius\Component\Customer\Model\CustomerGroupInterface;
22
use Webmozart\Assert\Assert;
23
24
final class ManagingCustomerGroupsContext implements Context
25
{
26
    /** @var CreatePageInterface */
27
    private $createPage;
28
29
    /** @var IndexPageInterface */
30
    private $indexPage;
31
32
    /** @var CurrentPageResolverInterface */
33
    private $currentPageResolver;
34
35
    /** @var UpdatePageInterface */
36
    private $updatePage;
37
38
    public function __construct(
39
        CreatePageInterface $createPage,
40
        IndexPageInterface $indexPage,
41
        CurrentPageResolverInterface $currentPageResolver,
42
        UpdatePageInterface $updatePage
43
    ) {
44
        $this->createPage = $createPage;
45
        $this->indexPage = $indexPage;
46
        $this->currentPageResolver = $currentPageResolver;
47
        $this->updatePage = $updatePage;
48
    }
49
50
    /**
51
     * @Given I want to create a new customer group
52
     */
53
    public function iWantToCreateANewCustomerGroup()
54
    {
55
        $this->createPage->open();
56
    }
57
58
    /**
59
     * @When I specify its code as :code
60
     * @When I do not specify its code
61
     */
62
    public function iSpecifyItsCodeAs($code = null)
63
    {
64
        $this->createPage->specifyCode($code ?? '');
65
    }
66
67
    /**
68
     * @When I specify its name as :name
69
     * @When I remove its name
70
     */
71
    public function iSpecifyItsNameAs($name = null)
72
    {
73
        $this->createPage->nameIt($name ?? '');
74
    }
75
76
    /**
77
     * @When I add it
78
     * @When I try to add it
79
     */
80
    public function iAddIt()
81
    {
82
        $this->createPage->create();
83
    }
84
85
    /**
86
     * @Then the customer group :customerGroup should appear in the store
87
     */
88
    public function theCustomerGroupShouldAppearInTheStore(CustomerGroupInterface $customerGroup)
89
    {
90
        $this->indexPage->open();
91
92
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]));
93
    }
94
95
    /**
96
     * @When /^I want to edit (this customer group)$/
97
     */
98
    public function iWantToEditThisCustomerGroup(CustomerGroupInterface $customerGroup)
99
    {
100
        $this->updatePage->open(['id' => $customerGroup->getId()]);
101
    }
102
103
    /**
104
     * @When I save my changes
105
     * @When I try to save my changes
106
     */
107
    public function iSaveMyChanges()
108
    {
109
        $this->updatePage->saveChanges();
110
    }
111
112
    /**
113
     * @When I check (also) the :customerGroupName customer group
114
     */
115
    public function iCheckTheCustomerGroup(string $customerGroupName): void
116
    {
117
        $this->indexPage->checkResourceOnPage(['name' => $customerGroupName]);
118
    }
119
120
    /**
121
     * @When I delete them
122
     */
123
    public function iDeleteThem(): void
124
    {
125
        $this->indexPage->bulkDelete();
126
    }
127
128
    /**
129
     * @Then this customer group with name :name should appear in the store
130
     * @Then I should see the customer group :name in the list
131
     */
132
    public function thisCustomerGroupWithNameShouldAppearInTheStore($name)
133
    {
134
        $this->indexPage->open();
135
136
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name]));
137
    }
138
139
    /**
140
     * @When I browse customer groups
141
     * @When I want to browse customer groups
142
     */
143
    public function iWantToBrowseCustomerGroups()
144
    {
145
        $this->indexPage->open();
146
    }
147
148
    /**
149
     * @Then I should see a single customer group in the list
150
     * @Then I should see :amountOfCustomerGroups customer groups in the list
151
     */
152
    public function iShouldSeeCustomerGroupsInTheList(int $amountOfCustomerGroups = 1): void
153
    {
154
        $this->indexPage->open();
155
156
        Assert::same($this->indexPage->countItems(), (int) $amountOfCustomerGroups);
157
    }
158
159
    /**
160
     * @Then /^(this customer group) should still be named "([^"]+)"$/
161
     */
162
    public function thisCustomerGroupShouldStillBeNamed(CustomerGroupInterface $customerGroup, $customerGroupName)
0 ignored issues
show
Unused Code introduced by
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...
163
    {
164
        $this->iWantToBrowseCustomerGroups();
165
166
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroupName]));
167
    }
168
169
    /**
170
     * @Then I should be notified that name is required
171
     */
172
    public function iShouldBeNotifiedThatNameIsRequired()
173
    {
174
        Assert::same(
175
            $this->updatePage->getValidationMessage('name'),
176
            'Please enter a customer group name.'
177
        );
178
    }
179
180
    /**
181
     * @Then I should be notified that customer group with this code already exists
182
     */
183
    public function iShouldBeNotifiedThatCustomerGroupWithThisCodeAlreadyExists()
184
    {
185
        Assert::same($this->createPage->getValidationMessage('code'), 'Customer group code has to be unique.');
186
    }
187
188
    /**
189
     * @Then I should be informed that this form contains errors
190
     */
191
    public function iShouldBeInformedThatThisFormContainsErrors()
192
    {
193
        /** @var CreatePageInterface|UpdatePageInterface $currentPage */
194
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
195
196
        Assert::contains($currentPage->getMessageInvalidForm(), 'This form contains errors');
197
    }
198
199
    /**
200
     * @Then I should not be able to edit its code
201
     */
202
    public function iShouldNotBeAbleToEditItsCode(): void
203
    {
204
        Assert::true($this->updatePage->isCodeDisabled());
205
    }
206
207
    /**
208
     * @When I delete the :customerGroup customer group
209
     */
210
    public function iDeleteTheCustomerGroup(CustomerGroupInterface $customerGroup)
211
    {
212
        $this->iWantToBrowseCustomerGroups();
213
214
        $this->indexPage->deleteResourceOnPage(['name' => $customerGroup->getName()]);
215
    }
216
217
    /**
218
     * @Then /^(this customer group) should no longer exist in the registry$/
219
     */
220
    public function thisCustomerGroupShouldNoLongerExistInTheRegistry(CustomerGroupInterface $customerGroup)
221
    {
222
        Assert::false(
223
            $this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]),
224
            sprintf(
225
                'Customer group %s should no longer exist in the registry',
226
                $customerGroup->getName()
227
            )
228
        );
229
    }
230
}
231