diff --git a/tests/behat/features/create-a-page.feature b/tests/behat/features/create-a-page.feature index 1a689aa6..e8f8ae74 100644 --- a/tests/behat/features/create-a-page.feature +++ b/tests/behat/features/create-a-page.feature @@ -5,6 +5,7 @@ Feature: Create a page Background: Given a "page" "MyPage" + And a "virtual page" "MyVirtualPage" And a "group" "AUTHOR group" has permissions "Access to 'Pages' section" And I am logged in with "ADMIN" permissions @@ -25,8 +26,15 @@ Feature: Create a page And I should see a "Add new" button in CMS Content Toolbar When I press the "Add new" button And I select the "Under another page" radio button - And I select "MyPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown + # Virtual page doesn't allow children, page radio button below should be disabled + And I select "MyVirtualPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown + And I wait for 2 seconds + Then I should see a "#Form_AddForm_PageType_Page[disabled]" element + # Normal pages allows children, page radio button below should not be disabled + When I select "MyPage" in the "#Form_AddForm_ParentID_Holder" tree dropdown + And I wait for 2 seconds And I select the "Page" radio button + Then I should not see a "#Form_AddForm_PageType_Page[disabled]" element And I press the "Create" button Then I should see an edit page form diff --git a/tests/behat/features/duplicate-a-page.feature b/tests/behat/features/duplicate-a-page.feature index bed32134..07cc477b 100644 --- a/tests/behat/features/duplicate-a-page.feature +++ b/tests/behat/features/duplicate-a-page.feature @@ -22,3 +22,6 @@ Feature: Duplicate a page And I press the "Publish" button Then I should see "Page1" in the tree And I should see "Duplicate Page" in the tree + When I follow "Duplicate Page" + Then I should see "Page1a" + And I should see "Page1b" diff --git a/tests/behat/features/edit-a-page.feature b/tests/behat/features/edit-a-page.feature index 5c359685..90ec8a09 100644 --- a/tests/behat/features/edit-a-page.feature +++ b/tests/behat/features/edit-a-page.feature @@ -4,8 +4,10 @@ Feature: Edit a page So that I correct errors and provide new information Background: - Given a "page" "About Us" - Given I am logged in with "ADMIN" permissions + Given a "page" "About Us" has the "Content" "

My content

