mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Convert behat PHP to SS coding conventions
This commit is contained in:
parent
c3b7afbdb1
commit
34c8fb22cb
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
|
||||
*/
|
||||
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) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user