mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
5d3af16aaf
- moving all phpunit tests into tests/php - moving all extensions from _config.php into config.yml and removing obsolete _config.php - moving GridFieldSubsiteDetailForm_ItemRequest into own file (cherry picked from commit ee02828)
118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Subsites\Tests\Behaviour;
|
|
|
|
if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) {
|
|
return;
|
|
}
|
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
|
use SilverStripe\BehatExtension\Context\BasicContext;
|
|
use SilverStripe\BehatExtension\Context\LoginContext;
|
|
use SilverStripe\BehatExtension\Context\FixtureContext;
|
|
use SilverStripe\Framework\Test\Behaviour\CmsFormsContext;
|
|
use SilverStripe\Framework\Test\Behaviour\CmsUiContext;
|
|
use SilverStripe\Cms\Test\Behaviour;
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
use SilverStripe\Core\ClassInfo;
|
|
use SilverStripe\Core\Injector\Injector;
|
|
use SilverStripe\Dev\BehatFixtureFactory;
|
|
use SilverStripe\Dev\FixtureBlueprint;
|
|
use SilverStripe\Dev\FixtureFactory;
|
|
use SilverStripe\Security\Member;
|
|
|
|
// 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.
|
|
*/
|
|
class FeatureContext extends SilverStripeContext
|
|
{
|
|
/**
|
|
* @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)
|
|
*/
|
|
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));
|
|
|
|
$fixtureContext = new FixtureContext($parameters);
|
|
$fixtureContext->setFixtureFactory($this->getFixtureFactory());
|
|
$this->useContext('FixtureContext', $fixtureContext);
|
|
|
|
// Use blueprints to set user name from identifier
|
|
$factory = $fixtureContext->getFixtureFactory();
|
|
$blueprint = Injector::inst()->create(FixtureBlueprint::class, Member::class);
|
|
$blueprint->addCallback('beforeCreate', function ($identifier, &$data, &$fixtures) {
|
|
if (!isset($data['FirstName'])) {
|
|
$data['FirstName'] = $identifier;
|
|
}
|
|
});
|
|
$factory->define(Member::class, $blueprint);
|
|
|
|
// Auto-publish pages
|
|
foreach (ClassInfo::subclassesFor(SiteTree::class) as $id => $class) {
|
|
$blueprint = Injector::inst()->create(FixtureBlueprint::class, $class);
|
|
$blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
|
|
$obj->publish('Stage', 'Live');
|
|
});
|
|
$factory->define($class, $blueprint);
|
|
}
|
|
}
|
|
|
|
public function setMinkParameters(array $parameters)
|
|
{
|
|
parent::setMinkParameters($parameters);
|
|
|
|
if (isset($parameters['files_path'])) {
|
|
$this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return FixtureFactory
|
|
*/
|
|
public function getFixtureFactory()
|
|
{
|
|
if (!$this->fixtureFactory) {
|
|
$this->fixtureFactory = Injector::inst()->create(BehatFixtureFactory::class);
|
|
}
|
|
|
|
return $this->fixtureFactory;
|
|
}
|
|
|
|
public function setFixtureFactory(FixtureFactory $factory)
|
|
{
|
|
$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);
|
|
// }
|
|
//
|
|
}
|