1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\BehatExtension; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
9
|
|
|
|
10
|
|
|
use Behat\Behat\Extension\ExtensionInterface; |
11
|
|
|
|
12
|
|
|
/* |
13
|
|
|
* This file is part of the SilverStripe\BehatExtension |
14
|
|
|
* |
15
|
|
|
* (c) Michał Ochman <[email protected]> |
16
|
|
|
* |
17
|
|
|
* This source file is subject to the MIT license that is bundled |
18
|
|
|
* with this source code in the file LICENSE. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* SilverStripe extension for Behat class. |
23
|
|
|
* |
24
|
|
|
* @author Michał Ochman <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class Extension implements ExtensionInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Loads a specific configuration. |
30
|
|
|
* |
31
|
|
|
* @param array $config Extension configuration hash (from behat.yml) |
32
|
|
|
* @param ContainerBuilder $container ContainerBuilder instance |
33
|
|
|
*/ |
34
|
|
|
public function load(array $config, ContainerBuilder $container) |
35
|
|
|
{ |
36
|
|
|
if (!isset($config['framework_path'])) { |
37
|
|
|
throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services')); |
41
|
|
|
$loader->load('silverstripe.yml'); |
42
|
|
|
|
43
|
|
|
$behatBasePath = $container->getParameter('behat.paths.base'); |
44
|
|
|
$config['framework_path'] = realpath(sprintf( |
45
|
|
|
'%s%s%s', |
46
|
|
|
rtrim($behatBasePath, DIRECTORY_SEPARATOR), |
47
|
|
|
DIRECTORY_SEPARATOR, |
48
|
|
|
ltrim($config['framework_path'], DIRECTORY_SEPARATOR) |
49
|
|
|
)); |
50
|
|
|
if (!file_exists($config['framework_path']) || !is_dir($config['framework_path'])) { |
51
|
|
|
throw new \InvalidArgumentException('Path specified as `framework_path` either doesn\'t exist or is not a directory'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']); |
55
|
|
|
$container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']); |
56
|
|
|
$container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']); |
57
|
|
|
$container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']); |
58
|
|
|
$container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']); |
59
|
|
|
if (isset($config['ajax_steps'])) { |
60
|
|
|
$container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']); |
61
|
|
|
} |
62
|
|
|
if (isset($config['region_map'])) { |
63
|
|
|
$container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
public function getCompilerPasses() |
71
|
|
|
{ |
72
|
|
|
return array( |
73
|
|
|
new Compiler\CoreInitializationPass() |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Setups configuration for current extension. |
79
|
|
|
* |
80
|
|
|
* @param ArrayNodeDefinition $builder |
81
|
|
|
*/ |
82
|
|
|
public function getConfig(ArrayNodeDefinition $builder) |
83
|
|
|
{ |
84
|
|
|
$builder-> |
85
|
|
|
children()-> |
86
|
|
|
scalarNode('framework_path')-> |
87
|
|
|
defaultValue('framework')-> |
88
|
|
|
end()-> |
89
|
|
|
scalarNode('screenshot_path')-> |
90
|
|
|
defaultNull()-> |
91
|
|
|
end()-> |
92
|
|
|
arrayNode('region_map')-> |
93
|
|
|
useAttributeAsKey('key')-> |
94
|
|
|
prototype('variable')->end()-> |
95
|
|
|
end()-> |
96
|
|
|
scalarNode('admin_url')-> |
97
|
|
|
defaultValue('/admin/')-> |
98
|
|
|
end()-> |
99
|
|
|
scalarNode('login_url')-> |
100
|
|
|
defaultValue('/Security/login')-> |
101
|
|
|
end()-> |
102
|
|
|
scalarNode('ajax_timeout')-> |
103
|
|
|
defaultValue(5000)-> |
104
|
|
|
end()-> |
105
|
|
|
arrayNode('ajax_steps')-> |
106
|
|
|
defaultValue(array( |
107
|
|
|
'go to', |
108
|
|
|
'follow', |
109
|
|
|
'press', |
110
|
|
|
'click', |
111
|
|
|
'submit' |
112
|
|
|
))-> |
113
|
|
|
prototype('scalar')-> |
114
|
|
|
end()-> |
115
|
|
|
end()-> |
116
|
|
|
end(); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|