Completed
Pull Request — master (#18)
by Kamil
19:34
created

iShouldBeNotifiedThatElementIsRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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 View Code Duplication
    public function theCustomBlockShouldAppearInTheStore($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
135
    {
136
        if (!$this->indexPage->isOpen()) {
137
            $this->indexPage->open();
138
        }
139
140
        Assert::true(
141
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
142
            sprintf('Could not find custom block with name "%s"!', $name)
143
        );
144
    }
145
146
    /**
147
     * @Then I should see :amount custom blocks in the list
148
     */
149
    public function iShouldSeeThatManyCustomBlocksInTheList($amount)
150
    {
151
        Assert::same(
152
            (int) $amount,
153
            $this->indexPage->countItems(),
154
            'Amount of custom blocks should be equal %s, but was %2$s.'
155
        );
156
    }
157
158
    /**
159
     * @Then the custom block :name should not be added
160
     */
161 View Code Duplication
    public function theCustomBlockShouldNotBeAdded($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
162
    {
163
        if (!$this->indexPage->isOpen()) {
164
            $this->indexPage->open();
165
        }
166
167
        Assert::false(
168
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
169
            sprintf('Static content with name %s was created, but it should not.', $name)
170
        );
171
    }
172
173
    /**
174
     * @When /^I preview (this custom block)$/
175
     */
176
    public function iPreviewCustomBlock(CustomBlock $customBlock)
177
    {
178
        $this->showPage->open(['id' => $customBlock->getId()]);
179
    }
180
181
    /**
182
     * @Given /^I want to edit (this custom block)$/
183
     */
184
    public function iWantToEditThisCustomBlock(CustomBlock $customBlock)
185
    {
186
        $this->updatePage->open(['id' => $customBlock->getId()]);
187
    }
188
189
    /**
190
     * @When I change its body to :body
191
     */
192
    public function iChangeItsBodyTo($body)
193
    {
194
        $this->updatePage->changeBodyTo($body);
195
    }
196
197
    /**
198
     * @When I change its link to :link
199
     */
200
    public function iChangeItsLinkTo($link)
201
    {
202
        $this->updatePage->changeLinkTo($link);
203
    }
204
205
    /**
206
     * @When I change its title to :title
207
     */
208
    public function iChangeItsTitleTo($title)
209
    {
210
        $this->updatePage->changeTitleTo($title);
211
    }
212
213
    /**
214
     * @When I save my changes
215
     * @When I try to save my changes
216
     */
217
    public function iSaveMyChanges()
218
    {
219
        $this->updatePage->saveChanges();
220
    }
221
222
    /**
223
     * @When I delete custom block :name
224
     */
225
    public function iDeleteCustomBlock($name)
226
    {
227
        $this->indexPage->open();
228
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
229
    }
230
231
    /**
232
     * @Then I should see :expected in this block contents
233
     */
234
    public function iShouldSeeInThisBlockContents($expected)
235
    {
236
        Assert::contains($this->showPage->getBlockContents(), $expected);
237
    }
238
239
    /**
240
     * @Then /^(this custom block) should have body "([^"]+)"$/
241
     */
242
    public function thisCustomBlockShouldHaveBody(CustomBlock $customBlock, $body)
243
    {
244
        $this->updatePage->open(['id' => $customBlock->getId()]);
245
246
        Assert::same($this->updatePage->getBody(), $body);
247
    }
248
249
    /**
250
     * @Then /^(this custom block) should have link "([^"]+)"$/
251
     */
252
    public function thisCustomBlockShouldHaveLink(CustomBlock $customBlock, $link)
253
    {
254
        $this->updatePage->open(['id' => $customBlock->getId()]);
255
256
        Assert::same($this->updatePage->getLink(), $link);
257
    }
258
259
    /**
260
     * @Then /^(this custom block) should have title "([^"]+)"$/
261
     */
262
    public function thisCustomBlockShouldHaveTitle(CustomBlock $customBlock, $title)
263
    {
264
        $this->updatePage->open(['id' => $customBlock->getId()]);
265
266
        Assert::same($this->updatePage->getTitle(), $title);
267
    }
268
269
    /**
270
     * @Then the custom block :name should no longer exist in the store
271
     */
272
    public function theCustomBlockShouldNoLongerExistInTheStore($name)
273
    {
274
        Assert::false(
275
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
276
            sprintf('Static content with name %s exists, but should not.', $name)
277
        );
278
    }
279
}
280