|
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\TaxCategory\CreatePageInterface; |
|
19
|
|
|
use Sylius\Behat\Page\Admin\TaxCategory\UpdatePageInterface; |
|
20
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
|
21
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
|
22
|
|
|
use Webmozart\Assert\Assert; |
|
23
|
|
|
|
|
24
|
|
|
final class ManagingTaxCategoriesContext implements Context |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var IndexPageInterface */ |
|
27
|
|
|
private $indexPage; |
|
28
|
|
|
|
|
29
|
|
|
/** @var CreatePageInterface */ |
|
30
|
|
|
private $createPage; |
|
31
|
|
|
|
|
32
|
|
|
/** @var UpdatePageInterface */ |
|
33
|
|
|
private $updatePage; |
|
34
|
|
|
|
|
35
|
|
|
/** @var CurrentPageResolverInterface */ |
|
36
|
|
|
private $currentPageResolver; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
IndexPageInterface $indexPage, |
|
40
|
|
|
CreatePageInterface $createPage, |
|
41
|
|
|
UpdatePageInterface $updatePage, |
|
42
|
|
|
CurrentPageResolverInterface $currentPageResolver |
|
43
|
|
|
) { |
|
44
|
|
|
$this->indexPage = $indexPage; |
|
45
|
|
|
$this->createPage = $createPage; |
|
46
|
|
|
$this->updatePage = $updatePage; |
|
47
|
|
|
$this->currentPageResolver = $currentPageResolver; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @When I delete tax category :taxCategory |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iDeletedTaxCategory(TaxCategoryInterface $taxCategory) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->indexPage->open(); |
|
56
|
|
|
$this->indexPage->deleteResourceOnPage(['code' => $taxCategory->getCode()]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @Then /^(this tax category) should no longer exist in the registry$/ |
|
61
|
|
|
*/ |
|
62
|
|
|
public function thisTaxCategoryShouldNoLongerExistInTheRegistry(TaxCategoryInterface $taxCategory) |
|
63
|
|
|
{ |
|
64
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['code' => $taxCategory->getCode()])); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @Given I want to create a new tax category |
|
69
|
|
|
*/ |
|
70
|
|
|
public function iWantToCreateNewTaxCategory() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->createPage->open(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @When I specify its code as :code |
|
77
|
|
|
* @When I do not specify its code |
|
78
|
|
|
*/ |
|
79
|
|
|
public function iSpecifyItsCodeAs($code = null) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->createPage->specifyCode($code ?? ''); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @When I name it :name |
|
86
|
|
|
* @When I rename it to :name |
|
87
|
|
|
* @When I do not name it |
|
88
|
|
|
* @When I remove its name |
|
89
|
|
|
*/ |
|
90
|
|
|
public function iNameIt($name = null) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->createPage->nameIt($name ?? ''); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @When I add it |
|
97
|
|
|
* @When I try to add it |
|
98
|
|
|
*/ |
|
99
|
|
|
public function iAddIt() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->createPage->create(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @Then I should see the tax category :taxCategoryName in the list |
|
106
|
|
|
* @Then the tax category :taxCategoryName should appear in the registry |
|
107
|
|
|
*/ |
|
108
|
|
|
public function theTaxCategoryShouldAppearInTheRegistry(string $taxCategoryName): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->indexPage->open(); |
|
111
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['nameAndDescription' => $taxCategoryName])); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @When I describe it as :description |
|
116
|
|
|
*/ |
|
117
|
|
|
public function iDescribeItAs($description) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->createPage->describeItAs($description); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @Given I want to modify a tax category :taxCategory |
|
124
|
|
|
* @Given /^I want to modify (this tax category)$/ |
|
125
|
|
|
*/ |
|
126
|
|
|
public function iWantToModifyTaxCategory(TaxCategoryInterface $taxCategory) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->updatePage->open(['id' => $taxCategory->getId()]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @When I save my changes |
|
133
|
|
|
* @When I try to save my changes |
|
134
|
|
|
*/ |
|
135
|
|
|
public function iSaveMyChanges() |
|
136
|
|
|
{ |
|
137
|
|
|
$this->updatePage->saveChanges(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @When I browse tax categories |
|
142
|
|
|
*/ |
|
143
|
|
|
public function iWantToBrowseTaxCategories(): void |
|
144
|
|
|
{ |
|
145
|
|
|
$this->indexPage->open(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @When I check (also) the :taxCategoryName tax category |
|
150
|
|
|
*/ |
|
151
|
|
|
public function iCheckTheTaxCategory(string $taxCategoryName): void |
|
152
|
|
|
{ |
|
153
|
|
|
$this->indexPage->checkResourceOnPage(['nameAndDescription' => $taxCategoryName]); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @When I delete them |
|
158
|
|
|
*/ |
|
159
|
|
|
public function iDeleteThem(): void |
|
160
|
|
|
{ |
|
161
|
|
|
$this->indexPage->bulkDelete(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @Then I should not be able to edit its code |
|
166
|
|
|
*/ |
|
167
|
|
|
public function iShouldNotBeAbleToEditItsCode(): void |
|
168
|
|
|
{ |
|
169
|
|
|
Assert::true($this->updatePage->isCodeDisabled()); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @Then /^(this tax category) name should be "([^"]+)"$/ |
|
174
|
|
|
* @Then /^(this tax category) should still be named "([^"]+)"$/ |
|
175
|
|
|
*/ |
|
176
|
|
|
public function thisTaxCategoryNameShouldBe(TaxCategoryInterface $taxCategory, $taxCategoryName) |
|
177
|
|
|
{ |
|
178
|
|
|
$this->indexPage->open(); |
|
179
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $taxCategory->getCode(), 'nameAndDescription' => $taxCategoryName])); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @Then I should be notified that tax category with this code already exists |
|
184
|
|
|
*/ |
|
185
|
|
|
public function iShouldBeNotifiedThatTaxCategoryWithThisCodeAlreadyExists() |
|
186
|
|
|
{ |
|
187
|
|
|
Assert::same($this->createPage->getValidationMessage('code'), 'The tax category with given code already exists.'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @Then there should still be only one tax category with :element :code |
|
192
|
|
|
*/ |
|
193
|
|
|
public function thereShouldStillBeOnlyOneTaxCategoryWith($element, $code) |
|
194
|
|
|
{ |
|
195
|
|
|
$this->indexPage->open(); |
|
196
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage([$element => $code])); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @Then I should be notified that :element is required |
|
201
|
|
|
*/ |
|
202
|
|
|
public function iShouldBeNotifiedThatIsRequired($element) |
|
203
|
|
|
{ |
|
204
|
|
|
/** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
|
205
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
|
206
|
|
|
|
|
207
|
|
|
Assert::same($currentPage->getValidationMessage($element), sprintf('Please enter tax category %s.', $element)); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @Then tax category with :element :name should not be added |
|
212
|
|
|
*/ |
|
213
|
|
|
public function taxCategoryWithElementValueShouldNotBeAdded($element, $name) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->indexPage->open(); |
|
216
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage([$element => $name])); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @Then I should see a single tax category in the list |
|
221
|
|
|
*/ |
|
222
|
|
|
public function iShouldSeeTaxCategoriesInTheList(): void |
|
223
|
|
|
{ |
|
224
|
|
|
Assert::same($this->indexPage->countItems(), 1); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|