1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\SyliusCmsBundle\Tests\Behat\Context\Ui\Admin; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\CustomBlock\ShowPageInterface; |
7
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
8
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\CustomBlock\CreatePageInterface; |
9
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\CustomBlock\UpdatePageInterface; |
10
|
|
|
use Lakion\SyliusCmsBundle\Document\CustomBlock; |
11
|
|
|
use Webmozart\Assert\Assert; |
12
|
|
|
|
13
|
|
|
final class ManagingCustomBlocksContext 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 custom block |
55
|
|
|
* @Given I want to add a new custom block |
56
|
|
|
*/ |
57
|
|
|
public function iWantToCreateNewCustomBlock() |
58
|
|
|
{ |
59
|
|
|
$this->createPage->open(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Given I browse custom blocks of the store |
64
|
|
|
*/ |
65
|
|
|
public function iWantToBrowseCustomBlocksOfTheStore() |
66
|
|
|
{ |
67
|
|
|
$this->indexPage->open(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @When I set its body to :body |
72
|
|
|
*/ |
73
|
|
|
public function iSetItsBodyTo($body) |
74
|
|
|
{ |
75
|
|
|
$this->createPage->setBody($body); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @When I set its link to :link |
80
|
|
|
*/ |
81
|
|
|
public function iSetItsLinkTo($link) |
82
|
|
|
{ |
83
|
|
|
$this->createPage->setLink($link); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @When I set its name to :name |
88
|
|
|
*/ |
89
|
|
|
public function iSetItsNameTo($name) |
90
|
|
|
{ |
91
|
|
|
$this->createPage->setName($name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @When I set its title to :title |
96
|
|
|
*/ |
97
|
|
|
public function iSetItsTitleTo($title) |
98
|
|
|
{ |
99
|
|
|
$this->createPage->setTitle($title); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @When I attach :imagePath as its image |
104
|
|
|
*/ |
105
|
|
|
public function iAttachAsItsImage($imagePath) |
106
|
|
|
{ |
107
|
|
|
$this->createPage->attachImage($imagePath); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @When I add it |
112
|
|
|
* @When I try to add it |
113
|
|
|
*/ |
114
|
|
|
public function iAddIt() |
115
|
|
|
{ |
116
|
|
|
$this->createPage->create(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @Then /^I should be notified that (body|name) is required$/ |
121
|
|
|
*/ |
122
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
123
|
|
|
{ |
124
|
|
|
Assert::same( |
125
|
|
|
$this->createPage->getValidationMessage($element), |
126
|
|
|
'This value should not be blank.' |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @Then the custom block :name should appear in the store |
132
|
|
|
* @Then I should see the custom block :name in the list |
133
|
|
|
*/ |
134
|
|
|
public function theCustomBlockShouldAppearInTheStore($name) |
135
|
|
|
{ |
136
|
|
|
if (!$this->indexPage->isOpen()) { |
137
|
|
|
$this->indexPage->open(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @Then I should see :amount custom blocks in the list |
145
|
|
|
*/ |
146
|
|
|
public function iShouldSeeThatManyCustomBlocksInTheList($amount) |
147
|
|
|
{ |
148
|
|
|
Assert::same( |
149
|
|
|
(int) $amount, |
150
|
|
|
$this->indexPage->countItems(), |
151
|
|
|
'Amount of custom blocks should be equal %s, but was %2$s.' |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @Then the custom block :name should not be added |
157
|
|
|
*/ |
158
|
|
|
public function theCustomBlockShouldNotBeAdded($name) |
159
|
|
|
{ |
160
|
|
|
if (!$this->indexPage->isOpen()) { |
161
|
|
|
$this->indexPage->open(); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @When /^I preview (this custom block)$/ |
169
|
|
|
*/ |
170
|
|
|
public function iPreviewCustomBlock(CustomBlock $customBlock) |
171
|
|
|
{ |
172
|
|
|
$this->showPage->open(['id' => $customBlock->getId()]); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @Given /^I want to edit (this custom block)$/ |
177
|
|
|
*/ |
178
|
|
|
public function iWantToEditThisCustomBlock(CustomBlock $customBlock) |
179
|
|
|
{ |
180
|
|
|
$this->updatePage->open(['id' => $customBlock->getId()]); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @When I change its body to :body |
185
|
|
|
*/ |
186
|
|
|
public function iChangeItsBodyTo($body) |
187
|
|
|
{ |
188
|
|
|
$this->updatePage->changeBodyTo($body); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @When I change its link to :link |
193
|
|
|
*/ |
194
|
|
|
public function iChangeItsLinkTo($link) |
195
|
|
|
{ |
196
|
|
|
$this->updatePage->changeLinkTo($link); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @When I change its title to :title |
201
|
|
|
*/ |
202
|
|
|
public function iChangeItsTitleTo($title) |
203
|
|
|
{ |
204
|
|
|
$this->updatePage->changeTitleTo($title); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @When I save my changes |
209
|
|
|
* @When I try to save my changes |
210
|
|
|
*/ |
211
|
|
|
public function iSaveMyChanges() |
212
|
|
|
{ |
213
|
|
|
$this->updatePage->saveChanges(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @When I delete custom block :name |
218
|
|
|
*/ |
219
|
|
|
public function iDeleteCustomBlock($name) |
220
|
|
|
{ |
221
|
|
|
$this->indexPage->open(); |
222
|
|
|
$this->indexPage->deleteResourceOnPage(['name' => $name]); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @Then I should see :expected in this block contents |
227
|
|
|
*/ |
228
|
|
|
public function iShouldSeeInThisBlockContents($expected) |
229
|
|
|
{ |
230
|
|
|
Assert::contains($this->showPage->getBlockContents(), $expected); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @Then /^(this custom block) should have body "([^"]+)"$/ |
235
|
|
|
*/ |
236
|
|
|
public function thisCustomBlockShouldHaveBody(CustomBlock $customBlock, $body) |
237
|
|
|
{ |
238
|
|
|
$this->updatePage->open(['id' => $customBlock->getId()]); |
239
|
|
|
|
240
|
|
|
Assert::same($this->updatePage->getBody(), $body); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @Then /^(this custom block) should have link "([^"]+)"$/ |
245
|
|
|
*/ |
246
|
|
|
public function thisCustomBlockShouldHaveLink(CustomBlock $customBlock, $link) |
247
|
|
|
{ |
248
|
|
|
$this->updatePage->open(['id' => $customBlock->getId()]); |
249
|
|
|
|
250
|
|
|
Assert::same($this->updatePage->getLink(), $link); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @Then /^(this custom block) should have title "([^"]+)"$/ |
255
|
|
|
*/ |
256
|
|
|
public function thisCustomBlockShouldHaveTitle(CustomBlock $customBlock, $title) |
257
|
|
|
{ |
258
|
|
|
$this->updatePage->open(['id' => $customBlock->getId()]); |
259
|
|
|
|
260
|
|
|
Assert::same($this->updatePage->getTitle(), $title); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @Then the custom block :name should no longer exist in the store |
265
|
|
|
*/ |
266
|
|
|
public function theCustomBlockShouldNoLongerExistInTheStore($name) |
267
|
|
|
{ |
268
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|