ManagingStringBlocksContext   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 6

Importance

Changes 0
Metric Value
wmc 20
lcom 4
cbo 6
dl 0
loc 198
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A iWantToCreateNewStringBlock() 0 4 1
A iWantToBrowseStringBlocksOfTheStore() 0 4 1
A iSetItsNameTo() 0 4 1
A iSetItsBodyTo() 0 4 1
A iAddIt() 0 4 1
A iShouldBeNotifiedThatElementIsRequired() 0 7 1
A theStringBlockShouldAppearInTheStore() 0 8 2
A iShouldSeeThatManyStringBlocksInTheList() 0 8 1
A theStringBlockShouldNotBeAdded() 0 8 2
A iWantToEditThisStringBlock() 0 4 1
A iPreviewStringBlock() 0 4 1
A iChangeItsBodyTo() 0 4 1
A iSaveMyChanges() 0 4 1
A iDeleteStringBlock() 0 5 1
A iShouldSeeInThisBlockContents() 0 4 1
A thisStringBlockShouldHaveBody() 0 6 1
A theStringBlockShouldNoLongerExistInTheStore() 0 4 1
1
<?php
2
3
namespace Tests\Lakion\CmsPlugin\Behat\Context\Ui\Admin;
4
5
use Behat\Behat\Context\Context;
6
use Tests\Lakion\CmsPlugin\Behat\Page\Admin\StringBlock\ShowPageInterface;
7
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
8
use Tests\Lakion\CmsPlugin\Behat\Page\Admin\StringBlock\CreatePageInterface;
9
use Tests\Lakion\CmsPlugin\Behat\Page\Admin\StringBlock\UpdatePageInterface;
10
use Lakion\CmsPlugin\Document\StringBlock;
11
use Webmozart\Assert\Assert;
12
13
final class ManagingStringBlocksContext 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 string block
55
     * @Given I want to add a new string block
56
     */
57
    public function iWantToCreateNewStringBlock()
58
    {
59
        $this->createPage->open();
60
    }
61
62
    /**
63
     * @Given I browse string blocks of the store
64
     */
65
    public function iWantToBrowseStringBlocksOfTheStore()
66
    {
67
        $this->indexPage->open();
68
    }
69
70
    /**
71
     * @When I set its name to :name
72
     */
73
    public function iSetItsNameTo($name)
74
    {
75
        $this->createPage->setName($name);
76
    }
77
78
    /**
79
     * @When I set its body to :body
80
     */
81
    public function iSetItsBodyTo($body)
82
    {
83
        $this->createPage->setBody($body);
84
    }
85
86
    /**
87
     * @When I add it
88
     * @When I try to add it
89
     */
90
    public function iAddIt()
91
    {
92
        $this->createPage->create();
93
    }
94
95
    /**
96
     * @Then /^I should be notified that (body|name) is required$/
97
     */
98
    public function iShouldBeNotifiedThatElementIsRequired($element)
99
    {
100
        Assert::same(
101
            $this->createPage->getValidationMessage($element),
102
            'This value should not be blank.'
103
        );
104
    }
105
106
    /**
107
     * @Then the string block :name should appear in the store
108
     * @Then I should see the string block :name in the list
109
     */
110
    public function theStringBlockShouldAppearInTheStore($name)
111
    {
112
        if (!$this->indexPage->isOpen()) {
113
            $this->indexPage->open();
114
        }
115
116
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name]));
117
    }
118
119
    /**
120
     * @Then I should see :amount string blocks in the list
121
     */
122
    public function iShouldSeeThatManyStringBlocksInTheList($amount)
123
    {
124
        Assert::same(
125
            (int) $amount,
126
            $this->indexPage->countItems(),
127
            'Amount of string blocks should be equal %s, but was %2$s.'
128
        );
129
    }
130
131
    /**
132
     * @Then the string block :name should not be added
133
     */
134
    public function theStringBlockShouldNotBeAdded($name)
135
    {
136
        if (!$this->indexPage->isOpen()) {
137
            $this->indexPage->open();
138
        }
139
140
        Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name]));
141
    }
142
143
    /**
144
     * @Given /^I want to edit (this string block)$/
145
     */
146
    public function iWantToEditThisStringBlock(StringBlock $staticContent)
147
    {
148
        $this->updatePage->open(['id' => $staticContent->getId()]);
149
    }
150
151
    /**
152
     * @When /^I preview (this string block)$/
153
     */
154
    public function iPreviewStringBlock(StringBlock $stringBlock)
155
    {
156
        $this->showPage->open(['id' => $stringBlock->getId()]);
157
    }
158
159
    /**
160
     * @When I change its body to :body
161
     */
162
    public function iChangeItsBodyTo($body)
163
    {
164
        $this->updatePage->changeBodyTo($body);
165
    }
166
167
    /**
168
     * @When I save my changes
169
     * @When I try to save my changes
170
     */
171
    public function iSaveMyChanges()
172
    {
173
        $this->updatePage->saveChanges();
174
    }
175
176
    /**
177
     * @When I delete string block :name
178
     */
179
    public function iDeleteStringBlock($name)
180
    {
181
        $this->indexPage->open();
182
        $this->indexPage->deleteResourceOnPage(['name' => $name]);
183
    }
184
185
    /**
186
     * @Then I should see :expected in this block contents
187
     */
188
    public function iShouldSeeInThisBlockContents($expected)
189
    {
190
        Assert::contains($this->showPage->getBlockContents(), $expected);
191
    }
192
193
    /**
194
     * @Then /^(this string block) should have body "([^"]+)"$/
195
     */
196
    public function thisStringBlockShouldHaveBody(StringBlock $staticContent, $body)
197
    {
198
        $this->updatePage->open(['id' => $staticContent->getId()]);
199
200
        Assert::same($this->updatePage->getBody(), $body);
201
    }
202
203
    /**
204
     * @Then the string block :name should no longer exist in the store
205
     */
206
    public function theStringBlockShouldNoLongerExistInTheStore($name)
207
    {
208
        Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name]));
209
    }
210
}
211