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