|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of monofony. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mobizel |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace App\Behat\Context\Ui\Backend; |
|
15
|
|
|
|
|
16
|
|
|
use App\Behat\Page\Backend\Article\CreatePage; |
|
17
|
|
|
use App\Behat\Page\Backend\Article\IndexPage; |
|
18
|
|
|
use App\Behat\Page\Backend\Article\UpdatePage; |
|
19
|
|
|
use App\Entity\Article; |
|
20
|
|
|
use Behat\Behat\Context\Context; |
|
21
|
|
|
use Webmozart\Assert\Assert; |
|
22
|
|
|
|
|
23
|
|
|
final class ManagingArticlesContext implements Context |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var CreatePage |
|
27
|
|
|
*/ |
|
28
|
|
|
private $createPage; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var IndexPage |
|
32
|
|
|
*/ |
|
33
|
|
|
private $indexPage; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var UpdatePage |
|
37
|
|
|
*/ |
|
38
|
|
|
private $updatePage; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct( |
|
41
|
|
|
CreatePage $createPage, |
|
42
|
|
|
IndexPage $indexPage, |
|
43
|
|
|
UpdatePage $updatePage |
|
44
|
|
|
) { |
|
45
|
|
|
$this->createPage = $createPage; |
|
46
|
|
|
$this->indexPage = $indexPage; |
|
47
|
|
|
$this->updatePage = $updatePage; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @Given I want to create a new article |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iWantToCreateANewArticle() |
|
54
|
|
|
{ |
|
55
|
|
|
|
|
56
|
|
|
$this->createPage->open(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @When I browse articles |
|
61
|
|
|
* @When I want to browse articles |
|
62
|
|
|
*/ |
|
63
|
|
|
public function iWantToBrowseArticles() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->indexPage->open(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @Given I want to modify the :article article |
|
70
|
|
|
*/ |
|
71
|
|
|
public function iWantToModifyAnArticle(Article $article) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->updatePage->open(['id' => $article->getId()]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @When I specify its title as :title |
|
78
|
|
|
* @When I do not specify its title |
|
79
|
|
|
*/ |
|
80
|
|
|
public function iSpecifyItsEmailAs($title = null) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->createPage->specifyTitle($title); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @When I rename it to :title |
|
87
|
|
|
*/ |
|
88
|
|
|
public function iChangeItsTitleAs($title = null) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->updatePage->changeTitle($title); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @When I add it |
|
95
|
|
|
* @When I try to add it |
|
96
|
|
|
*/ |
|
97
|
|
|
public function iAddIt() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->createPage->create(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @When I save my changes |
|
104
|
|
|
*/ |
|
105
|
|
|
public function iSaveMyChanges() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->updatePage->saveChanges(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @When I delete article with title :title |
|
112
|
|
|
*/ |
|
113
|
|
|
public function iDeleteArticleWithTitle($title) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->indexPage->deleteResourceOnPage(['title' => $title]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @When I (also) check the :title article |
|
120
|
|
|
*/ |
|
121
|
|
|
public function iCheckTheArticle(string $title): void |
|
122
|
|
|
{ |
|
123
|
|
|
$this->indexPage->checkResourceOnPage(['title' => $title]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @When I delete them |
|
128
|
|
|
*/ |
|
129
|
|
|
public function iDeleteThem(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->indexPage->bulkDelete(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @Then I should see a single article in the list |
|
136
|
|
|
* @Then /^there should be (\d+) articles in the list$/ |
|
137
|
|
|
*/ |
|
138
|
|
|
public function iShouldSeeArticlesInTheList(int $number = 1): void |
|
139
|
|
|
{ |
|
140
|
|
|
Assert::same($this->indexPage->countItems(), (int) $number); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @Then I should (also )see the article :title in the list |
|
145
|
|
|
* @Then the article :title should appear in the website |
|
146
|
|
|
*/ |
|
147
|
|
|
public function theArticleShouldAppearInTheWebsite($title) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->indexPage->open(); |
|
150
|
|
|
Assert::true($this->indexPage->isSingleResourceOnPage(['title' => $title])); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @Then there should not be :title article anymore |
|
155
|
|
|
*/ |
|
156
|
|
|
public function thereShouldBeNoAnymore($title) |
|
157
|
|
|
{ |
|
158
|
|
|
Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title])); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @Then I should be notified that the title is required |
|
163
|
|
|
*/ |
|
164
|
|
|
public function iShouldBeNotifiedThatTitleIsRequired() |
|
165
|
|
|
{ |
|
166
|
|
|
Assert::same($this->createPage->getValidationMessage('title'), 'This value should not be blank.'); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @Then this article should not be added |
|
171
|
|
|
*/ |
|
172
|
|
|
public function thisArticleShouldNotBeAdded() |
|
173
|
|
|
{ |
|
174
|
|
|
$this->indexPage->open(); |
|
175
|
|
|
Assert::same($this->indexPage->countItems(), 0); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|