Completed
Pull Request — master (#24)
by Kamil
02:40
created

iHaveCreatedCustomBlockWithImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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