1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\SyliusCmsBundle\Tests\Behat\Context\Ui\Admin; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Lakion\SyliusCmsBundle\Document\TaxonBlock; |
7
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\TaxonBlock\CreatePageInterface; |
8
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\TaxonBlock\ShowPageInterface; |
9
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\TaxonBlock\UpdatePageInterface; |
10
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
11
|
|
|
use Webmozart\Assert\Assert; |
12
|
|
|
|
13
|
|
View Code Duplication |
final class ManagingTaxonBlocksContext 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 taxon block |
55
|
|
|
* @Given I want to add a new taxon block |
56
|
|
|
*/ |
57
|
|
|
public function iWantToCreateNewTaxonBlock() |
58
|
|
|
{ |
59
|
|
|
$this->createPage->open(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Given I browse taxon blocks of the store |
64
|
|
|
*/ |
65
|
|
|
public function iWantToBrowseTaxonBlocksOfTheStore() |
66
|
|
|
{ |
67
|
|
|
$this->indexPage->open(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Given I have created a taxon block :name with image :imagePath |
72
|
|
|
*/ |
73
|
|
|
public function iHaveCreatedTaxonBlockWithImage($name, $imagePath) |
74
|
|
|
{ |
75
|
|
|
$this->iWantToCreateNewTaxonBlock(); |
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 :taxonName as its taxon |
115
|
|
|
*/ |
116
|
|
|
public function iChooseTaxon($taxonName) |
117
|
|
|
{ |
118
|
|
|
$this->createPage->chooseTaxon($taxonName); |
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 taxon block :name should appear in the store |
151
|
|
|
* @Then I should see the taxon block :name in the list |
152
|
|
|
*/ |
153
|
|
|
public function theTaxonBlockShouldAppearInTheStore($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 taxon blocks in the list |
164
|
|
|
*/ |
165
|
|
|
public function iShouldSeeThatManyTaxonBlocksInTheList($amount) |
166
|
|
|
{ |
167
|
|
|
Assert::same( |
168
|
|
|
(int) $amount, |
169
|
|
|
$this->indexPage->countItems(), |
170
|
|
|
'Amount of taxon blocks should be equal %s, but was %2$s.' |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @Then the taxon block :name should not be added |
176
|
|
|
*/ |
177
|
|
|
public function theTaxonBlockShouldNotBeAdded($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 taxon block)$/ |
188
|
|
|
* @When I preview taxon block :taxonBlock |
189
|
|
|
*/ |
190
|
|
|
public function iPreviewTaxonBlock(TaxonBlock $taxonBlock) |
191
|
|
|
{ |
192
|
|
|
$this->showPage->open(['id' => $taxonBlock->getId()]); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Given /^I want to edit (this taxon block)$/ |
197
|
|
|
*/ |
198
|
|
|
public function iWantToEditThisTaxonBlock(TaxonBlock $taxonBlock) |
199
|
|
|
{ |
200
|
|
|
$this->updatePage->open(['id' => $taxonBlock->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 taxon to :taxonName |
229
|
|
|
*/ |
230
|
|
|
public function iChangeItsTaxonTo($taxonName) |
231
|
|
|
{ |
232
|
|
|
$this->updatePage->changeTaxonTo($taxonName); |
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 taxon block :name |
246
|
|
|
*/ |
247
|
|
|
public function iDeleteTaxonBlock($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 taxon block) should have body "([^"]+)"$/ |
272
|
|
|
*/ |
273
|
|
|
public function thisTaxonBlockShouldHaveBody(TaxonBlock $taxonBlock, $body) |
274
|
|
|
{ |
275
|
|
|
$this->updatePage->open(['id' => $taxonBlock->getId()]); |
276
|
|
|
|
277
|
|
|
Assert::same($this->updatePage->getBody(), $body); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @Then /^(this taxon block) should have link "([^"]+)"$/ |
282
|
|
|
*/ |
283
|
|
|
public function thisTaxonBlockShouldHaveLink(TaxonBlock $taxonBlock, $link) |
284
|
|
|
{ |
285
|
|
|
$this->updatePage->open(['id' => $taxonBlock->getId()]); |
286
|
|
|
|
287
|
|
|
Assert::same($this->updatePage->getLink(), $link); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @Then /^(this taxon block) should have title "([^"]+)"$/ |
292
|
|
|
*/ |
293
|
|
|
public function thisTaxonBlockShouldHaveTitle(TaxonBlock $taxonBlock, $title) |
294
|
|
|
{ |
295
|
|
|
$this->updatePage->open(['id' => $taxonBlock->getId()]); |
296
|
|
|
|
297
|
|
|
Assert::same($this->updatePage->getTitle(), $title); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @Then /^(this taxon block) should have taxon "([^"]+)"$/ |
302
|
|
|
*/ |
303
|
|
|
public function thisTaxonBlockShouldHaveTaxon(TaxonBlock $taxonBlock, $taxonName) |
304
|
|
|
{ |
305
|
|
|
$this->updatePage->open(['id' => $taxonBlock->getId()]); |
306
|
|
|
|
307
|
|
|
Assert::same($this->updatePage->getTaxon(), $taxonName); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @Then the taxon block :name should no longer exist in the store |
312
|
|
|
*/ |
313
|
|
|
public function theTaxonBlockShouldNoLongerExistInTheStore($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.