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