2012-11-09 19:16:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Framework\Test\Behaviour;
|
|
|
|
|
2016-01-25 16:17:57 +01:00
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
|
|
|
use SilverStripe\BehatExtension\Context\BasicContext;
|
|
|
|
use SilverStripe\BehatExtension\Context\LoginContext;
|
|
|
|
use SilverStripe\BehatExtension\Context\FixtureContext;
|
|
|
|
use SilverStripe\BehatExtension\Context\EmailContext;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2016-11-17 05:50:28 +01:00
|
|
|
use SilverStripe\Dev\BehatFixtureFactory;
|
|
|
|
use SilverStripe\Dev\FixtureFactory;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2012-11-09 19:16:16 +01:00
|
|
|
/**
|
|
|
|
* Features context
|
|
|
|
*
|
|
|
|
* Context automatically loaded by Behat.
|
|
|
|
* Uses subcontexts to extend functionality.
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class FeatureContext extends SilverStripeContext
|
|
|
|
{
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @var FixtureFactory
|
|
|
|
*/
|
|
|
|
protected $fixtureFactory;
|
2013-06-04 17:30:13 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
2013-06-04 17:30:13 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->useContext('BasicContext', new BasicContext($parameters));
|
|
|
|
$this->useContext('LoginContext', new LoginContext($parameters));
|
|
|
|
$this->useContext('CmsFormsContext', new CmsFormsContext($parameters));
|
|
|
|
$this->useContext('CmsUiContext', new CmsUiContext($parameters));
|
|
|
|
$this->useContext('EmailContext', new EmailContext($parameters));
|
2012-11-09 19:16:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$fixtureContext = new FixtureContext($parameters);
|
|
|
|
$fixtureContext->setFixtureFactory($this->getFixtureFactory());
|
|
|
|
$this->useContext('FixtureContext', $fixtureContext);
|
2013-06-05 11:40:36 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// Use blueprints to set user name from identifier
|
|
|
|
$factory = $fixtureContext->getFixtureFactory();
|
|
|
|
$blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', 'SilverStripe\\Security\\Member');
|
|
|
|
$blueprint->addCallback('beforeCreate', function ($identifier, &$data, &$fixtures) {
|
|
|
|
if (!isset($data['FirstName'])) {
|
|
|
|
$data['FirstName'] = $identifier;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$factory->define('SilverStripe\\Security\\Member', $blueprint);
|
|
|
|
}
|
2013-06-04 17:30:13 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function setMinkParameters(array $parameters)
|
|
|
|
{
|
|
|
|
parent::setMinkParameters($parameters);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
if (isset($parameters['files_path'])) {
|
|
|
|
/** @var FixtureContext $fixtureContext */
|
|
|
|
$fixtureContext = $this->getSubcontext('FixtureContext');
|
|
|
|
$fixtureContext->setFilesPath($parameters['files_path']);
|
|
|
|
}
|
|
|
|
}
|
2013-06-04 17:30:13 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @return FixtureFactory
|
|
|
|
*/
|
|
|
|
public function getFixtureFactory()
|
|
|
|
{
|
|
|
|
if (!$this->fixtureFactory) {
|
|
|
|
$this->fixtureFactory = Injector::inst()->create(BehatFixtureFactory::class);
|
|
|
|
}
|
|
|
|
return $this->fixtureFactory;
|
|
|
|
}
|
2013-06-04 17:30:13 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function setFixtureFactory(FixtureFactory $factory)
|
|
|
|
{
|
|
|
|
$this->fixtureFactory = $factory;
|
|
|
|
}
|
2012-11-09 19:16:16 +01:00
|
|
|
}
|