|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Lakion\CmsPlugin\Behat\Context\Ui\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
|
6
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
|
7
|
|
|
use Tests\Lakion\CmsPlugin\Behat\Page\Admin\Route\CreatePageInterface; |
|
8
|
|
|
use Tests\Lakion\CmsPlugin\Behat\Page\Admin\Route\UpdatePageInterface; |
|
9
|
|
|
use Lakion\CmsPlugin\Document\Route; |
|
10
|
|
|
use Webmozart\Assert\Assert; |
|
11
|
|
|
|
|
12
|
|
|
final class ManagingRoutesContext 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 route |
|
46
|
|
|
* @Given I want to add a new route |
|
47
|
|
|
*/ |
|
48
|
|
|
public function iWantToCreateNewRoute() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->createPage->open(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @When I want to browse routes of the store |
|
55
|
|
|
*/ |
|
56
|
|
|
public function iWantToBrowseRoutesOfTheStore() |
|
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 choose :title as its content |
|
71
|
|
|
*/ |
|
72
|
|
|
public function iChooseContent($title) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->createPage->chooseContent($title); |
|
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 the route :name should appear in the store |
|
88
|
|
|
* @Then I should see the route :name in the list |
|
89
|
|
|
*/ |
|
90
|
|
|
public function theRouteShouldAppearInTheStore($name) |
|
91
|
|
|
{ |
|
92
|
|
|
if (!$this->indexPage->isOpen()) { |
|
93
|
|
|
$this->indexPage->open(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @Then I should see :amount routes in the list |
|
101
|
|
|
*/ |
|
102
|
|
|
public function iShouldSeeThatManyRoutesInTheList($amount) |
|
103
|
|
|
{ |
|
104
|
|
|
Assert::same( |
|
105
|
|
|
(int) $amount, |
|
106
|
|
|
$this->indexPage->countItems(), |
|
107
|
|
|
'Amount of routes should be equal %s, but was %2$s.' |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @When I delete route :name |
|
113
|
|
|
*/ |
|
114
|
|
|
public function iDeleteRoute($name) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->indexPage->open(); |
|
117
|
|
|
$this->indexPage->deleteResourceOnPage(['name' => $name]); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @Given the route :name should no longer exist in the store |
|
122
|
|
|
*/ |
|
123
|
|
|
public function theRouteShouldNoLongerExistInTheStore($name) |
|
124
|
|
|
{ |
|
125
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @Given /^I want to edit (this route)$/ |
|
130
|
|
|
*/ |
|
131
|
|
|
public function iWantToEditThisRoute(Route $route) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->updatePage->open(['id' => $route->getId()]); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @When I choose :title as its new content |
|
138
|
|
|
*/ |
|
139
|
|
|
public function iChooseNewContent($title) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->updatePage->chooseNewContent($title); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @When I save my changes |
|
146
|
|
|
* @When I try to save my changes |
|
147
|
|
|
*/ |
|
148
|
|
|
public function iSaveMyChanges() |
|
149
|
|
|
{ |
|
150
|
|
|
$this->updatePage->saveChanges(); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @Then /^(this route) should have assigned "([^"]+)" content$/ |
|
155
|
|
|
*/ |
|
156
|
|
|
public function thisRouteShouldHaveAssignedContent(Route $route, $contentTitle) |
|
157
|
|
|
{ |
|
158
|
|
|
if (!$this->indexPage->isOpen()) { |
|
159
|
|
|
$this->indexPage->open(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
Assert::true( |
|
163
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $route->getName(), 'content' => $contentTitle]), |
|
164
|
|
|
sprintf('Cannot find route with name "%s" and content "%s" assigned.', $route->getName(), $contentTitle) |
|
165
|
|
|
); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @Then I should be notified that name is required |
|
170
|
|
|
*/ |
|
171
|
|
|
public function iShouldBeNotifiedThatElementIsRequired() |
|
172
|
|
|
{ |
|
173
|
|
|
Assert::same( |
|
174
|
|
|
$this->createPage->getValidationMessage('name'), |
|
175
|
|
|
'This value should not be blank.' |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @Then the route with content :title should not be added |
|
181
|
|
|
*/ |
|
182
|
|
|
public function theRouteWithContentShouldNotBeAdded($title) |
|
183
|
|
|
{ |
|
184
|
|
|
if (!$this->indexPage->isOpen()) { |
|
185
|
|
|
$this->indexPage->open(); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['content' => $title])); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|