2012-08-15 16:50:19 +02:00
|
|
|
<?php
|
|
|
|
|
2012-10-16 22:01:16 +02:00
|
|
|
namespace SilverStripe\BehatExtension;
|
2012-08-15 16:50:19 +02:00
|
|
|
|
2016-08-10 03:35:13 +02:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
2012-08-15 16:50:19 +02:00
|
|
|
|
2012-11-14 00:29:20 +01:00
|
|
|
use Behat\Behat\Extension\ExtensionInterface;
|
2012-08-15 16:50:19 +02:00
|
|
|
|
|
|
|
/*
|
2012-10-16 22:01:16 +02:00
|
|
|
* This file is part of the SilverStripe\BehatExtension
|
2012-08-15 16:50:19 +02:00
|
|
|
*
|
|
|
|
* (c) Michał Ochman <ochman.d.michal@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SilverStripe extension for Behat class.
|
|
|
|
*
|
|
|
|
* @author Michał Ochman <ochman.d.michal@gmail.com>
|
|
|
|
*/
|
2012-11-14 00:29:20 +01:00
|
|
|
class Extension implements ExtensionInterface
|
2012-08-15 16:50:19 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Loads a specific configuration.
|
|
|
|
*
|
|
|
|
* @param array $config Extension configuration hash (from behat.yml)
|
|
|
|
* @param ContainerBuilder $container ContainerBuilder instance
|
|
|
|
*/
|
|
|
|
public function load(array $config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
if (!isset($config['framework_path'])) {
|
|
|
|
throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension');
|
|
|
|
}
|
|
|
|
|
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
|
|
|
|
$loader->load('silverstripe.yml');
|
|
|
|
|
2012-11-15 18:12:21 +01:00
|
|
|
$behatBasePath = $container->getParameter('behat.paths.base');
|
2016-08-10 03:35:13 +02:00
|
|
|
$config['framework_path'] = realpath(sprintf(
|
|
|
|
'%s%s%s',
|
2012-11-15 18:12:21 +01:00
|
|
|
rtrim($behatBasePath, DIRECTORY_SEPARATOR),
|
2012-08-15 16:50:19 +02:00
|
|
|
DIRECTORY_SEPARATOR,
|
|
|
|
ltrim($config['framework_path'], DIRECTORY_SEPARATOR)
|
|
|
|
));
|
|
|
|
if (!file_exists($config['framework_path']) || !is_dir($config['framework_path'])) {
|
|
|
|
throw new \InvalidArgumentException('Path specified as `framework_path` either doesn\'t exist or is not a directory');
|
|
|
|
}
|
|
|
|
|
|
|
|
$container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']);
|
2012-11-14 00:29:20 +01:00
|
|
|
$container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']);
|
|
|
|
$container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']);
|
|
|
|
$container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']);
|
|
|
|
$container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']);
|
2012-08-15 16:50:19 +02:00
|
|
|
if (isset($config['ajax_steps'])) {
|
|
|
|
$container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
|
|
|
|
}
|
2014-03-19 02:53:00 +01:00
|
|
|
if (isset($config['region_map'])) {
|
2016-08-10 03:35:13 +02:00
|
|
|
$container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']);
|
2014-03-19 02:53:00 +01:00
|
|
|
}
|
2016-09-13 08:03:12 +02:00
|
|
|
$container->setParameter('behat.silverstripe_extension.bootstrap_file', $config['bootstrap_file']);
|
2012-08-15 16:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getCompilerPasses()
|
|
|
|
{
|
2013-10-18 17:00:07 +02:00
|
|
|
return array(
|
|
|
|
new Compiler\CoreInitializationPass()
|
|
|
|
);
|
2012-08-15 16:50:19 +02:00
|
|
|
}
|
2012-11-14 00:29:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setups configuration for current extension.
|
|
|
|
*
|
|
|
|
* @param ArrayNodeDefinition $builder
|
|
|
|
*/
|
2016-08-10 03:35:13 +02:00
|
|
|
public function getConfig(ArrayNodeDefinition $builder)
|
2012-11-14 00:29:20 +01:00
|
|
|
{
|
|
|
|
$builder->
|
|
|
|
children()->
|
|
|
|
scalarNode('framework_path')->
|
2013-05-09 16:26:24 +02:00
|
|
|
defaultValue('framework')->
|
2012-11-14 00:29:20 +01:00
|
|
|
end()->
|
|
|
|
scalarNode('screenshot_path')->
|
|
|
|
defaultNull()->
|
|
|
|
end()->
|
2014-03-19 02:53:00 +01:00
|
|
|
arrayNode('region_map')->
|
|
|
|
useAttributeAsKey('key')->
|
|
|
|
prototype('variable')->end()->
|
|
|
|
end()->
|
2012-11-14 00:29:20 +01:00
|
|
|
scalarNode('admin_url')->
|
|
|
|
defaultValue('/admin/')->
|
|
|
|
end()->
|
|
|
|
scalarNode('login_url')->
|
|
|
|
defaultValue('/Security/login')->
|
|
|
|
end()->
|
|
|
|
scalarNode('ajax_timeout')->
|
|
|
|
defaultValue(5000)->
|
|
|
|
end()->
|
2016-09-13 08:03:12 +02:00
|
|
|
scalarNode('bootstrap_file')->
|
|
|
|
defaultNull()->
|
|
|
|
end()->
|
2012-11-14 00:29:20 +01:00
|
|
|
arrayNode('ajax_steps')->
|
|
|
|
defaultValue(array(
|
|
|
|
'go to',
|
|
|
|
'follow',
|
|
|
|
'press',
|
|
|
|
'click',
|
|
|
|
'submit'
|
|
|
|
))->
|
|
|
|
prototype('scalar')->
|
|
|
|
end()->
|
|
|
|
end()->
|
|
|
|
end();
|
|
|
|
}
|
2012-08-15 16:50:19 +02:00
|
|
|
}
|