silverstripe-framework/tests/behat/features/bootstrap/FeatureContext.php

74 lines
2.3 KiB
PHP
Raw Normal View History

<?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;
/**
* Features context
*
* Context automatically loaded by Behat.
* Uses subcontexts to extend functionality.
*/
class FeatureContext extends SilverStripeContext {
2014-08-15 08:53:05 +02:00
/**
* @var FixtureFactory
*/
protected $fixtureFactory;
/**
* Initializes context.
* Every scenario gets it's own context object.
*
2013-08-21 11:27:16 +02:00
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters) {
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));
2013-10-21 00:49:31 +02:00
$this->useContext('EmailContext', new EmailContext($parameters));
$fixtureContext = new FixtureContext($parameters);
$fixtureContext->setFixtureFactory($this->getFixtureFactory());
$this->useContext('FixtureContext', $fixtureContext);
// Use blueprints to set user name from identifier
2013-08-21 11:27:16 +02:00
$factory = $fixtureContext->getFixtureFactory();
2016-06-23 01:37:22 +02:00
$blueprint = \Injector::inst()->create('FixtureBlueprint', 'SilverStripe\\Security\\Member');
2013-08-21 11:27:16 +02:00
$blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) {
if(!isset($data['FirstName'])) $data['FirstName'] = $identifier;
});
2016-06-23 01:37:22 +02:00
$factory->define('SilverStripe\\Security\\Member', $blueprint);
}
public function setMinkParameters(array $parameters) {
2013-08-21 11:27:16 +02:00
parent::setMinkParameters($parameters);
2014-08-15 08:53:05 +02:00
2013-08-21 11:27:16 +02:00
if(isset($parameters['files_path'])) {
2014-08-15 08:53:05 +02:00
$this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']);
2013-08-21 11:27:16 +02:00
}
}
/**
* @return FixtureFactory
*/
public function getFixtureFactory() {
if(!$this->fixtureFactory) {
$this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory');
}
return $this->fixtureFactory;
}
public function setFixtureFactory(FixtureFactory $factory) {
$this->fixtureFactory = $factory;
}
}