From 463eb9076b7b7ff232fc0f16698b51c1dcf8abab Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 30 Apr 2018 14:38:41 +1200 Subject: [PATCH 1/2] Add Behat feature for viewing a version (History Viewer) --- .travis.yml | 2 +- tests/Behat/features/view-a-version.feature | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be09512d..8c86a0af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ before_script: - export PATH=~/.composer/vendor/bin:$PATH - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - # Install composer +# Install composer - composer validate - if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql 2.0.x-dev; fi - composer require --no-update silverstripe/recipe-testing:^1 silverstripe/recipe-cms 1.2.x-dev diff --git a/tests/Behat/features/view-a-version.feature b/tests/Behat/features/view-a-version.feature index 99b6cd03..6f46feb7 100644 --- a/tests/Behat/features/view-a-version.feature +++ b/tests/Behat/features/view-a-version.feature @@ -19,3 +19,4 @@ Feature: View a version When I click on the first version Then I should see an "#Form_versionForm_Title[readonly]" element And I should see an "#Form_versionForm_URLSegment[readonly]" element + From cbdacedad75eed0908100ae9a56fb1546cea36a9 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 30 Apr 2018 15:52:16 +1200 Subject: [PATCH 2/2] Add behat feature for listing versions (History Viewer) --- .travis.yml | 2 +- tests/Behat/Context/FeatureContext.php | 107 +++++++++++++++++++- tests/Behat/features/list-view.feature | 52 ++++++++++ tests/Behat/features/view-a-version.feature | 8 +- 4 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 tests/Behat/features/list-view.feature diff --git a/.travis.yml b/.travis.yml index 8c86a0af..be09512d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ before_script: - export PATH=~/.composer/vendor/bin:$PATH - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini -# Install composer + # Install composer - composer validate - if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql 2.0.x-dev; fi - composer require --no-update silverstripe/recipe-testing:^1 silverstripe/recipe-cms 1.2.x-dev diff --git a/tests/Behat/Context/FeatureContext.php b/tests/Behat/Context/FeatureContext.php index 2d82d822..c83750f7 100644 --- a/tests/Behat/Context/FeatureContext.php +++ b/tests/Behat/Context/FeatureContext.php @@ -2,6 +2,7 @@ namespace SilverStripe\VersionedAdmin\Tests\Behat\Context; +use Behat\Mink\Element\NodeElement; use SilverStripe\BehatExtension\Context\SilverStripeContext; if (!class_exists(SilverStripeContext::class)) { @@ -21,17 +22,113 @@ public function iShouldSeeAListOfVersions() } /** - * @When I click on the first version + * @Then I should see a list of versions in descending order */ - public function iClickOnTheFirstVersion() + public function iShouldSeeAListOfVersionsInDescendingOrder() { $page = $this->getSession()->getPage(); - $firstVersion = $page->find('css', '.history-viewer .table tbody tr'); - assertNotNull($firstVersion, 'I should see a list of versions'); + $versions = $page->findAll('css', '.history-viewer .table tbody tr td:nth-of-type(1)'); - $firstVersion->click(); + $previous = null; + foreach ($versions as $version) { + /** @var NodeElement $version */ + if ($previous) { + assert($version->getValue() < $previous); + } + $previous = $version->getValue(); + } + } + + /** + * @When I click on the first version + */ + public function iClickOnTheFirstVersion() + { + assertNotNull($this->getLatestVersion(), 'I should see a list of versions'); + $this->getLatestVersion()->click(); // Wait for the form builder to load $this->getSession()->wait(3000); } + + /** + * Example: I should see the "Live" badge + * Example: I should not see the "Live" badge + * + * @Then /^I should (not |)see the "([\w\s]+)" badge$/ + * @param string $negative + * @param string $text + */ + public function iShouldSeeTheBadge($negative, $text) + { + if ($negative) { + $this->assertElementNotOnPage('.history-viewer .badge'); + } else { + $this->assertElementContains('.history-viewer .badge', $text); + } + } + + /** + * Example: I should see "ADMIN User" in the author column in version 1 + * + * @Then I should see :text in the author column in version :versionNumber + */ + public function iShouldSeeInTheAuthorColumn($text, $versionNumber) + { + $version = $this->getSpecificVersion($versionNumber); + $authorColumn = $version->find('css', 'td:nth-of-type(3)'); + + $exists = strpos($authorColumn->getText(), $text) !== false; + assertTrue($exists, 'Author column contains ' . $text); + } + + /** + * Example: I should see "Saved" in the record column in version 1 + * + * @Then I should see :text in the record column in version :versionNumber + */ + public function iShouldSeeInTheRecordColumn($text, $versionNumber) + { + $version = $this->getSpecificVersion($versionNumber); + $recordColumn = $version->find('css', 'td:nth-of-type(2)'); + + $exists = strpos($recordColumn->getText(), $text) !== false; + assertTrue($exists, 'Record column contains ' . $text); + } + + /** + * @Then I should see :text in the version column in version :versionNumber + */ + public function iShouldSeeInTheVersionColumn($text, $versionNumber) + { + $version = $this->getSpecificVersion($versionNumber); + $versionColumn = $version->find('css', 'td'); + + $exists = strpos($versionColumn->getText(), $text) !== false; + assertTrue($exists, 'Version column contains ' . $text); + } + + /** + * Returns the table row that holds information on the most recent version + */ + protected function getLatestVersion() + { + $page = $this->getSession()->getPage(); + return $page->find('css', '.history-viewer .table tbody tr'); + } + + /** + * Returns the table row that holds information on the selected version. + * + * @param int $versionNumber + */ + protected function getSpecificVersion($versionNumber) + { + $versionColumns = $this->getSession()->getPage()->findAll('css', '.history-viewer tbody tr'); + foreach ($versionColumns as $version) { + if (strpos($version->getText(), $versionNumber) !== false) { + return $version; + } + } + } } diff --git a/tests/Behat/features/list-view.feature b/tests/Behat/features/list-view.feature new file mode 100644 index 00000000..e2531ee7 --- /dev/null +++ b/tests/Behat/features/list-view.feature @@ -0,0 +1,52 @@ +@javascript +Feature: View a list of versions + As a cms author + I want to view a list past revisions of a versioned DataObject (incl. pages) + + Background: + # Test date cannot be in the past or the version list numbers won't be descending + Given the current date is "2100-01-01" + Given a "page" "Home" with "Content"="Background" + + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + And I click on "Home" in the tree + + Scenario: A list of versions is displayed + Given I click on "History" in the header tabs + Then I should see a list of versions + + Scenario: List shows the publish state, publish date and the author + Given I should see an edit page form + When I fill in the "Content" HTML field with "

