2012-11-09 19:15:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Cms\Test\Behaviour;
|
|
|
|
|
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext,
|
2013-11-15 11:44:56 +01:00
|
|
|
SilverStripe\BehatExtension\Context\BasicContext,
|
|
|
|
SilverStripe\BehatExtension\Context\LoginContext,
|
|
|
|
SilverStripe\BehatExtension\Context\FixtureContext,
|
|
|
|
SilverStripe\Framework\Test\Behaviour\CmsFormsContext,
|
|
|
|
SilverStripe\Framework\Test\Behaviour\CmsUiContext,
|
2016-06-16 06:57:19 +02:00
|
|
|
SilverStripe\Cms\Test\Behaviour,
|
|
|
|
SilverStripe\ORM\Versioning\Versioned;
|
2016-08-10 06:08:39 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2012-11-09 19:15:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Features context
|
|
|
|
*
|
|
|
|
* Context automatically loaded by Behat.
|
|
|
|
* Uses subcontexts to extend functionality.
|
|
|
|
*/
|
2013-11-15 11:44:56 +01:00
|
|
|
class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes context.
|
|
|
|
* Every scenario gets it's own context object.
|
|
|
|
*
|
2015-09-28 11:31:31 +02:00
|
|
|
* @param array $parameters context parameters (set them up through behat.yml)
|
2013-11-15 11:44:56 +01:00
|
|
|
*/
|
|
|
|
public function __construct(array $parameters) {
|
|
|
|
parent::__construct($parameters);
|
|
|
|
|
|
|
|
// Override existing fixture context with more specific one
|
|
|
|
$fixtureContext = new \SilverStripe\Cms\Test\Behaviour\FixtureContext($parameters);
|
|
|
|
$fixtureContext->setFixtureFactory($this->getFixtureFactory());
|
|
|
|
$this->useContext('FixtureContext', $fixtureContext);
|
|
|
|
|
2014-02-13 06:54:44 +01:00
|
|
|
// Add extra contexts with more steps
|
|
|
|
$this->useContext('ThemeContext', new \SilverStripe\Cms\Test\Behaviour\ThemeContext($parameters));
|
|
|
|
|
2013-11-15 11:44:56 +01:00
|
|
|
// Use blueprints which auto-publish all subclasses of SiteTree
|
|
|
|
$factory = $fixtureContext->getFixtureFactory();
|
2016-08-23 04:36:06 +02:00
|
|
|
foreach(ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree') as $id => $class) {
|
|
|
|
$blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', $class);
|
2013-11-15 11:44:56 +01:00
|
|
|
$blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) {
|
2016-08-10 06:08:39 +02:00
|
|
|
/** @var SiteTree $obj */
|
2016-06-16 06:57:19 +02:00
|
|
|
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2013-11-15 11:44:56 +01:00
|
|
|
});
|
|
|
|
$factory->define($class, $blueprint);
|
2016-01-06 00:42:07 +01:00
|
|
|
}
|
2013-11-15 11:44:56 +01:00
|
|
|
|
|
|
|
}
|
2012-11-09 19:15:54 +01:00
|
|
|
}
|