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

iDeleteStaticContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Tests\Lakion\SyliusCmsBundle\Behat\Context\Ui\Admin;
4
5
use Behat\Behat\Context\Context;
6
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
7
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\StaticContent\CreatePageInterface;
8
use Tests\Lakion\SyliusCmsBundle\Behat\Page\Admin\StaticContent\UpdatePageInterface;
9
use Lakion\SyliusCmsBundle\Document\StaticContent;
10
use Webmozart\Assert\Assert;
11
12
final class ManagingStaticContentsContext 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 static content
46
     * @Given I want to add a new static content
47
     */
48
    public function iWantToCreateNewStaticContent()
49
    {
50
        $this->createPage->open();
51
    }
52
53
    /**
54
     * @When I want to browse static contents of the store
55
     */
56
    public function iWantToBrowseStaticContentsOfTheStore()
57
    {
58
        $this->indexPage->open();
59
    }
60
61
    /**
62
     * @When I set its title to :title
63
     */
64
    public function iSetItsTitleTo($title)
65
    {
66
        $this->createPage->setTitle($title);
67
    }
68
69
    /**
70
     * @When I set its name to :name
71
     */
72
    public function iSetItsNameTo($name)
73
    {
74
        $this->createPage->setName($name);
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|title) 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 static content :title should appear in the store
107
     * @Then I should see the static content :title in the list
108
     */
109 View Code Duplication
    public function theStaticContentShouldAppearInTheStore($title)
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($this->indexPage->isSingleResourceOnPage(['title' => $title]));
116
    }
117
118
    /**
119
     * @Then I should see :amount static contents in the list
120
     */
121
    public function iShouldSeeThatManyStaticContentsInTheList($amount)
122
    {
123
        Assert::same(
124
            (int) $amount,
125
            $this->indexPage->countItems(),
126
            'Amount of static contents should be equal %s, but was %2$s.'
127
        );
128
    }
129
130
    /**
131
     * @Then the static content :title should not be added
132
     */
133 View Code Duplication
    public function theStaticContentShouldNotBeAdded($title)
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...
134
    {
135
        if (!$this->indexPage->isOpen()) {
136
            $this->indexPage->open();
137
        }
138
139
        Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title]));
140
    }
141
142
    /**
143
     * @Given /^I want to edit (this static content)$/
144
     */
145
    public function iWantToEditThisStaticContent(StaticContent $staticContent)
146
    {
147
        $this->updatePage->open(['id' => $staticContent->getId()]);
148
    }
149
150
    /**
151
     * @When I change its body to :body
152
     */
153
    public function iChangeItsBodyTo($body)
154
    {
155
        $this->updatePage->changeBodyTo($body);
156
    }
157
158
    /**
159
     * @When I save my changes
160
     * @When I try to save my changes
161
     */
162
    public function iSaveMyChanges()
163
    {
164
        $this->updatePage->saveChanges();
165
    }
166
167
    /**
168
     * @When I delete static content :title
169
     */
170
    public function iDeleteStaticContent($title)
171
    {
172
        $this->indexPage->open();
173
        $this->indexPage->deleteResourceOnPage(['title' => $title]);
174
    }
175
176
    /**
177
     * @Then /^(this static content) should have body "([^"]+)"$/
178
     */
179
    public function thisStaticContentShouldHaveBody(StaticContent $staticContent, $body)
180
    {
181
        $this->updatePage->open(['id' => $staticContent->getId()]);
182
183
        Assert::same($this->updatePage->getBody(), $body);
184
    }
185
186
    /**
187
     * @Then the static content :title should no longer exist in the store
188
     */
189
    public function theStaticContentShouldNoLongerExistInTheStore($title)
190
    {
191
        Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title]));
192
    }
193
}
194