" + And a "image" "assets/file1.jpg" + #And a file "assets/file1.jpg" with changes "image"="assets/folder1/file2.jpg" and "page"="About Us" + And I am logged in with "ADMIN" permissions And I go to "/admin/pages" Then I should see "About Us" in the tree @@ -38,3 +40,88 @@ Feature: Edit a page When I click on "Settings" in the header tabs Then the "Settings" header tab should be active And the "Content" header tab should not be active + + Scenario: Frontend changes + When I click on "About Us" in the tree + + # Change URL segment + And I press the "Edit" button + Then the rendered HTML should contain "/about-us" + And I fill in "Form_EditForm_URLSegment" with "about-modified-us" + And I press the "OK" button + Then the rendered HTML should contain "/about-modified-us" + + # Add metadata + When I click on the "#ui-accordion-Form_EditForm_Metadata-header-0" element + And I wait for 1 second + And I fill in "Meta Description" with "MyMetaDesc" + + # Modified content is not displayed on the live site + When I press the "Save" button + And I go to "/about-modified-us?stage=Stage" + Then I should see "About Us" + And I go to "/about-modified-us" + Then I should not see "About Us" + + # Assert URL segment + metadata on frontend + When I go to "/admin/pages" + And I click on "About Us" in the tree + And I press the "Publish" button + And I go to "/about-modified-us" + Then I should see "About Us" + And the rendered HTML should contain "" + # media embed + Then the rendered HTML should contain "src=\"https://www.youtube.com/embed/ScMzIvxBSi4?feature=oembed\"" + + Scenario: Change page type + When I click on "About Us" in the tree + And I click the "Settings" CMS tab + And I select "Virtual Page" from the "#Form_EditForm_ClassName" field with javascript + And I press the "Save" button + Then I should see "Please choose a linked page in the main content fields in order to publish" + + Scenario: Change permission levels for who can view and edit the page, at an individual page level + When I click on "About Us" in the tree + And I click the "Settings" CMS tab + And I select the "Form_EditForm_CanViewType_LoggedInUsers" radio button + And I press the "Publish" button + + # Logout and assert frontend not visible to not-logged-in users + And I go to "/Security/login" + And I press the "Log in as someone else" button + And I go to "/about-us" + Then I should not see "About us" diff --git a/tests/behat/features/sitetree.feature b/tests/behat/features/sitetree.feature new file mode 100644 index 00000000..0bc356a6 --- /dev/null +++ b/tests/behat/features/sitetree.feature @@ -0,0 +1,74 @@ +Feature: Sitetree + As an author + I want to operate the sitetree + So that I can operate my website + + Background: + Given the "group" "EDITOR group" has permissions "CMS_ACCESS_LeftAndMain" and "SITETREE_REORGANISE" + And I am logged in with "EDITOR" permissions + And a "page" "One" + And a "page" "Two" + And a "page" "Three" + And I go to "/admin/pages" + + # @modal is required to use "I confirm the dialog" + @modal + Scenario: Operation sitetree + + Then the site tree order should be "--One,--Two,--Three" + And I should not see a ".status-modified" element + + # Drag and drop to reorder pages + When I drag the "#record-1 > a .text" element to the "#record-3 > a .text" element + And I wait for 3 seconds + Then the site tree order should be "--Two,--One,--Three" + And I should see a ".status-modified" element + When I click on the ".toast__close" element + + # Drag and drop change nesting levels for pages + When I drag the "#record-2 > a .text" element to the "#record-1 > a .text" element + And I wait for 3 seconds + Then the site tree order should be "--One,---Two,--Three" + When I click on the ".toast__close" element + + # Publish pages in a batch + When I press the "Batch actions" button + When I click on the "#record-1 .jstree-checkbox" element + And I click on the "#record-2 .jstree-checkbox" element + And I click on the "#record-3 .jstree-checkbox" element + And I select "Publish" from the "Form_BatchActionsForm_Action" field with javascript + And I click on the "#Form_BatchActionsForm_action_submit" element + And I confirm the dialog + Then I should see a "Published 3 pages" success toast + When I click on the ".toast__close" element + # Wait a little time to ensure the last toast is cleared + And I wait for 2 seconds + + # Unpublish pages in a batch + When I click on the "#record-2 .jstree-checkbox" element + And I select "Unpublish" from the "Form_BatchActionsForm_Action" field with javascript + And I click on the "#Form_BatchActionsForm_action_submit" element + And I confirm the dialog + Then I should see a "Unpublished 1 pages" success toast + When I click on the ".toast__close" element + And I wait for 2 seconds + + # Unpublish and archive pages in a batch + When I click on the "#record-3 .jstree-checkbox" element + And I select "Unpublish and archive" from the "Form_BatchActionsForm_Action" field with javascript + And I click on the "#Form_BatchActionsForm_action_submit" element + # Surprisingly unpublish and archive doesn't have a dialog + # And I confirm the dialog + # Assertion does not work for some reason despite screenshot showing the toast message + # Then I should see a "Deleted 1 pages from draft and live, and sent them to the archive" success toast + When I go to "/admin/pages" + Then I should not see "Three" + + # Toggle list and tree views + Then I should not see a "#Form_ListViewForm_Page" element + When I click on the "[data-view='listview']" element + And I wait for 5 seconds + Then I should see a "#Form_ListViewForm_Page" element + When I click on the "[data-view='treeview']" element + And I wait for 5 seconds + Then I should not see a "#Form_ListViewForm_Page" element diff --git a/tests/behat/src/FixtureContext.php b/tests/behat/src/FixtureContext.php index 93aa0476..ba6c59db 100644 --- a/tests/behat/src/FixtureContext.php +++ b/tests/behat/src/FixtureContext.php @@ -81,6 +81,10 @@ class FixtureContext extends BehatFixtureContext $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); } + // These functions should be in a FeatureContext, however framework FeatureContext is already + // loaded and adding another FeatureContext within CMS that extends SilverStripeContext will + // expose duplicate functions to behat e.g. FillField + /** * @When /^I see the "([^"]+)" element$/ * @param $selector @@ -113,4 +117,42 @@ class FixtureContext extends BehatFixtureContext Assert::assertNotNull($radioButton); Assert::assertEquals($value, $radioButton->getAttribute($attribute)); } + + /** + * Assumes you've just opened the Insert link menu, e.g. + * I click on the "div[aria-label='Insert link [Ctrl+K]'] button" element + * + * @When /^I select "(.+?)" from the TinyMCE menu with javascript$/ + * @param string $label + */ + public function iSelectFromTheTinyMceMenu($label) + { + // :visible and :contains are jQuery css selectors + $js = <<getMainContext()->getSession()->executeScript($js); + } + + /** + * e.g. --PageOne,--PageTwo,---PageTwoChild,--PageThree + * + * @Then /^the site tree order should be "(.+?)"$/ + * @param string $label + */ + public function theSiteTreeOrderShouldBe($expected) + { + $js = << { + let d = ''; + jQuery(el).parents('li').each(() => d += '-'); + return d + jQuery(el).html(); + }) + .get() + .join() +JS; + $actual = $this->getMainContext()->getSession()->evaluateScript($js); + Assert::assertEquals($expected, $actual); + } }