Convert behat PHP to SS coding conventions

This commit is contained in:
Ingo Schommer 2013-11-15 11:44:56 +01:00
parent c3b7afbdb1
commit 34c8fb22cb
2 changed files with 63 additions and 66 deletions

View File

@ -3,12 +3,12 @@
namespace SilverStripe\Cms\Test\Behaviour; namespace SilverStripe\Cms\Test\Behaviour;
use SilverStripe\BehatExtension\Context\SilverStripeContext, use SilverStripe\BehatExtension\Context\SilverStripeContext,
SilverStripe\BehatExtension\Context\BasicContext, SilverStripe\BehatExtension\Context\BasicContext,
SilverStripe\BehatExtension\Context\LoginContext, SilverStripe\BehatExtension\Context\LoginContext,
SilverStripe\BehatExtension\Context\FixtureContext, SilverStripe\BehatExtension\Context\FixtureContext,
SilverStripe\Framework\Test\Behaviour\CmsFormsContext, SilverStripe\Framework\Test\Behaviour\CmsFormsContext,
SilverStripe\Framework\Test\Behaviour\CmsUiContext, SilverStripe\Framework\Test\Behaviour\CmsUiContext,
SilverStripe\Cms\Test\Behaviour; SilverStripe\Cms\Test\Behaviour;
// PHPUnit // PHPUnit
require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Autoload.php';
@ -20,33 +20,32 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
* Context automatically loaded by Behat. * Context automatically loaded by Behat.
* Uses subcontexts to extend functionality. * Uses subcontexts to extend functionality.
*/ */
class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext 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);
// Override existing fixture context with more specific one /**
$fixtureContext = new \SilverStripe\Cms\Test\Behaviour\FixtureContext($parameters); * Initializes context.
$fixtureContext->setFixtureFactory($this->getFixtureFactory()); * Every scenario gets it's own context object.
$this->useContext('FixtureContext', $fixtureContext); *
* @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 // Override existing fixture context with more specific one
$factory = $fixtureContext->getFixtureFactory(); $fixtureContext = new \SilverStripe\Cms\Test\Behaviour\FixtureContext($parameters);
foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { $fixtureContext->setFixtureFactory($this->getFixtureFactory());
$blueprint = \Injector::inst()->create('FixtureBlueprint', $class); $this->useContext('FixtureContext', $fixtureContext);
$blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) {
$obj->publish('Stage', 'Live');
});
$factory->define($class, $blueprint);
}
} // 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);
}
}
} }

View File

@ -3,14 +3,14 @@
namespace SilverStripe\Cms\Test\Behaviour; namespace SilverStripe\Cms\Test\Behaviour;
use Behat\Behat\Context\ClosuredContextInterface, use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext, Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step, Behat\Behat\Context\Step,
Behat\Behat\Event\StepEvent, Behat\Behat\Event\StepEvent,
Behat\Behat\Exception\PendingException, Behat\Behat\Exception\PendingException,
Behat\Mink\Driver\Selenium2Driver, Behat\Mink\Driver\Selenium2Driver,
Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode; Behat\Gherkin\Node\TableNode;
// PHPUnit // PHPUnit
require_once 'PHPUnit/Autoload.php'; 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. * 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. * 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" * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1"
* *
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/ * @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
*/ */
public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) {
{ $class = 'RedirectorPage';
$class = 'RedirectorPage'; $targetClass = $this->convertTypeToClass($targetType);
$targetClass = $this->convertTypeToClass($targetType);
$targetObj = $this->fixtureFactory->get($targetClass, $targetId);
$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);
$fields = array('LinkToID' => $targetObj->ID); $obj = $this->fixtureFactory->get($class, $id);
$obj = $this->fixtureFactory->get($class, $id); if($obj) {
if($obj) { $obj->update($fields);
$obj->update($fields); } else {
} else { $obj = $this->fixtureFactory->createObject($class, $id, $fields);
$obj = $this->fixtureFactory->createObject($class, $id, $fields); }
} $obj->write();
$obj->write(); $obj->publish('Stage', 'Live');
$obj->publish('Stage', 'Live'); }
}
} }