Skip to content

Commit 021ad26

Browse files
authored
IBX-10333: [Behat] Added scenario for hide later coverage (#1731)
* IBX-10333 Added scenario for hide later coverage * IBX-10333 Removed OSS from hide later scenario * IBX-10333 Added scenario for canceling the schedule for hiding later content. * Fixes after review * Restored some parts of code * Removed unused component * Fix line * Fix line
1 parent 4d4562a commit 021ad26

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

features/standard/ContentManagement.feature

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,38 @@ Scenario: Content can be copied
133133
When I perform the "Reveal" action
134134
And I should be on Content view Page for "ContentManagement/TestArticleToHide"
135135
Then success notification that "Content item 'TestArticleToHide' revealed." appears
136+
137+
@IbexaHeadless @IbexaExperience @IbexaCommerce
138+
Scenario: Content can be hidden later
139+
Given a "folder" Content item named "ContentManagement" exists in root
140+
| name | short_name |
141+
| ContentManagement | ContentManagement |
142+
And a "article" Content item named "TestArticleToHideLater" exists in "ContentManagement"
143+
| title | short_title | intro |
144+
| TestArticleToHideLater | TestArticleToHideLater | TestArticleIntro |
145+
And I'm on Content view Page for "ContentManagement/TestArticleToHideLater"
146+
And I perform the "Hide" action
147+
And I select hide "later" for field options
148+
And I perform the "Confirm" action
149+
And I should be on Content view Page for "ContentManagement/TestArticleToHideLater"
150+
And I should see the alert contains "This Content item will be hidden and won't be publicly available after" appear
151+
When I run the scheduled jobs
152+
And I clear the behat cache directory
153+
Then I should see the alert "This Content item or its Location is hidden." appear
154+
155+
@IbexaHeadless @IbexaExperience @IbexaCommerce
156+
Scenario: Content hide later can be cancelled
157+
Given a "folder" Content item named "ContentManagement" exists in root
158+
| name | short_name |
159+
| ContentManagement | ContentManagement |
160+
And a "article" Content item named "TestArticleToHideLater" exists in "ContentManagement"
161+
| title | short_title | intro |
162+
| TestArticleToCancelHideLater | TestArticleToCancelHideLater | TestArticleIntro |
163+
And I'm on Content view Page for "ContentManagement/TestArticleToCancelHideLater"
164+
And I perform the "Hide" action
165+
And I select hide "later" for field options
166+
And I perform the "Confirm" action
167+
And I should be on Content view Page for "ContentManagement/TestArticleToCancelHideLater"
168+
And I should see the alert contains "This Content item will be hidden and won't be publicly available after" appear
169+
When I cancel scheduled hiding of the content item
170+
Then I should see the alert "Canceled scheduled hiding of Content item 'TestArticleToCancelHideLater'." appear

src/lib/Behat/BrowserContext/ContentViewContext.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,46 @@ public function verifyUrlAliasExists(string $path, string $type): void
197197
sprintf('Url alias "%s" with type "%s" not found', $path, $type)
198198
);
199199
}
200+
201+
/**
202+
* @Given I select hide :hideOption for field options
203+
*/
204+
public function iSelectForFieldOptions(string $hideOption): void
205+
{
206+
$this->contentViewPage->verifyIsLoaded();
207+
$this->contentViewPage->selectHideOption($hideOption);
208+
}
209+
210+
/**
211+
* @Then I should see the alert contains :alertMessage appear
212+
*/
213+
public function iShouldSeeTheAlertContainsAppear(string $alertMessage): void
214+
{
215+
$this->contentViewPage->verifyIsLoaded();
216+
$this->contentViewPage->verifyMessageContains($alertMessage);
217+
}
218+
219+
/**
220+
* @When I run the scheduled jobs
221+
*/
222+
public function iRunTheScheduledJobs(): void
223+
{
224+
$this->contentViewPage->runScheduledJobs();
225+
}
226+
227+
/**
228+
* @When I clear the behat cache directory
229+
*/
230+
public function iClearTheBehatCacheDirectory(): void
231+
{
232+
$this->contentViewPage->clearBehatCacheDirectory();
233+
}
234+
235+
/**
236+
* @When I cancel scheduled hiding of the content item
237+
*/
238+
public function iCancelScheduledHidingOfTheContentItem(): void
239+
{
240+
$this->contentViewPage->cancelScheduledHiding();
241+
}
200242
}

src/lib/Behat/Page/ContentViewPage.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget;
2525
use Ibexa\AdminUi\Behat\Component\UpperMenu;
2626
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
27+
use Ibexa\Behat\Browser\Element\Criterion\ElementAttributeCriterion;
2728
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
2829
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
2930
use Ibexa\Behat\Browser\Page\Page;
@@ -33,6 +34,8 @@
3334
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
3435
use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias;
3536
use PHPUnit\Framework\Assert;
37+
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
38+
use Symfony\Component\Filesystem\Filesystem;
3639

3740
class ContentViewPage extends Page
3841
{
@@ -337,6 +340,8 @@ protected function specifyLocators(): array
337340
new VisibleCSSLocator('addUrlAliasButton', '#ibexa-tab-location-view-urls [data-bs-target="#ibexa-modal--custom-url-alias"]'),
338341
new VisibleCSSLocator('customUrlAliasesTable', '#ibexa-tab-location-view-urls .ibexa-table'),
339342
new VisibleCSSLocator('alertTitle', '.ibexa-alert__title'),
343+
new VisibleCSSLocator('selectHideMode', '.form-check .ibexa-input--radio'),
344+
new VisibleCSSLocator('cancelScheduleButton', '.ibexa-btn--schedule-hide-cancel'),
340345
];
341346
}
342347

@@ -384,4 +389,42 @@ public function verifyMessage(string $expectedMessage): void
384389
{
385390
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('alertTitle'))->assert()->textEquals($expectedMessage);
386391
}
392+
393+
public function selectHideOption(string $viewMode): void
394+
{
395+
$this->getHTMLPage()
396+
->findAll($this->getLocator('selectHideMode'))
397+
->getByCriterion(new ElementAttributeCriterion('value', $viewMode))->click();
398+
}
399+
400+
public function verifyMessageContains(string $alertMessage): void
401+
{
402+
$this->getHTMLPage()->find($this->getLocator('alertTitle'))->assert()->textContains($alertMessage);
403+
}
404+
405+
public function runScheduledJobs(): void
406+
{
407+
shell_exec('bin/console ibexa:scheduled:run');
408+
}
409+
410+
public function clearBehatCacheDirectory(): void
411+
{
412+
$filesystem = new Filesystem();
413+
$cacheDir = getcwd() . \DIRECTORY_SEPARATOR . 'var' . \DIRECTORY_SEPARATOR . 'cache';
414+
415+
try {
416+
$filesystem->remove($cacheDir);
417+
$this->getHTMLPage()->setTimeout(5);
418+
$this->getSession()->reload();
419+
} catch (IOExceptionInterface $exception) {
420+
throw new \Exception('Error while clearing cache: ' . $exception->getMessage());
421+
}
422+
}
423+
424+
public function cancelScheduledHiding(): void
425+
{
426+
$this->getHTMLPage()->find($this->getLocator('cancelScheduleButton'))->click();
427+
$this->dialog->verifyIsLoaded();
428+
$this->dialog->confirm();
429+
}
387430
}

0 commit comments

Comments
 (0)