Completed
Pull Request — master (#18)
by Kamil
03:02
created

ManagingCustomBlocksContext::iAttachAsItsImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
7
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\CustomBlock\CreatePageInterface;
8
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\CustomBlock\UpdatePageInterface;
9
use Lakion\SyliusCmsBundle\Document\CustomBlock;
10
use Webmozart\Assert\Assert;
11
12
final class ManagingCustomBlocksContext implements Context
13
{
14
    /**
15
     * @var IndexPageInterface
16
     */
17
    private $indexPage;
18
19
    /**
20
     * @var CreatePageInterface
21
     */
22
    private $createPage;
23
24
    /**
25
     * @var UpdatePageInterface
26
     */
27
    private $updatePage;
28
29
    /**
30
     * @param IndexPageInterface $indexPage
31
     * @param CreatePageInterface $createPage
32
     * @param UpdatePageInterface $updatePage
33
     */
34
    public function __construct(
35
        IndexPageInterface $indexPage,
36
        CreatePageInterface $createPage,
37
        UpdatePageInterface $updatePage
38
    ) {
39
        $this->indexPage = $indexPage;
40
        $this->createPage = $createPage;
41
        $this->updatePage = $updatePage;
42
    }
43
44
    /**
45
     * @Given I want to create a new custom block
46
     * @Given I want to add a new custom block
47
     */
48
    public function iWantToCreateNewCustomBlock()
49
    {
50
        $this->createPage->open();
51
    }
52
53
    /**
54
     * @Given I browse custom blocks of the store
55
     */
56
    public function iWantToBrowseCustomBlocksOfTheStore()
57
    {
58
        $this->indexPage->open();
59
    }
60
61
    /**
62
     * @When I set its body to :body
63
     */
64
    public function iSetItsBodyTo($body)
65
    {
66
        $this->createPage->setBody($body);
67
    }
68
69
    /**
70
     * @When I set its link to :link
71
     */
72
    public function iSetItsLinkTo($link)
73
    {
74
        $this->createPage->setLink($link);
75
    }
76
77
    /**
78
     * @When I set its name to :name
79
     */
80
    public function iSetItsNameTo($name)
81
    {
82
        $this->createPage->setName($name);
83
    }
84
85
    /**
86
     * @When I set its title to :title
87
     */
88
    public function iSetItsTitleTo($title)
89
    {
90
        $this->createPage->setTitle($title);
91
    }
92
93
    /**
94
     * @When I attach :imagePath as its image
95
     */
96
    public function iAttachAsItsImage($imagePath)
97
    {
98
        $this->createPage->attachImage($imagePath);
99
    }
100
101
    /**
102
     * @When I add it
103
     * @When I try to add it
104
     */
105
    public function iAddIt()
106
    {
107
        $this->createPage->create();
108
    }
109
110
    /**
111
     * @Then /^I should be notified that (body|name) is required$/
112
     */
113
    public function iShouldBeNotifiedThatElementIsRequired($element)
114
    {
115
        Assert::same(
116
            $this->createPage->getValidationMessage($element),
117
            'This value should not be blank.'
118
        );
119
    }
120
121
    /**
122
     * @Then the custom block :name should appear in the store
123
     * @Then I should see the custom block :name in the list
124
     */
125 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...
126
    {
127
        if (!$this->indexPage->isOpen()) {
128
            $this->indexPage->open();
129
        }
130
131
        Assert::true(
132
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
133
            sprintf('Could not find custom block with name "%s"!', $name)
134
        );
135
    }
136
137
    /**
138
     * @Then I should see :amount custom blocks in the list
139
     */
140
    public function iShouldSeeThatManyCustomBlocksInTheList($amount)
141
    {
142
        Assert::same(
143
            (int) $amount,
144
            $this->indexPage->countItems(),
145
            'Amount of custom blocks should be equal %s, but was %2$s.'
146
        );
147
    }
148
149
    /**
150
     * @Then the custom block :name should not be added
151
     */
152 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...
153
    {
154
        if (!$this->indexPage->isOpen()) {
155
            $this->indexPage->open();
156
        }
157
158
        Assert::false(
159
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
160
            sprintf('Static content with name %s was created, but it should not.', $name)
161
        );
162
    }
163
164
    /**
165
     * @Given /^I want to edit (this custom block)$/
166
     */
167
    public function iWantToEditThisCustomBlock(CustomBlock $customBlock)
168
    {
169
        $this->updatePage->open(['id' => $customBlock->getId()]);
170
    }
171
172
    /**
173
     * @When I change its body to :body
174
     */
175
    public function iChangeItsBodyTo($body)
176
    {
177
        $this->updatePage->changeBodyTo($body);
178
    }
179
180
    /**
181
     * @When I change its link to :link
182
     */
183
    public function iChangeItsLinkTo($link)
184
    {
185
        $this->updatePage->changeLinkTo($link);
186
    }
187
188
    /**
189
     * @When I change its title to :title
190
     */
191
    public function iChangeItsTitleTo($title)
192
    {
193
        $this->updatePage->changeTitleTo($title);
194
    }
195
196
    /**
197
     * @When I save my changes
198
     * @When I try to save my changes
199
     */
200
    public function iSaveMyChanges()
201
    {
202
        $this->updatePage->saveChanges();
203
    }
204
205
    /**
206
     * @When I delete custom block :name
207
     */
208
    public function iDeleteCustomBlock($name)
209
    {
210
        $this->indexPage->open();
211
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
212
    }
213
214
    /**
215
     * @Then /^(this custom block) should have body "([^"]+)"$/
216
     */
217
    public function thisCustomBlockShouldHaveBody(CustomBlock $customBlock, $body)
218
    {
219
        $this->updatePage->open(['id' => $customBlock->getId()]);
220
221
        Assert::same($this->updatePage->getBody(), $body);
222
    }
223
224
    /**
225
     * @Then /^(this custom block) should have link "([^"]+)"$/
226
     */
227
    public function thisCustomBlockShouldHaveLink(CustomBlock $customBlock, $link)
228
    {
229
        $this->updatePage->open(['id' => $customBlock->getId()]);
230
231
        Assert::same($this->updatePage->getLink(), $link);
232
    }
233
234
    /**
235
     * @Then /^(this custom block) should have title "([^"]+)"$/
236
     */
237
    public function thisCustomBlockShouldHaveTitle(CustomBlock $customBlock, $title)
238
    {
239
        $this->updatePage->open(['id' => $customBlock->getId()]);
240
241
        Assert::same($this->updatePage->getTitle(), $title);
242
    }
243
244
    /**
245
     * @Then the custom block :name should no longer exist in the store
246
     */
247
    public function theCustomBlockShouldNoLongerExistInTheStore($name)
248
    {
249
        Assert::false(
250
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
251
            sprintf('Static content with name %s exists, but should not.', $name)
252
        );
253
    }
254
}
255