Completed
Push — master ( a13c2f...df1c7f )
by Kamil
9s
created

theCustomBlockShouldAppearInTheStore()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Tests\Lakion\SyliusCmsBundle\Behat\Context\Ui\Admin;
4
5
use Behat\Behat\Context\Context;
6
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\CustomBlock\ShowPageInterface;
7
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
8
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\CustomBlock\CreatePageInterface;
9
use Tests\Lakion\SyliusCmsBundle\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
     * @Given I have created a custom block :name with image :imagePath
72
     */
73
    public function iHaveCreatedCustomBlockWithImage($name, $imagePath)
74
    {
75
        $this->iWantToCreateNewCustomBlock();
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 attach :imagePath as its image
115
     */
116
    public function iAttachAsItsImage($imagePath)
117
    {
118
        $this->createPage->attachImage($imagePath);
119
    }
120
121
    /**
122
     * @When I add it
123
     * @When I try to add it
124
     */
125
    public function iAddIt()
126
    {
127
        $this->createPage->create();
128
    }
129
130
    /**
131
     * @Then /^I should be notified that (body|name) is required$/
132
     */
133
    public function iShouldBeNotifiedThatElementIsRequired($element)
134
    {
135
        Assert::same(
136
            $this->createPage->getValidationMessage($element),
137
            'This value should not be blank.'
138
        );
139
    }
140
141
    /**
142
     * @Then the custom block :name should appear in the store
143
     * @Then I should see the custom block :name in the list
144
     */
145
    public function theCustomBlockShouldAppearInTheStore($name)
146
    {
147
        if (!$this->indexPage->isOpen()) {
148
            $this->indexPage->open();
149
        }
150
151
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name]));
152
    }
153
154
    /**
155
     * @Then I should see :amount custom blocks in the list
156
     */
157
    public function iShouldSeeThatManyCustomBlocksInTheList($amount)
158
    {
159
        Assert::same(
160
            (int) $amount,
161
            $this->indexPage->countItems(),
162
            'Amount of custom blocks should be equal %s, but was %2$s.'
163
        );
164
    }
165
166
    /**
167
     * @Then the custom block :name should not be added
168
     */
169
    public function theCustomBlockShouldNotBeAdded($name)
170
    {
171
        if (!$this->indexPage->isOpen()) {
172
            $this->indexPage->open();
173
        }
174
175
        Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name]));
176
    }
177
178
    /**
179
     * @When /^I preview (this custom block)$/
180
     * @When I preview custom block :customBlock
181
     */
182
    public function iPreviewCustomBlock(CustomBlock $customBlock)
183
    {
184
        $this->showPage->open(['id' => $customBlock->getId()]);
185
    }
186
187
    /**
188
     * @Given /^I want to edit (this custom block)$/
189
     */
190
    public function iWantToEditThisCustomBlock(CustomBlock $customBlock)
191
    {
192
        $this->updatePage->open(['id' => $customBlock->getId()]);
193
    }
194
195
    /**
196
     * @When I change its body to :body
197
     */
198
    public function iChangeItsBodyTo($body)
199
    {
200
        $this->updatePage->changeBodyTo($body);
201
    }
202
203
    /**
204
     * @When I change its link to :link
205
     */
206
    public function iChangeItsLinkTo($link)
207
    {
208
        $this->updatePage->changeLinkTo($link);
209
    }
210
211
    /**
212
     * @When I change its title to :title
213
     */
214
    public function iChangeItsTitleTo($title)
215
    {
216
        $this->updatePage->changeTitleTo($title);
217
    }
218
219
    /**
220
     * @When I save my changes
221
     * @When I try to save my changes
222
     */
223
    public function iSaveMyChanges()
224
    {
225
        $this->updatePage->saveChanges();
226
    }
227
228
    /**
229
     * @When I delete custom block :name
230
     */
231
    public function iDeleteCustomBlock($name)
232
    {
233
        $this->indexPage->open();
234
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
235
    }
236
237
    /**
238
     * @Then I should see :expected in this block contents
239
     */
240
    public function iShouldSeeInThisBlockContents($expected)
241
    {
242
        Assert::contains($this->showPage->getBlockContents(), $expected);
243
    }
244
245
    /**
246
     * @Then I should see an image
247
     */
248
    public function iShouldSeeImage()
249
    {
250
        // TODO: No other way to be sure that image was uploaded properly without messing with setting up the server
251
        Assert::notEmpty($this->showPage->getBlockImageUrl());
252
    }
253
254
    /**
255
     * @Then /^(this custom block) should have body "([^"]+)"$/
256
     */
257
    public function thisCustomBlockShouldHaveBody(CustomBlock $customBlock, $body)
258
    {
259
        $this->updatePage->open(['id' => $customBlock->getId()]);
260
261
        Assert::same($this->updatePage->getBody(), $body);
262
    }
263
264
    /**
265
     * @Then /^(this custom block) should have link "([^"]+)"$/
266
     */
267
    public function thisCustomBlockShouldHaveLink(CustomBlock $customBlock, $link)
268
    {
269
        $this->updatePage->open(['id' => $customBlock->getId()]);
270
271
        Assert::same($this->updatePage->getLink(), $link);
272
    }
273
274
    /**
275
     * @Then /^(this custom block) should have title "([^"]+)"$/
276
     */
277
    public function thisCustomBlockShouldHaveTitle(CustomBlock $customBlock, $title)
278
    {
279
        $this->updatePage->open(['id' => $customBlock->getId()]);
280
281
        Assert::same($this->updatePage->getTitle(), $title);
282
    }
283
284
    /**
285
     * @Then the custom block :name should no longer exist in the store
286
     */
287
    public function theCustomBlockShouldNoLongerExistInTheStore($name)
288
    {
289
        Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name]));
290
    }
291
}
292