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\Route\CreatePageInterface; |
8
|
|
|
use Lakion\SyliusCmsBundle\Tests\Behat\Page\Admin\Route\UpdatePageInterface; |
9
|
|
|
use Lakion\SyliusCmsBundle\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
|
|
View Code Duplication |
public function theRouteShouldAppearInTheStore($name) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
if (!$this->indexPage->isOpen()) { |
93
|
|
|
$this->indexPage->open(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
Assert::true( |
97
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $name]), |
98
|
|
|
sprintf('Could not find route with name "%s"!', $name) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @Then I should see :amount routes in the list |
104
|
|
|
*/ |
105
|
|
|
public function iShouldSeeThatManyRoutesInTheList($amount) |
106
|
|
|
{ |
107
|
|
|
Assert::same( |
108
|
|
|
(int) $amount, |
109
|
|
|
$this->indexPage->countItems(), |
110
|
|
|
'Amount of routes should be equal %s, but was %2$s.' |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @When I delete route :name |
116
|
|
|
*/ |
117
|
|
|
public function iDeleteRoute($name) |
118
|
|
|
{ |
119
|
|
|
$this->indexPage->open(); |
120
|
|
|
$this->indexPage->deleteResourceOnPage(['name' => $name]); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @Given the route :name should no longer exist in the store |
125
|
|
|
*/ |
126
|
|
|
public function theRouteShouldNoLongerExistInTheStore($name) |
127
|
|
|
{ |
128
|
|
|
Assert::false( |
129
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $name]), |
130
|
|
|
sprintf('Route with name "%s" exists, but should not.', $name) |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @Given /^I want to edit (this route)$/ |
136
|
|
|
*/ |
137
|
|
|
public function iWantToEditThisRoute(Route $route) |
138
|
|
|
{ |
139
|
|
|
$this->updatePage->open(['id' => $route->getId()]); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @When I choose :title as its new content |
144
|
|
|
*/ |
145
|
|
|
public function iChooseNewContent($title) |
146
|
|
|
{ |
147
|
|
|
$this->updatePage->chooseNewContent($title); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @When I save my changes |
152
|
|
|
* @When I try to save my changes |
153
|
|
|
*/ |
154
|
|
|
public function iSaveMyChanges() |
155
|
|
|
{ |
156
|
|
|
$this->updatePage->saveChanges(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @Then /^(this route) should have assigned "([^"]+)" content$/ |
161
|
|
|
*/ |
162
|
|
|
public function thisRouteShouldHaveAssignedContent(Route $route, $contentTitle) |
163
|
|
|
{ |
164
|
|
|
if (!$this->indexPage->isOpen()) { |
165
|
|
|
$this->indexPage->open(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
Assert::true( |
169
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $route->getName(), 'content' => $contentTitle]), |
170
|
|
|
sprintf('Cannot find route with name "%s" and content "%s" assigned.', $route->getName(), $contentTitle) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @Then I should be notified that name is required |
176
|
|
|
*/ |
177
|
|
|
public function iShouldBeNotifiedThatElementIsRequired() |
178
|
|
|
{ |
179
|
|
|
Assert::same( |
180
|
|
|
$this->createPage->getValidationMessage('name'), |
181
|
|
|
'This value should not be blank.' |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @Then the route with content :title should not be added |
187
|
|
|
*/ |
188
|
|
View Code Duplication |
public function theRouteWithContentShouldNotBeAdded($title) |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
if (!$this->indexPage->isOpen()) { |
191
|
|
|
$this->indexPage->open(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
Assert::false( |
195
|
|
|
$this->indexPage->isSingleResourceOnPage(['content' => $title]), |
196
|
|
|
sprintf('Found route with content "%s" assigned, but expected not to.', $title) |
197
|
|
|
); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
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.