1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Lakion\SyliusCmsBundle\Behat\Context\Ui\Admin; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Lakion\SyliusCmsBundle\Document\ProductBlock; |
7
|
|
|
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\ProductBlock\CreatePageInterface; |
8
|
|
|
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\ProductBlock\ShowPageInterface; |
9
|
|
|
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\ProductBlock\UpdatePageInterface; |
10
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
11
|
|
|
use Webmozart\Assert\Assert; |
12
|
|
|
|
13
|
|
View Code Duplication |
final class ManagingProductBlocksContext implements Context |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var IndexPageInterface |
17
|
|
|
*/ |
18
|
|
|
private $indexPage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var CreatePageInterface |
22
|
|
|
*/ |
23
|
|
|
private $createPage; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var UpdatePageInterface |
27
|
|
|
*/ |
28
|
|
|
private $updatePage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ShowPageInterface |
32
|
|
|
*/ |
33
|
|
|
private $showPage; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param IndexPageInterface $indexPage |
37
|
|
|
* @param CreatePageInterface $createPage |
38
|
|
|
* @param UpdatePageInterface $updatePage |
39
|
|
|
* @param ShowPageInterface $showPage |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
IndexPageInterface $indexPage, |
43
|
|
|
CreatePageInterface $createPage, |
44
|
|
|
UpdatePageInterface $updatePage, |
45
|
|
|
ShowPageInterface $showPage |
46
|
|
|
) { |
47
|
|
|
$this->indexPage = $indexPage; |
48
|
|
|
$this->createPage = $createPage; |
49
|
|
|
$this->updatePage = $updatePage; |
50
|
|
|
$this->showPage = $showPage; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Given I want to create a new product block |
55
|
|
|
* @Given I want to add a new product block |
56
|
|
|
*/ |
57
|
|
|
public function iWantToCreateNewProductBlock() |
58
|
|
|
{ |
59
|
|
|
$this->createPage->open(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Given I browse product blocks of the store |
64
|
|
|
*/ |
65
|
|
|
public function iWantToBrowseProductBlocksOfTheStore() |
66
|
|
|
{ |
67
|
|
|
$this->indexPage->open(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Given I have created a product block :name with image :imagePath |
72
|
|
|
*/ |
73
|
|
|
public function iHaveCreatedProductBlockWithImage($name, $imagePath) |
74
|
|
|
{ |
75
|
|
|
$this->iWantToCreateNewProductBlock(); |
76
|
|
|
$this->iSetItsNameTo($name); |
77
|
|
|
$this->iAttachAsItsImage($imagePath); |
78
|
|
|
$this->iAddIt(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @When I set its body to :body |
83
|
|
|
*/ |
84
|
|
|
public function iSetItsBodyTo($body) |
85
|
|
|
{ |
86
|
|
|
$this->createPage->setBody($body); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @When I set its link to :link |
91
|
|
|
*/ |
92
|
|
|
public function iSetItsLinkTo($link) |
93
|
|
|
{ |
94
|
|
|
$this->createPage->setLink($link); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @When I set its name to :name |
99
|
|
|
*/ |
100
|
|
|
public function iSetItsNameTo($name) |
101
|
|
|
{ |
102
|
|
|
$this->createPage->setName($name); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @When I set its title to :title |
107
|
|
|
*/ |
108
|
|
|
public function iSetItsTitleTo($title) |
109
|
|
|
{ |
110
|
|
|
$this->createPage->setTitle($title); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @When I choose :productName as its product |
115
|
|
|
*/ |
116
|
|
|
public function iChooseProduct($productName) |
117
|
|
|
{ |
118
|
|
|
$this->createPage->chooseProduct($productName); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @When I attach :imagePath as its image |
123
|
|
|
*/ |
124
|
|
|
public function iAttachAsItsImage($imagePath) |
125
|
|
|
{ |
126
|
|
|
$this->createPage->attachImage($imagePath); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @When I add it |
131
|
|
|
* @When I try to add it |
132
|
|
|
*/ |
133
|
|
|
public function iAddIt() |
134
|
|
|
{ |
135
|
|
|
$this->createPage->create(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @Then /^I should be notified that (body|name) is required$/ |
140
|
|
|
*/ |
141
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
142
|
|
|
{ |
143
|
|
|
Assert::same( |
144
|
|
|
$this->createPage->getValidationMessage($element), |
145
|
|
|
'This value should not be blank.' |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @Then the product block :name should appear in the store |
151
|
|
|
* @Then I should see the product block :name in the list |
152
|
|
|
*/ |
153
|
|
|
public function theProductBlockShouldAppearInTheStore($name) |
154
|
|
|
{ |
155
|
|
|
if (!$this->indexPage->isOpen()) { |
156
|
|
|
$this->indexPage->open(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @Then I should see :amount product blocks in the list |
164
|
|
|
*/ |
165
|
|
|
public function iShouldSeeThatManyProductBlocksInTheList($amount) |
166
|
|
|
{ |
167
|
|
|
Assert::same( |
168
|
|
|
(int) $amount, |
169
|
|
|
$this->indexPage->countItems(), |
170
|
|
|
'Amount of product blocks should be equal %s, but was %2$s.' |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @Then the product block :name should not be added |
176
|
|
|
*/ |
177
|
|
|
public function theProductBlockShouldNotBeAdded($name) |
178
|
|
|
{ |
179
|
|
|
if (!$this->indexPage->isOpen()) { |
180
|
|
|
$this->indexPage->open(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @When /^I preview (this product block)$/ |
188
|
|
|
* @When I preview product block :productBlock |
189
|
|
|
*/ |
190
|
|
|
public function iPreviewProductBlock(ProductBlock $productBlock) |
191
|
|
|
{ |
192
|
|
|
$this->showPage->open(['id' => $productBlock->getId()]); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Given /^I want to edit (this product block)$/ |
197
|
|
|
*/ |
198
|
|
|
public function iWantToEditThisProductBlock(ProductBlock $productBlock) |
199
|
|
|
{ |
200
|
|
|
$this->updatePage->open(['id' => $productBlock->getId()]); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @When I change its body to :body |
205
|
|
|
*/ |
206
|
|
|
public function iChangeItsBodyTo($body) |
207
|
|
|
{ |
208
|
|
|
$this->updatePage->changeBodyTo($body); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @When I change its link to :link |
213
|
|
|
*/ |
214
|
|
|
public function iChangeItsLinkTo($link) |
215
|
|
|
{ |
216
|
|
|
$this->updatePage->changeLinkTo($link); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @When I change its title to :title |
221
|
|
|
*/ |
222
|
|
|
public function iChangeItsTitleTo($title) |
223
|
|
|
{ |
224
|
|
|
$this->updatePage->changeTitleTo($title); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @When I change its product to :productName |
229
|
|
|
*/ |
230
|
|
|
public function iChangeItsProductTo($productName) |
231
|
|
|
{ |
232
|
|
|
$this->updatePage->changeProductTo($productName); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @When I save my changes |
237
|
|
|
* @When I try to save my changes |
238
|
|
|
*/ |
239
|
|
|
public function iSaveMyChanges() |
240
|
|
|
{ |
241
|
|
|
$this->updatePage->saveChanges(); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @When I delete product block :name |
246
|
|
|
*/ |
247
|
|
|
public function iDeleteProductBlock($name) |
248
|
|
|
{ |
249
|
|
|
$this->indexPage->open(); |
250
|
|
|
$this->indexPage->deleteResourceOnPage(['name' => $name]); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @Then I should see :expected in this block contents |
255
|
|
|
*/ |
256
|
|
|
public function iShouldSeeInThisBlockContents($expected) |
257
|
|
|
{ |
258
|
|
|
Assert::contains($this->showPage->getBlockContents(), $expected); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @Then I should see an image |
263
|
|
|
*/ |
264
|
|
|
public function iShouldSeeImage() |
265
|
|
|
{ |
266
|
|
|
// TODO: No other way to be sure that image was uploaded properly without messing with setting up the server |
267
|
|
|
Assert::notEmpty($this->showPage->getBlockImageUrl()); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @Then /^(this product block) should have body "([^"]+)"$/ |
272
|
|
|
*/ |
273
|
|
|
public function thisProductBlockShouldHaveBody(ProductBlock $productBlock, $body) |
274
|
|
|
{ |
275
|
|
|
$this->updatePage->open(['id' => $productBlock->getId()]); |
276
|
|
|
|
277
|
|
|
Assert::same($this->updatePage->getBody(), $body); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @Then /^(this product block) should have link "([^"]+)"$/ |
282
|
|
|
*/ |
283
|
|
|
public function thisProductBlockShouldHaveLink(ProductBlock $productBlock, $link) |
284
|
|
|
{ |
285
|
|
|
$this->updatePage->open(['id' => $productBlock->getId()]); |
286
|
|
|
|
287
|
|
|
Assert::same($this->updatePage->getLink(), $link); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @Then /^(this product block) should have title "([^"]+)"$/ |
292
|
|
|
*/ |
293
|
|
|
public function thisProductBlockShouldHaveTitle(ProductBlock $productBlock, $title) |
294
|
|
|
{ |
295
|
|
|
$this->updatePage->open(['id' => $productBlock->getId()]); |
296
|
|
|
|
297
|
|
|
Assert::same($this->updatePage->getTitle(), $title); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @Then /^(this product block) should have product "([^"]+)"$/ |
302
|
|
|
*/ |
303
|
|
|
public function thisProductBlockShouldHaveProduct(ProductBlock $productBlock, $productName) |
304
|
|
|
{ |
305
|
|
|
$this->updatePage->open(['id' => $productBlock->getId()]); |
306
|
|
|
|
307
|
|
|
Assert::same($this->updatePage->getProduct(), $productName); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @Then the product block :name should no longer exist in the store |
312
|
|
|
*/ |
313
|
|
|
public function theProductBlockShouldNoLongerExistInTheStore($name) |
314
|
|
|
{ |
315
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.