From 14d74f7ae369483edab421b679d39c3c2955e888 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 7 Mar 2016 18:12:27 +1300 Subject: [PATCH] API Refactor for removal of CMSForm class --- .travis.yml | 2 +- code/controller/SiteConfigLeftAndMain.php | 18 ++++++++++++++++-- composer.json | 4 ++-- .../bootstrap/Context/FeatureContext.php | 6 ------ .../Test/Behaviour/FixtureContext.php | 4 ---- .../SiteConfig/Test/Behaviour/ThemeContext.php | 10 +++------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9433db17..f85e0a113 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_script: - composer self-update || true - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - "if [ \"$BEHAT_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi" - - "if [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension,silverstripe/cms; fi" + - "if [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension:~2,silverstripe/cms; fi" - cd ~/builds/ss - php ~/travis-support/travis_setup_selenium.php --if-env BEHAT_TEST - php ~/travis-support/travis_setup_php54_webserver.php --if-env BEHAT_TEST diff --git a/code/controller/SiteConfigLeftAndMain.php b/code/controller/SiteConfigLeftAndMain.php index 7f4a33038..e18f31087 100644 --- a/code/controller/SiteConfigLeftAndMain.php +++ b/code/controller/SiteConfigLeftAndMain.php @@ -63,10 +63,24 @@ public function getEditForm($id = null, $fields = null) } $actions = $siteConfig->getCMSActions(); - $form = CMSForm::create( + $negotiator = $this->getResponseNegotiator(); + /** @var Form $form */ + $form = Form::create( $this, 'EditForm', $fields, $actions, $validator )->setHTMLID('Form_EditForm'); - $form->setResponseNegotiator($this->getResponseNegotiator()); + $form->setValidationResponseCallback(function() use ($negotiator, $form) { + $request = $this->getRequest(); + if($request->isAjax() && $negotiator) { + $form->setupFormErrors(); + $result = $form->forTemplate(); + + return $negotiator->respond($request, array( + 'CurrentForm' => function() use($result) { + return $result; + } + )); + } + }); $form->addExtraClass('cms-content center cms-edit-form'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); diff --git a/composer.json b/composer.json index e1e13fbbb..4ab288435 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "require": { "silverstripe/framework": "^4.0" }, - "extra": { - "installer-name": "siteconfig" + "require-dev": { + "phpunit/PHPUnit": "~4.8" }, "minimum-stability": "dev", "autoload": { diff --git a/tests/behat/features/bootstrap/Context/FeatureContext.php b/tests/behat/features/bootstrap/Context/FeatureContext.php index d8b312177..c47c38b9f 100644 --- a/tests/behat/features/bootstrap/Context/FeatureContext.php +++ b/tests/behat/features/bootstrap/Context/FeatureContext.php @@ -6,14 +6,8 @@ use SilverStripe\BehatExtension\Context\BasicContext; use SilverStripe\BehatExtension\Context\LoginContext; use SilverStripe\BehatExtension\Context\FixtureContext; -use SilverStripe\Framework\Test\Behaviour\CmsFormsContext; -use SilverStripe\Framework\Test\Behaviour\CmsUiContext; use SilverStripe\Cms\Test\Behaviour; -// PHPUnit -require_once 'PHPUnit/Autoload.php'; -require_once 'PHPUnit/Framework/Assert/Functions.php'; - /** * Features context * diff --git a/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/FixtureContext.php b/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/FixtureContext.php index effb3faaa..a731c3111 100644 --- a/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/FixtureContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/FixtureContext.php @@ -12,10 +12,6 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; -// PHPUnit -require_once 'PHPUnit/Autoload.php'; -require_once 'PHPUnit/Framework/Assert/Functions.php'; - /** * Context used to create fixtures in the SilverStripe ORM. */ diff --git a/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php b/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php index a3ca840dd..80f4ea4e6 100644 --- a/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php +++ b/tests/behat/features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php @@ -12,10 +12,6 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; -// PHPUnit -require_once 'PHPUnit/Autoload.php'; -require_once 'PHPUnit/Framework/Assert/Functions.php'; - /** * Context used to create fixtures in the SilverStripe ORM. */ @@ -26,7 +22,7 @@ class ThemeContext extends BehatContext /** * Create a test theme - * + * * @Given /^a theme "(?[^"]+)"/ */ public function stepCreateTheme($theme) @@ -42,7 +38,7 @@ public function stepCreateTheme($theme) /** * Create a template within a test theme - * + * * @Given /^a template "(?