Publish scenario

" + And I press the "Publish" button + Then I should see a "Published 'Home' successfully." notice + # This is a workaround @todo remove when https://github.com/silverstripe/silverstripe-cms/issues/2128 is resolved in framework + And I go to "/admin/pages/history/show/1" + Then I should see a list of versions + And I should see "ADMIN User" in the author column in version 1 + And I should see "Published" in the record column in version 1 + And I should see "01/01/2100" in the record column in version 1 + And I should see the "Live" badge + + Scenario: List shows the draft state, draft date and the author + Given I should see an edit page form + When I fill in the "Content" HTML field with "

Save scenario

" + And I press the "Save" button + Then I should see a "Saved 'Home' successfully." notice + # This is a workaround @todo remove when https://github.com/silverstripe/silverstripe-cms/issues/2128 is resolved in framework + And I go to "/admin/pages/history/show/1" + Then I should see a list of versions + And I should see "ADMIN User" in the author column in version 1 + And I should see "Saved" in the record column in version 1 + And I should see "01/01/2100" in the record column in version 1 + And I should not see the "Live" badge + + Scenario: Revisions are ordered descending by date + Given I should see an edit page form + When I fill in the "Content" HTML field with "

Order scenario

" + And I press the "Publish" button + Then I should see a "Published 'Home' successfully." notice + # This is a workaround @todo remove when https://github.com/silverstripe/silverstripe-cms/issues/2128 is resolved in framework + And I go to "/admin/pages/history/show/1" + Then I should see a list of versions in descending order diff --git a/tests/Behat/features/view-a-version.feature b/tests/Behat/features/view-a-version.feature index 6f46feb7..685a1ee3 100644 --- a/tests/Behat/features/view-a-version.feature +++ b/tests/Behat/features/view-a-version.feature @@ -13,10 +13,14 @@ Feature: View a version Scenario: I can view a selected version of a record When I click on the first version + And I wait for 3 seconds until I see the "#Form_versionForm" element Then I should see "Welcome to my website" - Scenario: The form fields shown are readonly + Scenario: Shows readonly version of all core form fields + Given I click on "History" in the header tabs + Then I should see a list of versions + When I click on the first version + And I wait for 3 seconds until I see the "#Form_versionForm" element Then I should see an "#Form_versionForm_Title[readonly]" element And I should see an "#Form_versionForm_URLSegment[readonly]" element -