2014-03-27 05:11:50 +01:00
|
|
|
<?php
|
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests\Behaviour;
|
2014-03-27 05:11:50 +01:00
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
2017-05-24 15:26:28 +02:00
|
|
|
use SilverStripe\BehatExtension\Context\BasicContext;
|
|
|
|
use SilverStripe\BehatExtension\Context\LoginContext;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\BehatExtension\Context\FixtureContext;
|
|
|
|
use SilverStripe\Framework\Test\Behaviour\CmsFormsContext;
|
2017-05-29 13:44:19 +02:00
|
|
|
use SilverStripe\Framework\Test\Behaviour\CmsUiContext;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Cms\Test\Behaviour;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
2017-05-24 15:26:28 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Dev\BehatFixtureFactory;
|
|
|
|
use SilverStripe\Dev\FixtureBlueprint;
|
|
|
|
use SilverStripe\Dev\FixtureFactory;
|
|
|
|
use SilverStripe\Security\Member;
|
2014-03-27 05:11:50 +01:00
|
|
|
|
|
|
|
// PHPUnit
|
|
|
|
require_once 'PHPUnit/Autoload.php';
|
|
|
|
require_once 'PHPUnit/Framework/Assert/Functions.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Features context
|
|
|
|
*
|
|
|
|
* Context automatically loaded by Behat.
|
|
|
|
* Uses subcontexts to extend functionality.
|
|
|
|
*/
|
2017-05-24 15:26:28 +02:00
|
|
|
class FeatureContext extends SilverStripeContext
|
2017-05-29 13:42:42 +02:00
|
|
|
{
|
2014-03-27 05:11:50 +01:00
|
|
|
/**
|
|
|
|
* @var FixtureFactory
|
|
|
|
*/
|
|
|
|
protected $fixtureFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes context.
|
|
|
|
* Every scenario gets it's own context object.
|
|
|
|
*
|
|
|
|
* @param array $parameters context parameters (set them up through behat.yml)
|
|
|
|
*/
|
2017-05-24 15:26:28 +02:00
|
|
|
public function __construct(array $parameters)
|
|
|
|
{
|
2014-03-27 05:11:50 +01:00
|
|
|
parent::__construct($parameters);
|
|
|
|
|
|
|
|
$this->useContext('BasicContext', new BasicContext($parameters));
|
|
|
|
$this->useContext('LoginContext', new LoginContext($parameters));
|
|
|
|
$this->useContext('CmsFormsContext', new CmsFormsContext($parameters));
|
|
|
|
$this->useContext('CmsUiContext', new CmsUiContext($parameters));
|
|
|
|
|
|
|
|
$fixtureContext = new FixtureContext($parameters);
|
|
|
|
$fixtureContext->setFixtureFactory($this->getFixtureFactory());
|
|
|
|
$this->useContext('FixtureContext', $fixtureContext);
|
|
|
|
|
|
|
|
// Use blueprints to set user name from identifier
|
|
|
|
$factory = $fixtureContext->getFixtureFactory();
|
2017-05-29 13:42:42 +02:00
|
|
|
$blueprint = Injector::inst()->create(FixtureBlueprint::class, Member::class);
|
2017-05-24 15:26:28 +02:00
|
|
|
$blueprint->addCallback('beforeCreate', function ($identifier, &$data, &$fixtures) {
|
|
|
|
if (!isset($data['FirstName'])) {
|
|
|
|
$data['FirstName'] = $identifier;
|
|
|
|
}
|
2014-03-27 05:11:50 +01:00
|
|
|
});
|
2017-05-29 13:42:42 +02:00
|
|
|
$factory->define(Member::class, $blueprint);
|
2014-03-27 05:11:50 +01:00
|
|
|
|
|
|
|
// Auto-publish pages
|
2017-05-29 13:42:42 +02:00
|
|
|
foreach (ClassInfo::subclassesFor(SiteTree::class) as $id => $class) {
|
|
|
|
$blueprint = Injector::inst()->create(FixtureBlueprint::class, $class);
|
2017-05-24 15:26:28 +02:00
|
|
|
$blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
|
2014-03-27 05:11:50 +01:00
|
|
|
$obj->publish('Stage', 'Live');
|
|
|
|
});
|
|
|
|
$factory->define($class, $blueprint);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2014-03-27 05:11:50 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
public function setMinkParameters(array $parameters)
|
|
|
|
{
|
2014-03-27 05:11:50 +01:00
|
|
|
parent::setMinkParameters($parameters);
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
if (isset($parameters['files_path'])) {
|
|
|
|
$this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']);
|
2014-03-27 05:11:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FixtureFactory
|
|
|
|
*/
|
2017-05-24 15:26:28 +02:00
|
|
|
public function getFixtureFactory()
|
|
|
|
{
|
|
|
|
if (!$this->fixtureFactory) {
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->fixtureFactory = Injector::inst()->create(BehatFixtureFactory::class);
|
2014-03-27 05:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->fixtureFactory;
|
|
|
|
}
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
public function setFixtureFactory(FixtureFactory $factory)
|
|
|
|
{
|
2014-03-27 05:11:50 +01:00
|
|
|
$this->fixtureFactory = $factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Place your definition and hook methods here:
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * @Given /^I have done something with "([^"]*)"$/
|
|
|
|
// */
|
|
|
|
// public function iHaveDoneSomethingWith($argument) {
|
|
|
|
// $container = $this->kernel->getContainer();
|
|
|
|
// $container->get('some_service')->doSomethingWith($argument);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
}
|