From 9841d5b0746b435006de1fcb69ddc76a6026ce50 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Nov 2012 19:15:54 +0100 Subject: [PATCH 1/3] NEW Added Behat tests --- composer.json | 5 ++- tests/behat/README.md | 1 + tests/behat/_manifest_exclude | 0 tests/behat/behat.yml | 45 +++++++++++++++++++ .../features/bootstrap/FeatureContext.php | 38 ++++++++++++++++ tests/behat/features/create-a-page.feature | 15 +++++++ tests/behat/features/edit-a-page.feature | 29 ++++++++++++ tests/behat/features/preview-a-page.feature | 41 +++++++++++++++++ tests/behat/features/publish-a-page.feature | 4 ++ .../behat/features/search-for-a-page.feature | 18 ++++++++ 10 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 tests/behat/README.md create mode 100644 tests/behat/_manifest_exclude create mode 100644 tests/behat/behat.yml create mode 100644 tests/behat/features/bootstrap/FeatureContext.php create mode 100644 tests/behat/features/create-a-page.feature create mode 100644 tests/behat/features/edit-a-page.feature create mode 100644 tests/behat/features/preview-a-page.feature create mode 100644 tests/behat/features/publish-a-page.feature create mode 100644 tests/behat/features/search-for-a-page.feature diff --git a/composer.json b/composer.json index 60c4ebe0..96a82364 100644 --- a/composer.json +++ b/composer.json @@ -19,5 +19,8 @@ "php": ">=5.3.2", "composer/installers": "*", "silverstripe/framework": "self.version" - } + }, + "autoload": { + "classmap": ["tests/behat/"] + } } \ No newline at end of file diff --git a/tests/behat/README.md b/tests/behat/README.md new file mode 100644 index 00000000..e072aec9 --- /dev/null +++ b/tests/behat/README.md @@ -0,0 +1 @@ +See https://github.com/silverstripe-labs/silverstripe-behat-extension \ No newline at end of file diff --git a/tests/behat/_manifest_exclude b/tests/behat/_manifest_exclude new file mode 100644 index 00000000..e69de29b diff --git a/tests/behat/behat.yml b/tests/behat/behat.yml new file mode 100644 index 00000000..4a1926a9 --- /dev/null +++ b/tests/behat/behat.yml @@ -0,0 +1,45 @@ +default: + context: + class: SilverStripe\Cms\Test\Behaviour\FeatureContext + parameters: + admin_url: /admin/ + login_url: /Security/login + screenshot_path: %behat.paths.features%/screenshots/ + extensions: + SilverStripe\BehatExtension\Extension: + framework_path: ../../../framework + ajax_steps: + - go to + - follow + - press + - click + - submit + Behat\MinkExtension\Extension: + # Adjust this to your local environment + base_url: http://localhost/ + files_path: %behat.paths.features%/files/ + default_session: selenium2 + javascript_session: selenium2 + goutte: ~ + selenium2: + browser: firefox + +# Alternative profile, use with "vendor/bin/behat --profile chrome" +chrome: + extensions: + Behat\MinkExtension\Extension: + selenium2: + browser: chrome + +# Saucelabs.com sample setup, use with "vendor/bin/behat --profile saucelabs" +saucelabs: + extensions: + Behat\MinkExtension\Extension: + selenium2: + browser: firefox + # Add your own username and API token here + wd_host: :@ondemand.saucelabs.com/wd/hub + capabilities: + platform: "Windows 2008" + browser: "firefox" + version: "15" \ No newline at end of file diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000..859dc5e0 --- /dev/null +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -0,0 +1,38 @@ +useContext('BasicContext', new BasicContext($parameters)); + $this->useContext('LoginContext', new LoginContext($parameters)); + $this->useContext('CmsFormsContext', new CmsFormsContext($parameters)); + $this->useContext('CmsUiContext', new CmsUiContext($parameters)); + + parent::__construct($parameters); + } +} diff --git a/tests/behat/features/create-a-page.feature b/tests/behat/features/create-a-page.feature new file mode 100644 index 00000000..84652beb --- /dev/null +++ b/tests/behat/features/create-a-page.feature @@ -0,0 +1,15 @@ +@database-defaults +Feature: Create a page + As an author + I want to create a page in the CMS + So that I can grow my website + + @javascript + Scenario: I can create a page from the pages section + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + And I should see "Add new" button in CMS Content Toolbar + When I press "Add new" button + And I check "Page" + And I press "Create" button + Then I should see an edit page form diff --git a/tests/behat/features/edit-a-page.feature b/tests/behat/features/edit-a-page.feature new file mode 100644 index 00000000..79e74119 --- /dev/null +++ b/tests/behat/features/edit-a-page.feature @@ -0,0 +1,29 @@ +@database-defaults +Feature: Edit a page + As an author + I want to edit a page in the CMS + So that I correct errors and provide new information + + Background: + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + Then I should see "About Us" in CMS Tree + + @javascript + Scenario: I can open a page for editing from the pages tree + When I follow "About Us" + Then I should see an edit page form + + @javascript + Scenario: I can edit title and content and see the changes on draft + When I follow "About Us" + Then I should see an edit page form + + When I fill in "Title" with "About Us!" + And I fill in content form with "my new content" + And I press "Save Draft" button + Then I should see "Saved." notice + + When I follow "About Us" + Then the "Title" field should contain "About Us!" + And the content form should contain "my new content" \ No newline at end of file diff --git a/tests/behat/features/preview-a-page.feature b/tests/behat/features/preview-a-page.feature new file mode 100644 index 00000000..1ca2a5c5 --- /dev/null +++ b/tests/behat/features/preview-a-page.feature @@ -0,0 +1,41 @@ +@database-defaults +Feature: Preview a page + As an author + I want to preview the page I'm editing in the CMS + So that I can see how it would look like to my visitors + + @javascript + Scenario: I can show a preview of the current page from the pages section + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + Then I should see "About Us" in CMS Tree + + When I follow "About Us" + And I press "Preview »" button + Then I can see the preview panel + And the preview contains "About Us" + + # TODO: + # - Only tests correctly on fresh database + # - We should continue testing against it after we have fixtures ready + @javascript + Scenario: I can see an updated preview when editing content + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + Then I should see "About Us" in CMS Tree + + When I follow "About Us" + And I fill in content form with "my new content" + And I press "Save Draft" button + And I press "Preview »" button + + When I follow "Published Site" + Then the preview does not contain "my new content" + And the preview contains "You can fill" + + When I follow "Draft Site" + Then the preview does not contain "You can fill" + And the preview contains "my new content" + + When I press "« Edit" button + Then I should see an edit page form \ No newline at end of file diff --git a/tests/behat/features/publish-a-page.feature b/tests/behat/features/publish-a-page.feature new file mode 100644 index 00000000..ee7e1060 --- /dev/null +++ b/tests/behat/features/publish-a-page.feature @@ -0,0 +1,4 @@ +Feature: Create a page + As a site owner + I want content to go to a draft site before being published + So that only high quality changes are seen by our visitors \ No newline at end of file diff --git a/tests/behat/features/search-for-a-page.feature b/tests/behat/features/search-for-a-page.feature new file mode 100644 index 00000000..b5197811 --- /dev/null +++ b/tests/behat/features/search-for-a-page.feature @@ -0,0 +1,18 @@ +@database-defaults +Feature: Search for a page + As an author + I want to search for a page in the CMS + So that I can efficiently navigate nested content structures + + @javascript + Scenario: I can search for a page by its title + Given I am logged in with "ADMIN" permissions + And I go to "/admin/pages" + Then I should see "About Us" in CMS Tree + And I should see "Contact Us" in CMS Tree + + When I expand Filter CMS Panel + And I fill in "Content" with "About Us" + And I press "Apply Filter" button + Then I should see "About Us" in CMS Tree + But I should not see "Contact Us" in CMS Tree From df23a6ce1ac700a7f4d894f9339784832fb15360 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Nov 2012 20:50:16 +0100 Subject: [PATCH 2/3] Corrected step wording --- tests/behat/features/create-a-page.feature | 6 +++--- tests/behat/features/edit-a-page.feature | 6 +++--- tests/behat/features/preview-a-page.feature | 10 +++++----- tests/behat/features/search-for-a-page.feature | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/behat/features/create-a-page.feature b/tests/behat/features/create-a-page.feature index 84652beb..a1df9adc 100644 --- a/tests/behat/features/create-a-page.feature +++ b/tests/behat/features/create-a-page.feature @@ -8,8 +8,8 @@ Feature: Create a page Scenario: I can create a page from the pages section Given I am logged in with "ADMIN" permissions And I go to "/admin/pages" - And I should see "Add new" button in CMS Content Toolbar - When I press "Add new" button + And I should see a "Add new" button in CMS Content Toolbar + When I press the "Add new" button And I check "Page" - And I press "Create" button + And I press the "Create" button Then I should see an edit page form diff --git a/tests/behat/features/edit-a-page.feature b/tests/behat/features/edit-a-page.feature index 79e74119..0be2ba39 100644 --- a/tests/behat/features/edit-a-page.feature +++ b/tests/behat/features/edit-a-page.feature @@ -20,9 +20,9 @@ Feature: Edit a page Then I should see an edit page form When I fill in "Title" with "About Us!" - And I fill in content form with "my new content" - And I press "Save Draft" button - Then I should see "Saved." notice + And I fill in the content form with "my new content" + And I press the "Save Draft" button + Then I should see a "Saved." notice When I follow "About Us" Then the "Title" field should contain "About Us!" diff --git a/tests/behat/features/preview-a-page.feature b/tests/behat/features/preview-a-page.feature index 1ca2a5c5..279fdb27 100644 --- a/tests/behat/features/preview-a-page.feature +++ b/tests/behat/features/preview-a-page.feature @@ -11,7 +11,7 @@ Feature: Preview a page Then I should see "About Us" in CMS Tree When I follow "About Us" - And I press "Preview »" button + And I press the "Preview »" button Then I can see the preview panel And the preview contains "About Us" @@ -25,9 +25,9 @@ Feature: Preview a page Then I should see "About Us" in CMS Tree When I follow "About Us" - And I fill in content form with "my new content" - And I press "Save Draft" button - And I press "Preview »" button + And I fill in the content form with "my new content" + And I press the "Save Draft" button + And I press the "Preview »" button When I follow "Published Site" Then the preview does not contain "my new content" @@ -37,5 +37,5 @@ Feature: Preview a page Then the preview does not contain "You can fill" And the preview contains "my new content" - When I press "« Edit" button + When I press the "« Edit" button Then I should see an edit page form \ No newline at end of file diff --git a/tests/behat/features/search-for-a-page.feature b/tests/behat/features/search-for-a-page.feature index b5197811..23e51931 100644 --- a/tests/behat/features/search-for-a-page.feature +++ b/tests/behat/features/search-for-a-page.feature @@ -11,8 +11,8 @@ Feature: Search for a page Then I should see "About Us" in CMS Tree And I should see "Contact Us" in CMS Tree - When I expand Filter CMS Panel + When I expand the "Filter" CMS Panel And I fill in "Content" with "About Us" - And I press "Apply Filter" button + And I press the "Apply Filter" button Then I should see "About Us" in CMS Tree But I should not see "Contact Us" in CMS Tree From 20a817875a366ff387ae4e9d6d7c0da8545d4014 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 14 Nov 2012 00:41:01 +0100 Subject: [PATCH 3/3] Shortened behat.yml --- tests/behat/behat.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/behat/behat.yml b/tests/behat/behat.yml index 4a1926a9..0bf9097f 100644 --- a/tests/behat/behat.yml +++ b/tests/behat/behat.yml @@ -1,19 +1,8 @@ default: context: class: SilverStripe\Cms\Test\Behaviour\FeatureContext - parameters: - admin_url: /admin/ - login_url: /Security/login - screenshot_path: %behat.paths.features%/screenshots/ extensions: - SilverStripe\BehatExtension\Extension: - framework_path: ../../../framework - ajax_steps: - - go to - - follow - - press - - click - - submit + SilverStripe\BehatExtension\Extension: ~ Behat\MinkExtension\Extension: # Adjust this to your local environment base_url: http://localhost/