1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Sergii Bondarenko, <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
namespace Drupal\TqExtension\ServiceContainer; |
6
|
|
|
|
7
|
|
|
use Behat\EnvironmentLoader; |
8
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
9
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class TqExtension. |
15
|
|
|
* |
16
|
|
|
* @package Drupal\TqExtension\ServiceContainer |
17
|
|
|
*/ |
18
|
|
|
class TqExtension implements Extension |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritDoc} |
22
|
|
|
*/ |
23
|
20 |
|
public function getConfigKey() |
24
|
|
|
{ |
25
|
20 |
|
return 'tq'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritDoc} |
30
|
|
|
*/ |
31
|
4 |
|
public function initialize(ExtensionManager $extensionManager) |
32
|
|
|
{ |
33
|
4 |
|
if (null === $extensionManager->getExtension('debug')) { |
34
|
4 |
|
$extensionManager->activateExtension('Behat\DebugExtension'); |
35
|
4 |
|
} |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
4 |
|
public function load(ContainerBuilder $container, array $config) |
42
|
|
|
{ |
43
|
4 |
|
$loader = new EnvironmentLoader($this, $container, $config); |
44
|
4 |
|
$loader->load(); |
45
|
4 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
* |
50
|
|
|
* @see EnvironmentExtension::getEnvironmentReaderId() |
51
|
|
|
*/ |
52
|
4 |
|
public function process(ContainerBuilder $container) |
53
|
|
|
{ |
54
|
4 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
* |
59
|
|
|
* @link http://symfony.com/doc/current/components/config/definition.html |
60
|
|
|
* |
61
|
|
|
* @example |
62
|
|
|
* Drupal\TqExtension: |
63
|
|
|
* wait_for_redirect: 60 |
64
|
|
|
* email_account_strings: get_account_strings_for_email |
65
|
|
|
* email_accounts: |
66
|
|
|
* account_alias: |
67
|
|
|
* imap: imap.gmail.com:993/imap/ssl |
68
|
|
|
* email: [email protected] |
69
|
|
|
* password: p4sswDstr_1 |
70
|
|
|
* administrator: |
71
|
|
|
* imap: imap.gmail.com:993/imap/ssl |
72
|
|
|
* email: [email protected] |
73
|
|
|
* password: p4sswDstr_2 |
74
|
|
|
*/ |
75
|
8 |
|
public function configure(ArrayNodeDefinition $builder) |
76
|
|
|
{ |
77
|
4 |
|
$config = $builder->children(); |
78
|
|
|
|
79
|
|
|
foreach ([ |
80
|
|
|
'wait_for_redirect' => [ |
81
|
4 |
|
'defaultValue' => 30, |
82
|
4 |
|
'info' => 'The timeout (in seconds) for waiting opening a page', |
83
|
4 |
|
], |
84
|
|
|
'wait_for_email' => [ |
85
|
4 |
|
'defaultValue' => 30, |
86
|
4 |
|
'info' => 'This timeout will be used if you checking an email via IMAP', |
87
|
4 |
|
], |
88
|
|
|
'email_account_strings' => [ |
89
|
4 |
|
'defaultValue' => '', |
90
|
4 |
|
'info' => 'See detailed description in "docs/examples/EMAIL.md"', |
91
|
4 |
|
], |
92
|
4 |
|
] as $scalarNode => $data) { |
93
|
8 |
|
$config = $config->scalarNode($scalarNode) |
94
|
4 |
|
->defaultValue($data['defaultValue']) |
95
|
4 |
|
->info($data['info']) |
96
|
4 |
|
->end(); |
97
|
4 |
|
} |
98
|
|
|
|
99
|
4 |
|
$config = $config->arrayNode('email_accounts') |
100
|
4 |
|
->requiresAtLeastOneElement() |
101
|
4 |
|
->prototype('array') |
102
|
8 |
|
->children(); |
103
|
|
|
|
104
|
|
|
foreach ([ |
105
|
4 |
|
'imap' => 'IMAP url without parameters. For example: imap.gmail.com:993/imap/ssl', |
106
|
4 |
|
'username' => 'Login from an e-mail account', |
107
|
4 |
|
'password' => 'Password from an e-mail account', |
108
|
4 |
|
] as $scalarNode => $info) { |
109
|
4 |
|
$config = $config->scalarNode($scalarNode) |
110
|
4 |
|
->isRequired() |
111
|
4 |
|
->cannotBeEmpty() |
112
|
4 |
|
->info($info) |
113
|
4 |
|
->end(); |
114
|
4 |
|
} |
115
|
|
|
|
116
|
4 |
|
$config->end()->end()->end()->end(); |
117
|
4 |
|
} |
118
|
|
|
} |
119
|
|
|
|