-
Notifications
You must be signed in to change notification settings - Fork 60
/
ContentViewContext.php
323 lines (278 loc) · 12.6 KB
/
ContentViewContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;
use Behat\Gherkin\Node\TableNode;
use EzSystems\Behat\Core\Environment\EnvironmentConstants;
use EzSystems\Behat\Core\Behat\ArgumentParser;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\Breadcrumb;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\Dialog;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\DraftConflictDialog;
use EzSystems\Behat\Browser\Factory\ElementFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\LanguagePicker;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\LeftMenu;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\RightMenu;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\UniversalDiscoveryWidget;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\ContentItemPage;
use EzSystems\Behat\Browser\Factory\PageObjectFactory;
use PHPUnit\Framework\Assert;
class ContentViewContext extends BusinessContext
{
private $argumentParser;
public function __construct(ArgumentParser $argumentParser)
{
$this->argumentParser = $argumentParser;
}
/**
* @Given I start creating a new content :contentType
*/
public function startCreatingContent(string $contentType): void
{
PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, 'Home')->startCreatingContent($contentType);
}
/**
* @Given I start creating a new user
*/
public function startCreatingUser(): void
{
PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, '')->startCreatingUser();
}
/**
* @Given I start editing the current content
* @Given I start editing the current content in :language language
*/
public function startEditingContent(string $language = null): void
{
$rightMenu = new RightMenu($this->browserContext);
$rightMenu->clickButton('Edit');
$languagePicker = ElementFactory::createElement($this->browserContext, LanguagePicker::ELEMENT_NAME);
if ($languagePicker->isVisible()) {
$availableLanguages = $languagePicker->getLanguages();
Assert::assertGreaterThan(1, count($availableLanguages));
Assert::assertContains($language, $availableLanguages);
$languagePicker->chooseLanguage($language);
}
}
/**
* @Given I open UDW and go to :itemPath
*/
public function iOpenUDWAndGoTo(string $itemPath): void
{
$leftMenu = new LeftMenu($this->browserContext);
$leftMenu->verifyVisibility();
$leftMenu->clickButton('Browse');
$udw = ElementFactory::createElement($this->browserContext, UniversalDiscoveryWidget::ELEMENT_NAME);
$udw->verifyVisibility();
$udw->selectContent($this->argumentParser->replaceRootKeyword($itemPath));
$udw->openPreview();
}
/**
* @Then I (should) see :title title/topic
*/
public function iSeeTitle(string $title): void
{
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, 'Home');
Assert::assertEquals($title, $contentItemPage->getPageTitle());
}
/**
* Check if item has or not sub-item, according to $itemShouldExist param.
*
* @param string $itemName
* @param string $itemType
* @param string $containerName
* @param bool $itemShouldExist
*/
private function verifyItemExistenceInSubItemList(string $itemName, string $itemType, string $containerName, bool $itemShouldExist): void
{
$isItemInTable = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $containerName)
->subItemList->table->isElementInTable($itemName);
$itemShouldExistString = $itemShouldExist ? '' : 'n\'t';
if ($isItemInTable !== $itemShouldExist) {
Assert::fail(sprintf('%s "%s" should%s be on %s Sub-items list', $itemType, $itemName, $itemShouldExistString, $containerName));
}
}
/**
* @Then there's :itemName :itemType on :containerName Sub-items list
*/
public function verifyThereIsItemInSubItemList(string $itemName, string $itemType, string $containerName): void
{
$this->verifyItemExistenceInSubitemList($itemName, $itemType, $containerName, true);
}
/**
* @Then there's no :itemName :itemType on :containerName Sub-items list
*/
public function verifyThereIsNoItemInSubItemList(string $itemName, string $itemType, string $containerName): void
{
$this->verifyItemExistenceInSubitemList($itemName, $itemType, $containerName, false);
}
/**
* @Then there's no :itemName :itemType on Sub-items list of root
*/
public function verifyThereIsNoItemInSubItemListInRoot(string $itemName, string $itemType): void
{
$this->verifyThereIsNoItemInSubItemList($itemName, $itemType, EnvironmentConstants::get('ROOT_CONTENT_NAME'));
}
/**
* @Given I should be on content item page :contentName of type :contentType
* @Given I should be on content item page :contentName of type :contentType in :path
*/
public function verifyImOnContentItemPage(string $contentName, string $contentType, ?string $path = null)
{
$path = !$path ? $contentName : $path . '/' . $contentName;
$path = $this->argumentParser->replaceRootKeyword($path);
$spacedPath = str_replace('/', ' ', $path);
$contentPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $contentName);
$contentPage->verifyIsLoaded();
$contentPage->verifyContentType($contentType);
$breadcrumb = ElementFactory::createElement($this->browserContext, Breadcrumb::ELEMENT_NAME);
Assert::assertEquals($spacedPath, $breadcrumb->getBreadcrumb(), 'Wrong content location');
}
/**
* @Given I should be on content item page :contentName of type :contentType in root path
*/
public function verifyImOnContentItemPageInRoot(string $contentName, string $contentType)
{
$this->verifyImOnContentItemPage($contentName, $contentType, EnvironmentConstants::get('ROOT_CONTENT_NAME'));
}
/**
* @Given I should be on content container page :contentName of type :contentType
* @Given I should be on content container page :contentName of type :contentType in :path
*/
public function verifyImOnContentContainerPage(string $contentName, string $contentType, ?string $path = null)
{
$this->verifyImOnContentItemPage($contentName, $contentType, $path);
PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $contentName)->verifySubItemListVisibility();
}
/**
* @Given I should be on content container page :contentName of type :contentType in root path
*/
public function verifyImOnContentContainerPageInRoot(string $contentName, string $contentType)
{
$this->verifyImOnContentContainerPage($contentName, $contentType, EnvironmentConstants::get('ROOT_CONTENT_NAME'));
}
/**
* @Given I should be on root container page in Content View
*/
public function verifyImOnRootPage()
{
$contentName = EnvironmentConstants::get('ROOT_CONTENT_NAME');
$contentType = EnvironmentConstants::get('ROOT_CONTENT_TYPE');
$this->verifyImOnContentContainerPage($contentName, $contentType);
}
/**
* @Then content attributes equal
*/
public function contentAttributesEqual(TableNode $parameters): void
{
$hash = $parameters->getHash();
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, '');
foreach ($hash as $fieldData) {
$contentItemPage->contentField->verifyFieldHasValue($fieldData['label'], $fieldData);
}
}
/**
* @Then article main content field equals :intro
*/
public function articleMainContentFieldEquals(string $intro): void
{
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, '');
$fieldName = EnvironmentConstants::get('ARTICLE_MAIN_FIELD_NAME');
$contentItemPage->contentField->verifyFieldHasValue($fieldName, ['value' => $intro]);
}
/**
* @When I start creating new draft from draft conflict modal
*/
public function startCreatingNewDraftFromDraftConflictModal(): void
{
$draftConflictModal = ElementFactory::createElement($this->browserContext, DraftConflictDialog::ELEMENT_NAME);
$draftConflictModal->verifyVisibility();
$draftConflictModal->createNewDraft();
}
/**
* @When I start editing draft with ID :draftID from draft conflict modal
*/
public function startEditingDraftFromDraftConflictModal(string $draftID): void
{
$draftConflictModal = ElementFactory::createElement($this->browserContext, DraftConflictDialog::ELEMENT_NAME);
$draftConflictModal->verifyVisibility();
$draftConflictModal->draftConflictTable->clickEditButton($draftID);
}
/**
* @Then going to :path there is no :contentName :contentType on Sub-items list
*/
public function goingToPathTheresNoSubItem(string $path, string $contentName, string $contentType): void
{
$contentPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $contentName);
$contentPage->navigateToPath($path);
$explodedPath = explode('/', $path);
$this->verifyThereIsNoItemInSubItemList($contentName, $contentType, $explodedPath[count($explodedPath) - 1]);
}
/**
* @Then going to root path there is no :contentName :contentType on Sub-items list
*/
public function goingToRootTheresNoSubItem(string $contentName, string $contentType): void
{
$this->goingToPathTheresNoSubItem(EnvironmentConstants::get('ROOT_CONTENT_NAME'), $contentName, $contentType);
}
/**
* @Then going to :path there is a :contentName :contentType on Sub-items list
*/
public function goingToPathTheresSubItem(string $path, string $contentName, string $contentType): void
{
$contentPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $contentName);
$contentPage->navigateToPath($path);
$explodedPath = explode('/', $path);
$pathSize = count($explodedPath);
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $explodedPath[$pathSize - 1]);
if ($contentItemPage->subItemList->canBeSorted()) {
$contentItemPage->subItemList->sortBy('Modified', false);
}
Assert::assertTrue(
$contentItemPage->subItemList->table->isElementInTable($contentName),
sprintf('%s "%s" shouldn\'t be on %s Sub-items list', $contentType, $contentName, $explodedPath[$pathSize - 1])
);
}
/**
* @Then going to root path there is :contentName :contentType on Sub-items list
*/
public function goingToRootTheresSubItem(string $contentName, string $contentType): void
{
$this->goingToPathTheresSubItem(EnvironmentConstants::get('ROOT_CONTENT_NAME'), $contentName, $contentType);
}
/**
* @When I send content to trash
*/
public function iSendContentToTrash(): void
{
$rightMenu = ElementFactory::createElement($this->browserContext, RightMenu::ELEMENT_NAME);
$rightMenu->clickButton('Send to Trash');
$dialog = ElementFactory::createElement($this->browserContext, Dialog::ELEMENT_NAME);
$dialog->confirm();
}
/**
* @Given I go to :tab tab (in Content structure) of item :item
*/
public function iGoToTab($tab, $item): void
{
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $item);
$contentItemPage->switchToTab($tab);
}
/**
* @Given I click on Add Location (button) of item :item
*/
public function iClickAddLocationButton($item): void
{
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $item);
$contentItemPage->addLocation();
}
/**
* @Given I select :location location for item :item
*/
public function iSelectLocationForItem($location, $item): void
{
$contentItemPage = PageObjectFactory::createPage($this->browserContext, ContentItemPage::PAGE_NAME, $item);
$contentItemPage->addContentFromUDW($location);
}
}