|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NuvoleWeb\Drupal\DrupalExtension\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Mink\Exception\ExpectationException; |
|
6
|
|
|
use Behat\Mink\Exception\UnsupportedDriverActionException; |
|
7
|
|
|
use NuvoleWeb\Drupal\DrupalExtension\Context\RawMinkContext; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Autocomplete step definitions. |
|
11
|
|
|
*/ |
|
12
|
|
|
class AutocompleteContext extends RawMinkContext { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Fill out autocomplete fields based on gist. |
|
16
|
|
|
* |
|
17
|
|
|
* @When I fill in the autocomplete :autocomplete with :text |
|
18
|
|
|
*/ |
|
19
|
|
|
public function fillInDrupalAutocomplete($locator, $text) { |
|
20
|
|
|
|
|
21
|
|
|
$session = $this->getSession(); |
|
22
|
|
|
$el = $session->getPage()->findField($locator); |
|
23
|
|
|
|
|
24
|
|
|
if (empty($el)) { |
|
25
|
|
|
throw new ExpectationException('No such autocomplete element ' . $locator, $session); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// Set the text and trigger the autocomplete with a space keystroke. |
|
29
|
|
|
$el->setValue($text); |
|
30
|
|
|
|
|
31
|
|
|
try { |
|
32
|
|
|
$el->keyDown(' '); |
|
33
|
|
|
$el->keyUp(' '); |
|
34
|
|
|
|
|
35
|
|
|
// Wait for ajax. |
|
36
|
|
|
$this->getSession()->wait(1000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'); |
|
37
|
|
|
// Wait a second, just to be sure. |
|
38
|
|
|
sleep(1); |
|
39
|
|
|
|
|
40
|
|
|
// Select the autocomplete popup with the name we are looking for. |
|
41
|
|
|
$popup = $session->getPage()->find('xpath', "//ul[contains(@class, 'ui-autocomplete')]/li/a[text() = '{$text}']"); |
|
42
|
|
|
|
|
43
|
|
|
if (empty($popup)) { |
|
44
|
|
|
throw new ExpectationException('No such option ' . $text . ' in ' . $locator, $session); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// Clicking on the popup fills the autocomplete properly. |
|
48
|
|
|
$popup->click(); |
|
49
|
|
|
} |
|
50
|
|
|
catch (UnsupportedDriverActionException $e) { |
|
51
|
|
|
// So javascript is not supported. |
|
52
|
|
|
// We did set the value correctly, so Drupal will figure it out. |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|