From 8f474ce69e1f97bdd9182805fbf4aa10a82e6733 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 11 Nov 2021 13:02:22 +1300 Subject: [PATCH] MNT Update behat tests --- .travis.yml | 1 + behat.yml | 28 +++++------ composer.json | 5 +- tests/behat/features/content-reviews.feature | 53 ++++++++++++++++++++ tests/behat/files/blank.txt | 0 tests/behat/src/FeatureContext.php | 29 +++++++++++ tests/behat/src/FixtureContext.php | 9 ++++ 7 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 tests/behat/features/content-reviews.feature create mode 100644 tests/behat/files/blank.txt create mode 100644 tests/behat/src/FeatureContext.php create mode 100644 tests/behat/src/FixtureContext.php diff --git a/.travis.yml b/.travis.yml index a371558..3f97107 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,4 @@ import: env: global: - BEHAT_SUITE="contentreview" + - REQUIRE_EXTRA="symbiote/silverstripe-queuedjobs:^4" diff --git a/behat.yml b/behat.yml index 86e1026..6afcfff 100644 --- a/behat.yml +++ b/behat.yml @@ -2,18 +2,19 @@ default: suites: contentreview: paths: - - '%paths.modules.contentreview%/tests/behat/features' + - "%paths.modules.contentreview%/tests/behat/features" contexts: - - SilverStripe\Framework\Tests\Behaviour\FeatureContext - - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext - - SilverStripe\Framework\Tests\Behaviour\CmsUiContext + - SilverStripe\Admin\Tests\Behat\Context\AdminContext - SilverStripe\BehatExtension\Context\BasicContext - SilverStripe\BehatExtension\Context\EmailContext - - SilverStripe\CMS\Tests\Behaviour\LoginContext - - SilverStripe\CMS\Tests\Behaviour\ThemeContext - - SilverStripe\CMS\Tests\Behaviour\FixtureContext: - # Note: double indent for args is intentional - - '%paths.modules.contentreview%/tests/behat/features/files/' + - SilverStripe\BehatExtension\Context\LoginContext + - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext + - SilverStripe\Framework\Tests\Behaviour\CmsUiContext + - SilverStripe\ContentReview\Tests\Behat\Context\FeatureContext + - SilverStripe\ContentReview\Tests\Behat\Context\FixtureContext + - + SilverStripe\ContentReview\Tests\Behat\Context\FixtureContext: + - "%paths.modules.contentreview%/tests/behat/files/" extensions: SilverStripe\BehatExtension\MinkExtension: @@ -21,9 +22,8 @@ default: javascript_session: facebook_web_driver facebook_web_driver: browser: chrome - wd_host: "http://127.0.0.1:9515" #chromedriver port - browser_name: chrome - + wd_host: "http://127.0.0.1:9515" + SilverStripe\BehatExtension\Extension: - screenshot_path: '%paths.base%/artifacts/screenshots' - bootstrap_file: "vendor/silverstripe/cms/tests/behat/serve-bootstrap.php" + screenshot_path: "%paths.base%/artifacts/screenshots" + bootstrap_file: vendor/silverstripe/framework/tests/behat/serve-bootstrap.php diff --git a/composer.json b/composer.json index b86dc28..8987b3a 100644 --- a/composer.json +++ b/composer.json @@ -42,9 +42,10 @@ "autoload": { "psr-4": { "SilverStripe\\ContentReview\\": "src/", - "SilverStripe\\ContentReview\\Tests\\": "tests/php/" + "SilverStripe\\ContentReview\\Tests\\": "tests/php/", + "SilverStripe\\ContentReview\\Tests\\Behat\\Context\\": "tests/behat/src/" } }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/tests/behat/features/content-reviews.feature b/tests/behat/features/content-reviews.feature new file mode 100644 index 0000000..f6b2a24 --- /dev/null +++ b/tests/behat/features/content-reviews.feature @@ -0,0 +1,53 @@ +Feature: Set up reviews + As a CMS user + I can set up content reviews for my content + In order to ensure my content gets reviewed regularly + + Background: + # Note: the review date is deliberately in the past + Given a "page" "My page" with "Content"="

Welcome

", "NextReviewDate"="01/01/2017", "ReviewPeriodDays"="1" + And the "group" "EDITOR group" has permissions "CMS_ACCESS_LeftAndMain" and "FILE_EDIT_ALL" + And the "group" "FILEONLY group" has permissions "FILE_EDIT_ALL" + And a "member" "Ed" belonging to "EDITOR group" with "Email"="ed@example.com" + And a "member" "Phil" belonging to "FILEONLY group" with "Email"="phil@example.com" + And I am logged in with "ADMIN" permissions + And I go to "admin/pages" + And I click on "My page" in the tree + And I click the "Settings" CMS tab + And I click the "Content review" CMS tab + + Scenario: I can set content reviewers to users and groups who can edit pages + When I select "Custom settings" from "Options" input group + And I wait for 1 second + + # Test adding individual member based on them having access to the Pages section fo the CMS + Then the "#Form_EditForm_OwnerUsers" select element should have an option with an "Ed" label + And the "#Form_EditForm_OwnerUsers" select element should not have an option with a "Phil" label + + # Test adding groups + Then the "#Form_EditForm_OwnerGroups" select element should have an option with an "EDITOR group" label + + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save" button + + Scenario: There is an alert icon when a content review is overdue + When I select "Custom settings" from "Options" input group + And I wait for 1 second + Then I should not see the ".content-review__button" element + When I select "ADMIN group" from "Groups" + # Set a date in the past + And I set a content review date of "2020-01-01" + And I press the "Save" button + Then I should see the ".content-review__button" element + When I click on the ".content-review__button" element + Then I should see the ".modal" element + And I should see "Mark as reviewed" + + # Fill in a review + When I fill in "Form_EditForm_ReviewContent_Review" with "My review" + And I press "Mark as reviewed" + And I wait for 1 second + Then I should see "Review successfully added" + When I click on the ".close" element + And I press the "Save" button + Then I should see "My review" diff --git a/tests/behat/files/blank.txt b/tests/behat/files/blank.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/behat/src/FeatureContext.php b/tests/behat/src/FeatureContext.php new file mode 100644 index 0000000..19df65e --- /dev/null +++ b/tests/behat/src/FeatureContext.php @@ -0,0 +1,29 @@ + option').forEach(function(option) { + if (option.innerHTML == '$label') { + hasLabel = 1; + } + }); + return hasLabel; +JS; + return $this->getSession()->evaluateScript($js) == $n; + } +} diff --git a/tests/behat/src/FixtureContext.php b/tests/behat/src/FixtureContext.php new file mode 100644 index 0000000..3d34479 --- /dev/null +++ b/tests/behat/src/FixtureContext.php @@ -0,0 +1,9 @@ +