1 | <?php |
||
19 | trait AuthenticationTrait |
||
20 | { |
||
21 | /** |
||
22 | * Key to resolve identity from an environment |
||
23 | */ |
||
24 | public static $identityEnv = 'IDENTITY'; |
||
25 | |||
26 | /** |
||
27 | * Key to resolve credential from an environment |
||
28 | */ |
||
29 | public static $credentialEnv = 'CREDENTIAL'; |
||
30 | |||
31 | /** |
||
32 | * Login |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $identity; |
||
37 | |||
38 | /** |
||
39 | * Password |
||
40 | */ |
||
41 | protected $credential; |
||
42 | |||
43 | /** |
||
44 | * Login input name |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | public $identityName = 'identity'; |
||
49 | |||
50 | /** |
||
51 | * Password input name |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | public $credentialName = 'credential'; |
||
56 | |||
57 | /** |
||
58 | * CSS selector of element to assert after successful authentication |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $authSuccessLocator; |
||
63 | |||
64 | /** |
||
65 | * Enters the input value |
||
66 | * |
||
67 | * @param string $name |
||
68 | * @param string $value |
||
69 | * @param callable|false|null $callback |
||
70 | * @return $this |
||
71 | */ |
||
72 | abstract protected function enterInput($name, $value, $callback = null); |
||
73 | |||
74 | /** |
||
75 | * Wait for something, then do something else |
||
76 | * |
||
77 | * @param callable $action |
||
78 | * @param callable $callback |
||
79 | * @return $this |
||
80 | */ |
||
81 | abstract protected function waitFor(callable $action, callable $callback = null); |
||
82 | |||
83 | /** |
||
84 | * Returns element by CSS selector |
||
85 | * |
||
86 | * @param string $selector |
||
87 | * @return \PHPWebDriver_WebDriverElement |
||
88 | */ |
||
89 | abstract protected function elementByCssSelector($selector); |
||
90 | |||
91 | /** |
||
92 | * Resolve test identity from an environment variable |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | protected function getIdentity() |
||
108 | |||
109 | /** |
||
110 | * Resolve test credential from an environment variable |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function getCredential() |
||
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | * @throws RuntimeException Use setAuthSuccessLocator() first |
||
130 | */ |
||
131 | protected function getAuthSuccessLocator() |
||
138 | |||
139 | /** |
||
140 | * Set login for authentication |
||
141 | * |
||
142 | * @param string $identity |
||
143 | * @return $this |
||
144 | */ |
||
145 | protected function setIdentity($identity) |
||
150 | |||
151 | /** |
||
152 | * Set password for authentication |
||
153 | * |
||
154 | * @param string $credential |
||
155 | * @return $this |
||
156 | */ |
||
157 | protected function setCredential($credential) |
||
162 | |||
163 | /** |
||
164 | * @param string $locator CSS selector |
||
165 | * @return $this |
||
166 | */ |
||
167 | protected function setAuthSuccessLocator($locator) |
||
172 | |||
173 | /** |
||
174 | * Authenticate and check for success |
||
175 | * |
||
176 | * @return $this |
||
177 | */ |
||
178 | protected function authenticate(callable $callback = null) |
||
189 | |||
190 | /** |
||
191 | * Enters the password into input |
||
192 | * |
||
193 | * @param callable $callback |
||
194 | * @return $this |
||
195 | */ |
||
196 | protected function enterIdentity(callable $callback = null) |
||
201 | |||
202 | /** |
||
203 | * Enters the password into input |
||
204 | * |
||
205 | * @param callable $callback |
||
206 | * @return $this |
||
207 | */ |
||
208 | protected function enterCredential(callable $callback = null) |
||
213 | |||
214 | /** |
||
215 | * Check that we are authenticated successfuly |
||
216 | * |
||
217 | * @param callable $callback |
||
218 | * @return $this |
||
219 | */ |
||
220 | protected function waitToBeAuthenticated(callable $callback = null) |
||
230 | } |
||
231 |