diff --git a/features/standard/ContentManagement.feature b/features/standard/ContentManagement.feature index b0cc11610f..a616b92c40 100644 --- a/features/standard/ContentManagement.feature +++ b/features/standard/ContentManagement.feature @@ -133,3 +133,38 @@ Scenario: Content can be copied When I perform the "Reveal" action And I should be on Content view Page for "ContentManagement/TestArticleToHide" Then success notification that "Content item 'TestArticleToHide' revealed." appears + + @IbexaHeadless @IbexaExperience @IbexaCommerce + Scenario: Content can be hidden later + Given a "folder" Content item named "ContentManagement" exists in root + | name | short_name | + | ContentManagement | ContentManagement | + And a "article" Content item named "TestArticleToHideLater" exists in "ContentManagement" + | title | short_title | intro | + | TestArticleToHideLater | TestArticleToHideLater | TestArticleIntro | + And I'm on Content view Page for "ContentManagement/TestArticleToHideLater" + And I perform the "Hide" action + And I select hide "later" for field options + And I perform the "Confirm" action + And I should be on Content view Page for "ContentManagement/TestArticleToHideLater" + And I should see the alert contains "This Content item will be hidden and won't be publicly available after" appear + When I run the scheduled jobs + And I clear the behat cache directory + Then I should see the alert "This Content item or its Location is hidden." appear + + @IbexaHeadless @IbexaExperience @IbexaCommerce + Scenario: Content hide later can be cancelled + Given a "folder" Content item named "ContentManagement" exists in root + | name | short_name | + | ContentManagement | ContentManagement | + And a "article" Content item named "TestArticleToHideLater" exists in "ContentManagement" + | title | short_title | intro | + | TestArticleToCancelHideLater | TestArticleToCancelHideLater | TestArticleIntro | + And I'm on Content view Page for "ContentManagement/TestArticleToCancelHideLater" + And I perform the "Hide" action + And I select hide "later" for field options + And I perform the "Confirm" action + And I should be on Content view Page for "ContentManagement/TestArticleToCancelHideLater" + And I should see the alert contains "This Content item will be hidden and won't be publicly available after" appear + When I cancel scheduled hiding of the content item + Then I should see the alert "Canceled scheduled hiding of Content item 'TestArticleToCancelHideLater'." appear diff --git a/src/lib/Behat/BrowserContext/ContentViewContext.php b/src/lib/Behat/BrowserContext/ContentViewContext.php index df5d09b9ea..ee22d0c024 100644 --- a/src/lib/Behat/BrowserContext/ContentViewContext.php +++ b/src/lib/Behat/BrowserContext/ContentViewContext.php @@ -197,4 +197,46 @@ public function verifyUrlAliasExists(string $path, string $type): void sprintf('Url alias "%s" with type "%s" not found', $path, $type) ); } + + /** + * @Given I select hide :hideOption for field options + */ + public function iSelectForFieldOptions(string $hideOption): void + { + $this->contentViewPage->verifyIsLoaded(); + $this->contentViewPage->selectHideOption($hideOption); + } + + /** + * @Then I should see the alert contains :alertMessage appear + */ + public function iShouldSeeTheAlertContainsAppear(string $alertMessage): void + { + $this->contentViewPage->verifyIsLoaded(); + $this->contentViewPage->verifyMessageContains($alertMessage); + } + + /** + * @When I run the scheduled jobs + */ + public function iRunTheScheduledJobs(): void + { + $this->contentViewPage->runScheduledJobs(); + } + + /** + * @When I clear the behat cache directory + */ + public function iClearTheBehatCacheDirectory(): void + { + $this->contentViewPage->clearBehatCacheDirectory(); + } + + /** + * @When I cancel scheduled hiding of the content item + */ + public function iCancelScheduledHidingOfTheContentItem(): void + { + $this->contentViewPage->cancelScheduledHiding(); + } } diff --git a/src/lib/Behat/Page/ContentViewPage.php b/src/lib/Behat/Page/ContentViewPage.php index 64a78ee31a..bc0fb416d1 100644 --- a/src/lib/Behat/Page/ContentViewPage.php +++ b/src/lib/Behat/Page/ContentViewPage.php @@ -24,6 +24,7 @@ use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget; use Ibexa\AdminUi\Behat\Component\UpperMenu; use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition; +use Ibexa\Behat\Browser\Element\Criterion\ElementAttributeCriterion; use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; use Ibexa\Behat\Browser\Page\Page; @@ -33,6 +34,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias; use PHPUnit\Framework\Assert; +use Symfony\Component\Filesystem\Exception\IOExceptionInterface; +use Symfony\Component\Filesystem\Filesystem; class ContentViewPage extends Page { @@ -337,6 +340,8 @@ protected function specifyLocators(): array new VisibleCSSLocator('addUrlAliasButton', '#ibexa-tab-location-view-urls [data-bs-target="#ibexa-modal--custom-url-alias"]'), new VisibleCSSLocator('customUrlAliasesTable', '#ibexa-tab-location-view-urls .ibexa-table'), new VisibleCSSLocator('alertTitle', '.ibexa-alert__title'), + new VisibleCSSLocator('selectHideMode', '.form-check .ibexa-input--radio'), + new VisibleCSSLocator('cancelScheduleButton', '.ibexa-btn--schedule-hide-cancel'), ]; } @@ -384,4 +389,42 @@ public function verifyMessage(string $expectedMessage): void { $this->getHTMLPage()->setTimeout(3)->find($this->getLocator('alertTitle'))->assert()->textEquals($expectedMessage); } + + public function selectHideOption(string $viewMode): void + { + $this->getHTMLPage() + ->findAll($this->getLocator('selectHideMode')) + ->getByCriterion(new ElementAttributeCriterion('value', $viewMode))->click(); + } + + public function verifyMessageContains(string $alertMessage): void + { + $this->getHTMLPage()->find($this->getLocator('alertTitle'))->assert()->textContains($alertMessage); + } + + public function runScheduledJobs(): void + { + shell_exec('bin/console ibexa:scheduled:run'); + } + + public function clearBehatCacheDirectory(): void + { + $filesystem = new Filesystem(); + $cacheDir = getcwd() . \DIRECTORY_SEPARATOR . 'var' . \DIRECTORY_SEPARATOR . 'cache'; + + try { + $filesystem->remove($cacheDir); + $this->getHTMLPage()->setTimeout(5); + $this->getSession()->reload(); + } catch (IOExceptionInterface $exception) { + throw new \Exception('Error while clearing cache: ' . $exception->getMessage()); + } + } + + public function cancelScheduledHiding(): void + { + $this->getHTMLPage()->find($this->getLocator('cancelScheduleButton'))->click(); + $this->dialog->verifyIsLoaded(); + $this->dialog->confirm(); + } }