Completed
Push — master ( 3182b0...115a8b )
by Arkadiusz
11s
created

theStringBlockShouldAppearInTheStore()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
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\StringBlock\CreatePageInterface;
8
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\StringBlock\UpdatePageInterface;
9
use Lakion\SyliusCmsBundle\Document\StringBlock;
10
use Webmozart\Assert\Assert;
11
12
final class ManagingStringBlocksContext 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 string block
46
     * @Given I want to add a new string block
47
     */
48
    public function iWantToCreateNewStringBlock()
49
    {
50
        $this->createPage->open();
51
    }
52
53
    /**
54
     * @Given I browse string blocks of the store
55
     */
56
    public function iWantToBrowseStringBlocksOfTheStore()
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 body to :body
71
     */
72
    public function iSetItsBodyTo($body)
73
    {
74
        $this->createPage->setBody($body);
75
    }
76
77
    /**
78
     * @When I add it
79
     * @When I try to add it
80
     */
81
    public function iAddIt()
82
    {
83
        $this->createPage->create();
84
    }
85
86
    /**
87
     * @Then /^I should be notified that (body|name) is required$/
88
     */
89
    public function iShouldBeNotifiedThatElementIsRequired($element)
90
    {
91
        Assert::same(
92
            $this->createPage->getValidationMessage($element),
93
            'This value should not be blank.'
94
        );
95
    }
96
97
    /**
98
     * @Then the string block :name should appear in the store
99
     * @Then I should see the string block :name in the list
100
     */
101 View Code Duplication
    public function theStringBlockShouldAppearInTheStore($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...
102
    {
103
        if (!$this->indexPage->isOpen()) {
104
            $this->indexPage->open();
105
        }
106
107
        Assert::true(
108
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
109
            sprintf('Could not find string block with name "%s"!', $name)
110
        );
111
    }
112
113
    /**
114
     * @Then I should see :amount string blocks in the list
115
     */
116
    public function iShouldSeeThatManyStringBlocksInTheList($amount)
117
    {
118
        Assert::same(
119
            (int) $amount,
120
            $this->indexPage->countItems(),
121
            'Amount of string blocks should be equal %s, but was %2$s.'
122
        );
123
    }
124
125
    /**
126
     * @Then the string block :name should not be added
127
     */
128 View Code Duplication
    public function theStringBlockShouldNotBeAdded($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...
129
    {
130
        if (!$this->indexPage->isOpen()) {
131
            $this->indexPage->open();
132
        }
133
134
        Assert::false(
135
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
136
            sprintf('Static content with name %s was created, but it should not.', $name)
137
        );
138
    }
139
140
    /**
141
     * @Given /^I want to edit (this string block)$/
142
     */
143
    public function iWantToEditThisStringBlock(StringBlock $staticContent)
144
    {
145
        $this->updatePage->open(['id' => $staticContent->getId()]);
146
    }
147
148
    /**
149
     * @When I change its body to :body
150
     */
151
    public function iChangeItsBodyTo($body)
152
    {
153
        $this->updatePage->changeBodyTo($body);
154
    }
155
156
    /**
157
     * @When I save my changes
158
     * @When I try to save my changes
159
     */
160
    public function iSaveMyChanges()
161
    {
162
        $this->updatePage->saveChanges();
163
    }
164
165
    /**
166
     * @When I delete string block :name
167
     */
168
    public function iDeleteStringBlock($name)
169
    {
170
        $this->indexPage->open();
171
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
172
    }
173
174
    /**
175
     * @Then /^(this string block) should have body "([^"]+)"$/
176
     */
177
    public function thisStringBlockShouldHaveBody(StringBlock $staticContent, $body)
178
    {
179
        $this->updatePage->open(['id' => $staticContent->getId()]);
180
181
        Assert::same($this->updatePage->getBody(), $body);
182
    }
183
184
    /**
185
     * @Then the string block :name should no longer exist in the store
186
     */
187
    public function theStringBlockShouldNoLongerExistInTheStore($name)
188
    {
189
        Assert::false(
190
            $this->indexPage->isSingleResourceOnPage(['name' => $name]),
191
            sprintf('Static content with name %s exists, but should not.', $name)
192
        );
193
    }
194
}
195