diff --git a/features/standard/ContentManagement.feature b/features/standard/ContentManagement.feature index b0cc11610f..eca522648f 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" + When 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" + Then 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" + When 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" + Then 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/bundle/Resources/config/services/test/components.yaml b/src/bundle/Resources/config/services/test/components.yaml index 6763d53a3a..489fb63f0e 100644 --- a/src/bundle/Resources/config/services/test/components.yaml +++ b/src/bundle/Resources/config/services/test/components.yaml @@ -61,3 +61,5 @@ services: Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~ Ibexa\AdminUi\Behat\Component\TrashSearch: ~ + + Ibexa\AdminUi\Behat\Component\CancelContentDialog: ~ diff --git a/src/lib/Behat/BrowserContext/ContentViewContext.php b/src/lib/Behat/BrowserContext/ContentViewContext.php index 609fa9b2b4..8720589eff 100644 --- a/src/lib/Behat/BrowserContext/ContentViewContext.php +++ b/src/lib/Behat/BrowserContext/ContentViewContext.php @@ -177,4 +177,46 @@ public function iShouldSeeAlertAppears(string $alertMessage): void $this->contentViewPage->verifyIsLoaded(); $this->contentViewPage->verifyMessage($alertMessage); } + + /** + * @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/Component/CancelContentDialog.php b/src/lib/Behat/Component/CancelContentDialog.php new file mode 100644 index 0000000000..a482fa86a9 --- /dev/null +++ b/src/lib/Behat/Component/CancelContentDialog.php @@ -0,0 +1,30 @@ +getHTMLPage() + ->findAll($this->getLocator('confirmCancelButton')) + ->getByCriterion(new ElementTextCriterion($cancelScheduledHidingButton)) + ->click(); + } + + public function specifyLocators(): array + { + return array_merge(parent::specifyLocators(), [ + new VisibleCSSLocator('confirmCancelButton', '#review-content-modal .ibexa-btn'), + ]); + } +} diff --git a/src/lib/Behat/Page/ContentViewPage.php b/src/lib/Behat/Page/ContentViewPage.php index 5c3aa4a1aa..ef4a19a737 100644 --- a/src/lib/Behat/Page/ContentViewPage.php +++ b/src/lib/Behat/Page/ContentViewPage.php @@ -10,6 +10,7 @@ use Behat\Mink\Session; use Ibexa\AdminUi\Behat\Component\Breadcrumb; +use Ibexa\AdminUi\Behat\Component\CancelContentDialog; use Ibexa\AdminUi\Behat\Component\ContentActionsMenu; use Ibexa\AdminUi\Behat\Component\ContentItemAdminPreview; use Ibexa\AdminUi\Behat\Component\ContentTypePicker; @@ -22,6 +23,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; @@ -31,6 +33,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 { @@ -85,6 +89,8 @@ class ContentViewPage extends Page private DeleteContentDialog $deleteContentDialog; + private ?CancelContentDialog $cancelContentDialog; + public function __construct( Session $session, Router $router, @@ -101,7 +107,8 @@ public function __construct( UniversalDiscoveryWidget $universalDiscoveryWidget, IbexaDropdown $ibexaDropdown, UpperMenu $upperMenu, - DeleteContentDialog $deleteContentDialog + DeleteContentDialog $deleteContentDialog, + ?CancelContentDialog $cancelContentDialog = null ) { parent::__construct($session, $router); $this->contentActionsMenu = $contentActionsMenu; @@ -118,6 +125,7 @@ public function __construct( $this->ibexaDropdown = $ibexaDropdown; $this->upperMenu = $upperMenu; $this->deleteContentDialog = $deleteContentDialog; + $this->cancelContentDialog = $cancelContentDialog; } public function startCreatingContent(string $contentTypeName, ?string $language = null) @@ -309,6 +317,8 @@ protected function specifyLocators(): array new VisibleCSSLocator('moreTab', '.ibexa-tabs__tab--more'), new VisibleCSSLocator('popupMenuItem', '.ibexa-popup-menu__item .ibexa-popup-menu__item-content'), new VisibleCSSLocator('alertTitle', '.ibexa-alert__title'), + new VisibleCSSLocator('selectHideMode', '.form-check .ibexa-input--radio'), + new VisibleCSSLocator('cancelScheduleButton', '.ibexa-btn--schedule-hide-cancel'), ]; } @@ -356,4 +366,44 @@ 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(); + if ($this->cancelContentDialog !== null) { + $this->cancelContentDialog->confirmCanceling('Cancel scheduled hiding'); + } + } }