From 34c8fb22cb2751180e5235b17b2e630c899d7265 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 15 Nov 2013 11:44:56 +0100 Subject: [PATCH] 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