Completed
Pull Request — master (#18)
by Kamil
02:30
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 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 name to :name
63
     */
64
    public function iSetItsNameTo($name)
65
    {
66
        $this->createPage->setName($name);
67
    }
68
69
    /**
70
     * @When I set its title to :title
71
     */
72
    public function iSetItsTitleTo($title)
73
    {
74
        $this->createPage->setTitle($title);
75
    }
76
77
    /**
78
     * @When I set its body to :body
79
     */
80
    public function iSetItsBodyTo($body)
81
    {
82
        $this->createPage->setBody($body);
83
    }
84
85
    /**
86
     * @When I add it
87
     * @When I try to add it
88
     */
89
    public function iAddIt()
90
    {
91
        $this->createPage->create();
92
    }
93
94
    /**
95
     * @Then /^I should be notified that (body|name) is required$/
96
     */
97
    public function iShouldBeNotifiedThatElementIsRequired($element)
98
    {
99
        Assert::same(
100
            $this->createPage->getValidationMessage($element),
101
            'This value should not be blank.'
102
        );
103
    }
104
105
    /**
106
     * @Then the custom block :name should appear in the store
107
     * @Then I should see the custom block :name in the list
108
     */
109 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...
110
    {
111
        if (!$this->indexPage->isOpen()) {
112
            $this->indexPage->open();
113
        }
114
115
        Assert::true(
116
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
117
            sprintf('Could not find custom block with name "%s"!', $name)
118
        );
119
    }
120
121
    /**
122
     * @Then I should see :amount custom blocks in the list
123
     */
124
    public function iShouldSeeThatManyCustomBlocksInTheList($amount)
125
    {
126
        Assert::same(
127
            (int) $amount,
128
            $this->indexPage->countItems(),
129
            'Amount of custom blocks should be equal %s, but was %2$s.'
130
        );
131
    }
132
133
    /**
134
     * @Then the custom block :name should not be added
135
     */
136 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...
137
    {
138
        if (!$this->indexPage->isOpen()) {
139
            $this->indexPage->open();
140
        }
141
142
        Assert::false(
143
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
144
            sprintf('Static content with name %s was created, but it should not.', $name)
145
        );
146
    }
147
148
    /**
149
     * @Given /^I want to edit (this custom block)$/
150
     */
151
    public function iWantToEditThisCustomBlock(CustomBlock $customBlock)
152
    {
153
        $this->updatePage->open(['id' => $customBlock->getId()]);
154
    }
155
156
    /**
157
     * @When I change its body to :body
158
     */
159
    public function iChangeItsBodyTo($body)
160
    {
161
        $this->updatePage->changeBodyTo($body);
162
    }
163
164
    /**
165
     * @When I change its title to :title
166
     */
167
    public function iChangeItsTitleTo($title)
168
    {
169
        $this->updatePage->changeTitleTo($title);
170
    }
171
172
    /**
173
     * @When I save my changes
174
     * @When I try to save my changes
175
     */
176
    public function iSaveMyChanges()
177
    {
178
        $this->updatePage->saveChanges();
179
    }
180
181
    /**
182
     * @When I delete custom block :name
183
     */
184
    public function iDeleteCustomBlock($name)
185
    {
186
        $this->indexPage->open();
187
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
188
    }
189
190
    /**
191
     * @Then /^(this custom block) should have body "([^"]+)"$/
192
     */
193
    public function thisCustomBlockShouldHaveBody(CustomBlock $customBlock, $body)
194
    {
195
        $this->updatePage->open(['id' => $customBlock->getId()]);
196
197
        Assert::same($this->updatePage->getBody(), $body);
198
    }
199
200
    /**
201
     * @Then /^(this custom block) should have title "([^"]+)"$/
202
     */
203
    public function thisCustomBlockShouldHaveTitle(CustomBlock $customBlock, $title)
204
    {
205
        $this->updatePage->open(['id' => $customBlock->getId()]);
206
207
        Assert::same($this->updatePage->getTitle(), $title);
208
    }
209
210
    /**
211
     * @Then the custom block :name should no longer exist in the store
212
     */
213
    public function theCustomBlockShouldNoLongerExistInTheStore($name)
214
    {
215
        Assert::false(
216
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
217
            sprintf('Static content with name %s exists, but should not.', $name)
218
        );
219
    }
220
}
221