From 677f38227c80429dcc4ed67c9db42743cf77f04a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 23 Oct 2013 21:58:28 +0200 Subject: [PATCH 01/11] Behat tests for image upload and overwrite in HTML editor --- tests/behat/features/insert-an-image.feature | 49 +++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/tests/behat/features/insert-an-image.feature b/tests/behat/features/insert-an-image.feature index 742f8f71..c5a34421 100644 --- a/tests/behat/features/insert-an-image.feature +++ b/tests/behat/features/insert-an-image.feature @@ -6,10 +6,8 @@ Feature: Insert an image into a page Background: Given a "page" "About Us" - #And a "file" "assets/folder1/file1.jpg" - #And a "file" "assets/folder1/file3.jpg" - #And a "file" "assets/folder1/folder1.1/file2.jpg" - #And a "folder" "assets/folder2" + And a "file" "assets/folder1/file1.jpg" + And a "file" "assets/folder1/file2.jpg" And I am logged in with "ADMIN" permissions And I go to "/admin/pages" And I click on "About Us" in the tree @@ -28,17 +26,36 @@ Feature: Insert an image into a page # Required to avoid "unsaved changed" browser dialog Then I press the "Save draft" button - @todo + @assets Scenario: I can insert an image uploaded from my own computer Given I press the "Insert Media" button And I press the "From your computer" button - # TODO Figure out how to provide the file And I attach the file "testfile.jpg" to "AssetUploadField" with HTML5 - Then the upload field should have successfully uploaded "testfile.jpg" + # TODO Delay previous step until upload succeeded + And I wait for 2 seconds + Then there should be a file "assets/Uploads/testfile.jpg" When I press the "Insert" button Then the "Content" HTML field should contain "testfile.jpg" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button - @todo + @assets + Scenario: I can overwrite an existing image with one uploaded from my own computer + Given a "file" "assets/Uploads/file1.jpg" + When I press the "Insert Media" button + And I press the "From your computer" button + And I attach the file "file1.jpg" to "AssetUploadField" with HTML5 + # TODO Delay previous step until upload succeeded + And I wait for 2 seconds + Then I should see "Overwrite" + When I press the "Overwrite" button + Then there should be a file "assets/Uploads/file1.jpg" + When I press the "Insert" button + Then the "Content" HTML field should contain "file1.jpg" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button + + @todo Scenario: I can insert an image from the CMS file store Given I press the "Insert Media" button And I press the "From the CMS" button @@ -46,6 +63,8 @@ Feature: Insert an image into a page And I select "file1.jpg" When I press the "Insert" button Then the "Content" HTML field should contain "file1.jpg" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button @todo Scenario: I can insert multiple images at once @@ -53,10 +72,12 @@ Feature: Insert an image into a page And I press the "From the CMS" button And I select "folder1" in the "Find in Folder" dropdown And I select "file1.jpg" - And I select "file3.jpg" + And I select "file2.jpg" When I press the "Insert" button Then the "Content" HTML field should contain "file1.jpg" - And the "Content" HTML field should contain "file1.jpg" + And the "Content" HTML field should contain "file2.jpg" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button @todo Scenario: I can edit properties of an image before inserting it @@ -69,6 +90,8 @@ Feature: Insert an image into a page And I press the "Insert" button Then the "Content" HTML field should contain "file1.jpg" And the "Content" HTML field should contain "My alt" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button @todo Scenario: I can edit dimensions of an image before inserting it @@ -81,6 +104,8 @@ Feature: Insert an image into a page When I fill in "Height" with "20" And I press the "Insert" button Then the "Content" HTML field should contain "" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button @todo Scenario: I can edit dimensions of an existing image @@ -92,4 +117,6 @@ Feature: Insert an image into a page When I fill in "Width" with "10" When I fill in "Height" with "20" And I press the "Insert" button - Then the "Content" HTML field should contain "" \ No newline at end of file + Then the "Content" HTML field should contain "" + # Required to avoid "unsaved changed" browser dialog + Then I press the "Save draft" button \ No newline at end of file From 34c8fb22cb2751180e5235b17b2e630c899d7265 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Nov 2013 11:44:56 +0100 Subject: [PATCH 02/11] Convert behat PHP to SS coding conventions --- .../features/bootstrap/FeatureContext.php | 61 ++++++++--------- .../Cms/Test/Behaviour/FixtureContext.php | 68 +++++++++---------- 2 files changed, 63 insertions(+), 66 deletions(-) diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 1f9e5bc1..579ea3bd 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -3,12 +3,12 @@ namespace SilverStripe\Cms\Test\Behaviour; use SilverStripe\BehatExtension\Context\SilverStripeContext, - SilverStripe\BehatExtension\Context\BasicContext, - SilverStripe\BehatExtension\Context\LoginContext, - SilverStripe\BehatExtension\Context\FixtureContext, - SilverStripe\Framework\Test\Behaviour\CmsFormsContext, - SilverStripe\Framework\Test\Behaviour\CmsUiContext, - SilverStripe\Cms\Test\Behaviour; + SilverStripe\BehatExtension\Context\BasicContext, + SilverStripe\BehatExtension\Context\LoginContext, + SilverStripe\BehatExtension\Context\FixtureContext, + SilverStripe\Framework\Test\Behaviour\CmsFormsContext, + SilverStripe\Framework\Test\Behaviour\CmsUiContext, + SilverStripe\Cms\Test\Behaviour; // PHPUnit require_once 'PHPUnit/Autoload.php'; @@ -20,33 +20,32 @@ require_once 'PHPUnit/Framework/Assert/Functions.php'; * Context automatically loaded by Behat. * Uses subcontexts to extend functionality. */ -class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext -{ - /** - * Initializes context. - * Every scenario gets it's own context object. - * - * @param array $parameters context parameters (set them up through behat.yml) - */ - public function __construct(array $parameters) - { - parent::__construct($parameters); +class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext { - // Override existing fixture context with more specific one - $fixtureContext = new \SilverStripe\Cms\Test\Behaviour\FixtureContext($parameters); - $fixtureContext->setFixtureFactory($this->getFixtureFactory()); - $this->useContext('FixtureContext', $fixtureContext); + /** + * Initializes context. + * Every scenario gets it's own context object. + * + * @param array $parameters context parameters (set them up through behat.yml) + */ + public function __construct(array $parameters) { + parent::__construct($parameters); - // Use blueprints which auto-publish all subclasses of SiteTree - $factory = $fixtureContext->getFixtureFactory(); - foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { - $blueprint = \Injector::inst()->create('FixtureBlueprint', $class); - $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) { - $obj->publish('Stage', 'Live'); - }); - $factory->define($class, $blueprint); - } + // Override existing fixture context with more specific one + $fixtureContext = new \SilverStripe\Cms\Test\Behaviour\FixtureContext($parameters); + $fixtureContext->setFixtureFactory($this->getFixtureFactory()); + $this->useContext('FixtureContext', $fixtureContext); - } + // Use blueprints which auto-publish all subclasses of SiteTree + $factory = $fixtureContext->getFixtureFactory(); + foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { + $blueprint = \Injector::inst()->create('FixtureBlueprint', $class); + $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) { + $obj->publish('Stage', 'Live'); + }); + $factory->define($class, $blueprint); + } + + } } diff --git a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php index a2c20914..7c2ac887 100644 --- a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php @@ -3,14 +3,14 @@ namespace SilverStripe\Cms\Test\Behaviour; use Behat\Behat\Context\ClosuredContextInterface, - Behat\Behat\Context\TranslatedContextInterface, - Behat\Behat\Context\BehatContext, - Behat\Behat\Context\Step, - Behat\Behat\Event\StepEvent, - Behat\Behat\Exception\PendingException, - Behat\Mink\Driver\Selenium2Driver, - Behat\Gherkin\Node\PyStringNode, - Behat\Gherkin\Node\TableNode; + Behat\Behat\Context\TranslatedContextInterface, + Behat\Behat\Context\BehatContext, + Behat\Behat\Context\Step, + Behat\Behat\Event\StepEvent, + Behat\Behat\Exception\PendingException, + Behat\Mink\Driver\Selenium2Driver, + Behat\Gherkin\Node\PyStringNode, + Behat\Gherkin\Node\TableNode; // PHPUnit require_once 'PHPUnit/Autoload.php'; @@ -19,32 +19,30 @@ require_once 'PHPUnit/Framework/Assert/Functions.php'; /** * Context used to create fixtures in the SilverStripe ORM. */ -class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext -{ +class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext { - /** - * Find or create a redirector page and link to another existing page. - * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1" - * - * @Given /^(?:(an|a|the) )"(?[^"]+)" "(?[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?[^"]+)" "(?[^"]+)"$/ - */ - public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) - { - $class = 'RedirectorPage'; - $targetClass = $this->convertTypeToClass($targetType); - - $targetObj = $this->fixtureFactory->get($targetClass, $targetId); - if(!$targetObj) $targetObj = $this->fixtureFactory->get($targetClass, $targetId); - - $fields = array('LinkToID' => $targetObj->ID); - $obj = $this->fixtureFactory->get($class, $id); - if($obj) { - $obj->update($fields); - } else { - $obj = $this->fixtureFactory->createObject($class, $id, $fields); - } - $obj->write(); - $obj->publish('Stage', 'Live'); - } + /** + * Find or create a redirector page and link to another existing page. + * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1" + * + * @Given /^(?:(an|a|the) )"(?[^"]+)" "(?[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?[^"]+)" "(?[^"]+)"$/ + */ + public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) { + $class = 'RedirectorPage'; + $targetClass = $this->convertTypeToClass($targetType); + + $targetObj = $this->fixtureFactory->get($targetClass, $targetId); + if(!$targetObj) $targetObj = $this->fixtureFactory->get($targetClass, $targetId); + + $fields = array('LinkToID' => $targetObj->ID); + $obj = $this->fixtureFactory->get($class, $id); + if($obj) { + $obj->update($fields); + } else { + $obj = $this->fixtureFactory->createObject($class, $id, $fields); + } + $obj->write(); + $obj->publish('Stage', 'Live'); + } -} +} \ No newline at end of file From e444b359ec3f38a29e59a11677ee5228773db228 Mon Sep 17 00:00:00 2001 From: Sriram Venkatesh Date: Fri, 15 Nov 2013 14:43:55 +0100 Subject: [PATCH 03/11] Implemented Behat test for page search (fixes #620) Added Deleted state to UpdateState step defination See https://github.com/silverstripe/silverstripe-cms/pull/896 --- .../behat/features/search-for-a-page.feature | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/behat/features/search-for-a-page.feature b/tests/behat/features/search-for-a-page.feature index 1da95bd9..d98aeb1f 100644 --- a/tests/behat/features/search-for-a-page.feature +++ b/tests/behat/features/search-for-a-page.feature @@ -17,38 +17,35 @@ Feature: Search for a page Then I should see "About Us" in the tree But I should not see "Contact Us" in the tree - @todo Scenario: I can search for a page by its type - Given a "page" "My Error Page" of type "Error Page" - And I fill in "Page Type" with "Redirector Page" + Given a "Error Page" "My Error Page" + When I select "Error Page" from "Page Type" And I press the "Apply Filter" button Then I should see "My Error Page" in the tree But I should not see "Contact Us" in the tree - @todo Scenario: I can search for a page by its oldest last edited date Given a "page" "Recent Page" - And a "page" "Old Page" was last edited 7 days ago - When I fill in "From" with "5 days ago" + And a "page" "Old Page" was last edited "7 days ago" + When I fill in "From" with "the date of 5 days ago" And I press the "Apply Filter" button Then I should see "Recent Page" in the tree But I should not see "Old Page" in the tree - @todo Scenario: I can search for a page by its newest last edited date Given a "page" "Recent Page" - And a "page" "Old Page" was last edited 7 days ago - When I fill in "To" with "5 days ago" + And a "page" "Old Page" was last edited "7 days ago" + When I fill in "To" with "the date of 5 days ago" And I press the "Apply Filter" button Then I should not see "Recent Page" in the tree But I should see "Old Page" in the tree - @todo + Scenario: I can include deleted pages in my search Given a "page" "Deleted Page" - And the "page" "Old Page" is deleted + And the "page" "Deleted Page" is deleted When I press the "Apply Filter" button Then I should not see "Deleted Page" in the tree - When I fill in "Pages" with "All pages, including deleted" + When I select "All pages, including deleted" from "Pages" And I press the "Apply Filter" button Then I should see "Deleted Page" in the tree \ No newline at end of file From ddc2e3822b0b5f610bb1920599d83f3d6b2ea742 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 18 Nov 2013 16:32:15 +1300 Subject: [PATCH 04/11] FIX: ErrorPage generating empty responses for 403/401 requests Previously by setting the response status code inside the action, this prevented response bodies from being included due to 403/401 being matched by SS_HTTPResponse::isFinished() (which stops popular I assume SS_HTTPResponse::isFinished() is valid for the permission error use case (and I would be hesitant to change it) so this simply moves the declaration of the response status code till after the parent has populated the body of the response. --- code/model/ErrorPage.php | 44 +++++++++++++++++++++++------------ tests/model/ErrorPageTest.php | 13 +++++++++-- tests/model/ErrorPageTest.yml | 7 +++++- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index ac029c7a..e5503ecb 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -42,7 +42,9 @@ class ErrorPage extends Page { /** * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an - * {@link ErrorPage} for that code is present. + * {@link ErrorPage} for that code is present. First tries to serve it + * through the standard SilverStripe request method. Falls back to a static + * file generated when the user hit's save and publish in the CMS * * @param int $statusCode * @@ -50,11 +52,17 @@ class ErrorPage extends Page { */ public static function response_for($statusCode) { // first attempt to dynamically generate the error page - if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorPage\".\"ErrorCode\" = $statusCode")) { + $errorPage = ErrorPage::get()->filter(array( + "ErrorCode" => $statusCode + ))->first(); + + if($errorPage) { Requirements::clear(); Requirements::clear_combined_files(); - return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst()); + return ModelAsController::controller_for($errorPage)->handleRequest( + new SS_HTTPRequest('GET', ''), DataModel::inst() + ); } // then fall back on a cached version @@ -62,13 +70,13 @@ class ErrorPage extends Page { $statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null ); - + if(file_exists($cachedPath)) { $response = new SS_HTTPResponse(); $response->setStatusCode($statusCode); $response->setBody(file_get_contents($cachedPath)); - + return $response; } } @@ -129,13 +137,12 @@ class ErrorPage extends Page { } } } - } } /** - * Returns an array of arrays, each of which defines - * properties for a new ErrorPage record. + * Returns an array of arrays, each of which defines properties for a new + * ErrorPage record. * * @return array */ @@ -159,6 +166,7 @@ class ErrorPage extends Page { ) ) ); + $this->extend('getDefaultRecords', $data); return $data; @@ -316,14 +324,20 @@ class ErrorPage extends Page { */ class ErrorPage_Controller extends Page_Controller { - public function init() { - parent::init(); + /** + * Overload the provided {@link Controller::handleRequest()} to append the + * correct status code post request since otherwise permission related error + * pages such as 401 and 403 pages won't be rendered due to + * {@link SS_HTTPResponse::isFinished() ignoring the response body. + * + * @param SS_HTTPRequest + * @param DataModel + */ + public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) { + $body = parent::handleRequest($request, $model); + $this->response->setStatusCode($this->ErrorCode); - $action = $this->request->param('Action'); - if(!$action || $action == 'index') { - $this->getResponse()->setStatusCode($this->failover->ErrorCode ? $this->failover->ErrorCode : 404); - } - + return $this->response; } } diff --git a/tests/model/ErrorPageTest.php b/tests/model/ErrorPageTest.php index c3c11629..c68d9594 100644 --- a/tests/model/ErrorPageTest.php +++ b/tests/model/ErrorPageTest.php @@ -60,5 +60,14 @@ class ErrorPageTest extends FunctionalTest { /* Don't show the error page in the search */ $this->assertEquals($page->ShowInSearch, 0, 'Don\'t show the error page in search'); } - -} + + public function testBehaviourOf403() { + $page = $this->objFromFixture('ErrorPage', '403'); + $page->publish('Stage', 'Live'); + + $response = $this->get($page->Link()); + + $this->assertEquals($response->getStatusCode(), '403'); + $this->assertNotNull($response->getBody(), 'We have body text from the error page'); + } +} \ No newline at end of file diff --git a/tests/model/ErrorPageTest.yml b/tests/model/ErrorPageTest.yml index 859332ae..e2152199 100644 --- a/tests/model/ErrorPageTest.yml +++ b/tests/model/ErrorPageTest.yml @@ -3,4 +3,9 @@ ErrorPage: Title: Page Not Found URLSegment: page-not-found Content: My error page body - ErrorCode: 404 \ No newline at end of file + ErrorCode: 404 + 403: + Title: Permission Failure + URLSegment: permission-denied + Content: You do not have permission to view this page + ErrorCode: 403 \ No newline at end of file From 95d9257b1b20070e4058eab037c6367c161141d7 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Thu, 4 Jul 2013 15:12:25 +0100 Subject: [PATCH 05/11] ENHANCEMENT: Add 'Cancel' button to 'Add Page' form --- code/controllers/CMSPageAddController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 14564425..496052f4 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -10,6 +10,7 @@ class CMSPageAddController extends CMSPageEditController { private static $allowed_actions = array( 'AddForm', 'doAdd', + 'doCancel' ); /** @@ -108,9 +109,11 @@ class CMSPageAddController extends CMSPageEditController { } $actions = new FieldList( - // $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')), FormAction::create("doAdd", _t('CMSMain.Create',"Create")) ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') + ->setUseButtonTag(true), + FormAction::create("doCancel", _t('CMSMain.Cancel',"Cancel")) + ->addExtraClass('ss-ui-action-destructive') ->setUseButtonTag(true) ); @@ -174,4 +177,8 @@ class CMSPageAddController extends CMSPageEditController { return $this->redirect(Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID)); } + public function doCancel($data, $form) { + return $this->redirect(singleton('CMSMain')->Link()); + } + } From 8f720406b58bbdc068ee988bc9453c669bc807a4 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Mon, 11 Nov 2013 12:31:32 +0000 Subject: [PATCH 06/11] Implement History.js logic for "Cancel" action --- code/controllers/CMSPageAddController.php | 2 +- javascript/CMSMain.AddForm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 496052f4..bace5550 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -113,7 +113,7 @@ class CMSPageAddController extends CMSPageEditController { ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') ->setUseButtonTag(true), FormAction::create("doCancel", _t('CMSMain.Cancel',"Cancel")) - ->addExtraClass('ss-ui-action-destructive') + ->addExtraClass('ss-ui-action-destructive ss-ui-action-cancel') ->setUseButtonTag(true) ); diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js index 08e62d6b..e76055f4 100644 --- a/javascript/CMSMain.AddForm.js +++ b/javascript/CMSMain.AddForm.js @@ -84,7 +84,7 @@ else $(this).find('input').removeAttr('disabled'); } }); - + $(".cms-page-add-button").entwine({ onclick: function(e) { var tree = $('.cms-tree'), list = $('.cms-list'), parentId = 0; From a79ac87e2b357bc6d6a3ed436d07e68107f031ad Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 28 Nov 2013 23:22:44 +1300 Subject: [PATCH 07/11] Fixing up scenarios for managing page permissions Behat tests. Relies on changes from silverstripe-behat-extension: silverstripe-behat-extension/pull/15 silverstripe-behat-extension/pull/14 silverstripe-behat-extension/pull/13 silverstripe-behat-extension/pull/12 --- .../features/manage-page-permisions.feature | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/tests/behat/features/manage-page-permisions.feature b/tests/behat/features/manage-page-permisions.feature index d606d076..f751f3c7 100644 --- a/tests/behat/features/manage-page-permisions.feature +++ b/tests/behat/features/manage-page-permisions.feature @@ -1,56 +1,60 @@ -@todo Feature: Manage global page permissions As an administrator I want to manage view and edit permission defaults on pages In order to set good defaults and avoid repeating myself on each page Background: - Given I have an "Administrator" user in a "Administrators" Security Group - Given I have an "Content Author" user in a "Content Authors" Security Group - And I am logged in as an "ADMIN" - And I navigate to the "Settings" CMS section + Given a "page" "Home" with "Content"="Welcome" + And a "group" "AUTHOR group" has permissions "Access to 'Pages' section" + And a "group" "SECURITY group" has permissions "Access to 'Security' section" + And I am logged in with "ADMIN" permissions + And I go to "admin/settings" + And I click the "Access" CMS tab Scenario: I can open global view permissions to everyone - Given I select the 'Access' tab - And I select "Anyone" in the 'Who can view pages on this site?' field - And press the "Save" button - When I visit the homepage without being logged in - Then I can see "Welcome" - + Given I select "Anyone" from "Who can view pages on this site?" input group + And I press the "Save" button + When I am not logged in + And I go to the homepage + Then I should see "Welcome" + Scenario: I can limit global view permissions to logged-in users - Given I select the 'Access' tab - And I select "Logged-in users" in 'Who can view pages on this site?' - And press the 'Save' button - When I visit the homepage without being logged in - Then I am redirected to the log-in page - When I visit the homepage as "Content Author" - Then I can see "Welcome" + Given I select "Logged-in users" from "Who can view pages on this site?" input group + And I press the "Save" button + When I am not logged in + And I go to the homepage + Then I should see a log-in form + When I am logged in with "AUTHOR" permissions + And I go to the homepage + Then I should see "Welcome" Scenario: I can limit global view permissions to certain groups - Given I select the 'Access' tab - And I select "Only these people (choose from list)" in 'Who can view pages on this site?' - And I select "Administrators" in the "Viewer Groups" dropdown - And press the 'Save' button - When I visit the homepage without being logged in - Then I am redirected to the log-in page - When I visit the homepage as "Content Author" - Then I am redirected to the log-in page - When I visit the homepage as "Administrator" - Then I can see "Welcome" + Given I select "Only these people (choose from list)" from "Who can view pages on this site?" input group + And I select "AUTHOR group" from "Viewer Groups" + And I press the "Save" button + When I am not logged in + And I go to the homepage + Then I should see a log-in form + When I am logged in with "SECURITY" permissions + And I go to the homepage + Then I will see a "warning" log-in message + When I am not logged in + And I am logged in with "AUTHOR" permissions + And I go to the homepage + Then I should see "Welcome" +@todo Scenario: I can limit global edit permissions to logged-in users - Given I select the 'Access' tab - And I select "Logged-in users" in 'Who can edit pages on this site?' - And press the 'Save' button - Then pages should be editable by "Content Authors" - And pages should be editable by "Administrators" + Given I select "Logged-in users" in "Who can edit pages on this site?" input group + And I press the "Save" button + Then pages should be editable by "Content Authors" + And pages should be editable by "Administrators" +@todo Scenario: I can limit global edit permissions to certain groups - Given I select the 'Access' tab - And I select "Only these people (choose from list)" in 'Who can edit pages on this site?' - And I select "Administrators" in the "Viewer Groups" dropdown - And press the 'Save' button - Then pages should not be editable by "Content Authors" - But pages should be editable by "Administrators" + Given I select "Only these people (choose from list)" from "Who can edit pages on this site?" input group + And I select "Administrators" from "Viewer Groups" + And I press the "Save" button + Then pages should not be editable by "Content Authors" + But pages should be editable by "Administrators" - \ No newline at end of file From 86301e627b62431f4176aade675c98aeba68079e Mon Sep 17 00:00:00 2001 From: Sriram Venkatesh Date: Fri, 29 Nov 2013 16:44:22 +1300 Subject: [PATCH 08/11] NEW STEP: Pages editable by and renamed manage page permissions feature file --- .../features/bootstrap/FeatureContext.php | 1 - .../Cms/Test/Behaviour/FixtureContext.php | 35 +++++++++++++++---- ...eature => manage-page-permissions.feature} | 14 ++++---- 3 files changed, 34 insertions(+), 16 deletions(-) rename tests/behat/features/{manage-page-permisions.feature => manage-page-permissions.feature} (84%) diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 579ea3bd..371d0986 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -47,5 +47,4 @@ class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureConte } } - } diff --git a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php index 7c2ac887..207d4339 100644 --- a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php @@ -21,7 +21,7 @@ require_once 'PHPUnit/Framework/Assert/Functions.php'; */ class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext { - /** + /** * Find or create a redirector page and link to another existing page. * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1" * @@ -30,13 +30,13 @@ class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) { $class = 'RedirectorPage'; $targetClass = $this->convertTypeToClass($targetType); - + $targetObj = $this->fixtureFactory->get($targetClass, $targetId); - if(!$targetObj) $targetObj = $this->fixtureFactory->get($targetClass, $targetId); - + if (!$targetObj) $targetObj = $this->fixtureFactory->get($targetClass, $targetId); + $fields = array('LinkToID' => $targetObj->ID); $obj = $this->fixtureFactory->get($class, $id); - if($obj) { + if ($obj) { $obj->update($fields); } else { $obj = $this->fixtureFactory->createObject($class, $id, $fields); @@ -44,5 +44,26 @@ class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext $obj->write(); $obj->publish('Stage', 'Live'); } - -} \ No newline at end of file + + /** + * + * Check if the user can edit a page + * + * Example: Then pages should be editable by "Admin" + * Then pages should not be editable by "Admin" + * + * @Then /^pages should( not? |\s*)be editable by "([^"]*)"$/ + */ + public function pagesShouldBeEditableBy($negative, $member){ + $edit = '"/admin/pages/edit"'; + $editable = 'I should'.$negative.'see an edit page form'; + + return array( + new Step\Given('I am not logged in'), + new Step\Given('I am logged in with "'.$member.'" permissions'), + new Step\Given('I go to '.$edit), + new Step\Given($editable), + new Step\Then('I am on the homepage') + ); + } +} diff --git a/tests/behat/features/manage-page-permisions.feature b/tests/behat/features/manage-page-permissions.feature similarity index 84% rename from tests/behat/features/manage-page-permisions.feature rename to tests/behat/features/manage-page-permissions.feature index f751f3c7..4fada427 100644 --- a/tests/behat/features/manage-page-permisions.feature +++ b/tests/behat/features/manage-page-permissions.feature @@ -43,18 +43,16 @@ Scenario: I can limit global view permissions to certain groups And I go to the homepage Then I should see "Welcome" -@todo Scenario: I can limit global edit permissions to logged-in users - Given I select "Logged-in users" in "Who can edit pages on this site?" input group + Given I select "Anyone who can log-in to the CMS" from "Who can edit pages on this site?" input group And I press the "Save" button - Then pages should be editable by "Content Authors" - And pages should be editable by "Administrators" + Then pages should be editable by "AUTHOR" + And pages should be editable by "ADMIN" -@todo Scenario: I can limit global edit permissions to certain groups Given I select "Only these people (choose from list)" from "Who can edit pages on this site?" input group - And I select "Administrators" from "Viewer Groups" + And I select "ADMIN group" from "Viewer Groups" And I press the "Save" button - Then pages should not be editable by "Content Authors" - But pages should be editable by "Administrators" + Then pages should not be editable by "AUTHOR" + But pages should be editable by "ADMIN" From bd5f631af6f5ea1eaaa4474953b7d7d2649c7c09 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 30 Nov 2013 14:12:01 +0100 Subject: [PATCH 09/11] Reload "Settings" form on save (fixes #895) Regression from 920da0d1202ec403c193a0b282f5379bc415c287 --- templates/Includes/CMSSettingsController_Content.ss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/Includes/CMSSettingsController_Content.ss b/templates/Includes/CMSSettingsController_Content.ss index 1bda4c6a..058c52b0 100644 --- a/templates/Includes/CMSSettingsController_Content.ss +++ b/templates/Includes/CMSSettingsController_Content.ss @@ -1,4 +1,4 @@ -
+
<% with $EditForm %> From ec41cb38ce33444e440109ddda0418175c043ff8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 30 Nov 2013 14:12:19 +0100 Subject: [PATCH 10/11] ValidationException support in CMS "Settings" UI --- code/controllers/CMSSettingsController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php index a86ad860..beec22fd 100644 --- a/code/controllers/CMSSettingsController.php +++ b/code/controllers/CMSSettingsController.php @@ -77,7 +77,13 @@ class CMSSettingsController extends LeftAndMain { public function save_siteconfig($data, $form) { $siteConfig = SiteConfig::current_site_config(); $form->saveInto($siteConfig); - $siteConfig->write(); + + try { + $siteConfig->write(); + } catch(ValidationException $ex) { + $form->sessionMessage($ex->getResult()->message(), 'bad'); + return $this->getResponseNegotiator()->respond($this->request); + } $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.'))); return $this->getResponseNegotiator()->respond($this->request); From 78b9ef2df32ee7d62b72513670c3d013841c9d49 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 Dec 2013 18:36:17 +0100 Subject: [PATCH 11/11] More specific Behat assertion for page editability --- .../SilverStripe/Cms/Test/Behaviour/FixtureContext.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php index 207d4339..bd816ae7 100644 --- a/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/Cms/Test/Behaviour/FixtureContext.php @@ -55,14 +55,13 @@ class FixtureContext extends \SilverStripe\BehatExtension\Context\FixtureContext * @Then /^pages should( not? |\s*)be editable by "([^"]*)"$/ */ public function pagesShouldBeEditableBy($negative, $member){ - $edit = '"/admin/pages/edit"'; - $editable = 'I should'.$negative.'see an edit page form'; + $page = \Page::get()->First(); return array( new Step\Given('I am not logged in'), - new Step\Given('I am logged in with "'.$member.'" permissions'), - new Step\Given('I go to '.$edit), - new Step\Given($editable), + new Step\Given('I am logged in with "' . $member . '" permissions'), + new Step\Given('I go to "/admin/pages/edit/show/' . $page->ID . '"'), + new Step\Given('I should' . $negative . 'see a "Page name" field'), new Step\Then('I am on the homepage') ); }