silverstripe-behat-extension/src/SilverStripe/BehatExtension/Extension.php

123 lines
4.3 KiB
PHP
Raw Normal View History

2012-08-15 16:50:19 +02:00
<?php
namespace SilverStripe\BehatExtension;
2012-08-15 16:50:19 +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
use Behat\Behat\Extension\ExtensionInterface;
2012-08-15 16:50:19 +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>
*/
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');
$behatBasePath = $container->getParameter('behat.paths.base');
$config['framework_path'] = realpath(sprintf(
'%s%s%s',
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']);
$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'])) {
$container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']);
2014-03-19 02:53:00 +01:00
}
$container->setParameter('behat.silverstripe_extension.bootstrap_file', $config['bootstrap_file']);
2012-08-15 16:50:19 +02:00
}
/**
* @return array
*/
public function getCompilerPasses()
{
return array(
new Compiler\CoreInitializationPass()
);
2012-08-15 16:50:19 +02:00
}
/**
* Setups configuration for current extension.
*
* @param ArrayNodeDefinition $builder
*/
public function getConfig(ArrayNodeDefinition $builder)
{
$builder->
children()->
scalarNode('framework_path')->
defaultValue('framework')->
end()->
scalarNode('screenshot_path')->
defaultNull()->
end()->
2014-03-19 02:53:00 +01:00
arrayNode('region_map')->
useAttributeAsKey('key')->
prototype('variable')->end()->
end()->
scalarNode('admin_url')->
defaultValue('/admin/')->
end()->
scalarNode('login_url')->
defaultValue('/Security/login')->
end()->
scalarNode('ajax_timeout')->
defaultValue(5000)->
end()->
scalarNode('bootstrap_file')->
defaultNull()->
end()->
arrayNode('ajax_steps')->
defaultValue(array(
'go to',
'follow',
'press',
'click',
'submit'
))->
prototype('scalar')->
end()->
end()->
end();
}
2012-08-15 16:50:19 +02:00
}