Skip to content

Commit

Permalink
Merge pull request #152 from creative-commoners/pulls/2.5/behat
Browse files Browse the repository at this point in the history
MNT Update behat test
  • Loading branch information
Maxime Rainville authored Nov 10, 2021
2 parents ee9206e + 861e091 commit 4359bd7
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 35 deletions.
31 changes: 14 additions & 17 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
# Run sharedraftcontent behat tests with this command
# Note that sharedraftcontent behat tests require CMS module
# ========================================================================= #
# chromedriver
# vendor/bin/behat @sharedraftcontent
# ========================================================================= #
default:
suites:
sharedraftcontent:
paths:
- '%paths.modules.sharedraftcontent%/tests/Behat/features'
- "%paths.modules.sharedraftcontent%/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\BehatExtension\Context\LoginContext
- SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
- SilverStripe\Framework\Tests\Behaviour\CmsUiContext
- SilverStripe\ShareDraftContent\Tests\Behat\Context\FeatureContext
- SilverStripe\ShareDraftContent\Tests\Behat\Context\FixtureContext
-
SilverStripe\BehatExtension\Context\FixtureContext:
- '%paths.modules.sharedraftcontent%/tests/Behat/files/'
SilverStripe\ShareDraftContent\Tests\Behat\Context\FixtureContext:
- "%paths.modules.sharedraftcontent%/tests/behat/files/"

extensions:
SilverStripe\BehatExtension\MinkExtension:
default_session: facebook_web_driver
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:
bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php
screenshot_path: '%paths.base%/artifacts/screenshots'
retry_seconds: 4 # default is 2
screenshot_path: "%paths.base%/artifacts/screenshots"
bootstrap_file: vendor/silverstripe/framework/tests/behat/serve-bootstrap.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"autoload": {
"psr-4": {
"SilverStripe\\ShareDraftContent\\": "src/",
"SilverStripe\\ShareDraftContent\\Tests\\": "tests/"
"SilverStripe\\ShareDraftContent\\Tests\\": "tests/",
"SilverStripe\\ShareDraftContent\\Tests\\Behat\\Context\\": "tests/behat/src/"
}
},
"minimum-stability": "dev",
Expand Down
17 changes: 0 additions & 17 deletions tests/Behat/features/share-draft.feature

This file was deleted.

Empty file added tests/behat/_manifest_exclude
Empty file.
32 changes: 32 additions & 0 deletions tests/behat/features/share-draft.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@javascript
Feature: Share the draft version of a page
As a CMS author
I want to share the draft version of a page
So that unauthenticated users can view draft changes before I publish them

Background:
Given a "page" "My page" with "Content"="Initial content"
And the "group" "EDITOR group" has permissions "CMS_ACCESS_LeftAndMain"

Scenario: I can generate a share draft link
# Setup
Given I am logged in with "EDITOR" permissions
And I go to "/admin/pages"
And I click on "My page" in the tree

# Test link generation works
Given I press the "Share" button
Then I should see "Share draft content"
And I should see "Anyone with this link can view the draft version of this page"
And I save the link to share draft content local storage

# Test the link allows us to view content on the front end when not logged in
When I go to "/Security/login"
And I press the "Log in as someone else" button
And I follow the link in share draft content local storage
And I clear the link from share draft content local storage
Then I should see "My page"

# Test that still cannot view regular draft content
When I go to "/my-page"
Then I should not see "My Page"
Empty file added tests/behat/files/blank.txt
Empty file.
46 changes: 46 additions & 0 deletions tests/behat/src/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace SilverStripe\ShareDraftContent\Tests\Behat\Context;

use SilverStripe\BehatExtension\Context\SilverStripeContext;

class FeatureContext extends SilverStripeContext
{
private const KEY = 'behat.sharedraftcontent.link';

/**
* @Given /^I save the link to share draft content local storage$/
*/
public function iSaveTheLinkToShareDraftContentLocalStorage()
{
$key = self::KEY;
$js = <<<JS
window.localStorage.setItem('{$key}', document.querySelector('.share-draft-content__link').value);
JS;
$this->getSession()->evaluateScript($js);
}

/**
* @Given /^I follow the link in share draft content local storage$/
*/
public function iFollowTheLinkInShareDraftContentLocalStorage()
{
$key = self::KEY;
$js = <<<JS
window.location = window.localStorage.getItem('{$key}');
JS;
$this->getSession()->evaluateScript($js);
}

/**
* @Given /^I clear the link from share draft content local storage$/
*/
public function iClearTheLinkFromShareDraftContentLocalStorage()
{
$key = self::KEY;
$js = <<<JS
window.localStorage.removeItem('{$key}');
JS;
$this->getSession()->evaluateScript($js);
}
}
9 changes: 9 additions & 0 deletions tests/behat/src/FixtureContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace SilverStripe\ShareDraftContent\Tests\Behat\Context;

use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;

class FixtureContext extends BaseFixtureContext
{
}

0 comments on commit 4359bd7

Please sign in to comment.