|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\DFExtension\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
|
6
|
|
|
use Drupal\Component\Utility\Html; |
|
7
|
|
|
use Drupal\DrupalExtension\Context\DrupalSubContextBase; |
|
8
|
|
|
use Drupal\DrupalExtension\Context\MinkContext; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Contains step definitions for working with entity browsers. |
|
12
|
|
|
*/ |
|
13
|
|
|
class EntityBrowserContext extends DrupalSubContextBase { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The Mink context. |
|
17
|
|
|
* |
|
18
|
|
|
* @var MinkContext |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $minkContext; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Gathers required contexts. |
|
24
|
|
|
* |
|
25
|
|
|
* @BeforeScenario |
|
26
|
|
|
*/ |
|
27
|
|
|
public function gatherContexts() { |
|
28
|
|
|
$this->minkContext = $this->getContext(MinkContext::class); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Submits the entity browser. |
|
33
|
|
|
* |
|
34
|
|
|
* @When I submit the entity browser |
|
35
|
|
|
*/ |
|
36
|
|
|
public function submit() { |
|
37
|
|
|
$session = $this->getSession(); |
|
38
|
|
|
|
|
39
|
|
|
// The entity browser frame will be destroyed, so we need to switch into |
|
40
|
|
|
// the main window and reach into the frame to submit the form. Ugh. |
|
41
|
|
|
$frame = $session->evaluateScript('frameElement.name'); |
|
42
|
|
|
$session->switchToWindow(); |
|
43
|
|
|
// @TODO: Make this smarter, because we can't be sure that #edit-submit |
|
44
|
|
|
// exists at all, or that it's the correct submit button. |
|
45
|
|
|
$session->executeScript('frames["' . $frame . '"].document.forms[0].querySelector("#edit-submit").click()'); |
|
46
|
|
|
sleep(10); |
|
47
|
|
|
$this->minkContext->iWaitForAjaxToFinish(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Opens an image browser for a particular field. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $field |
|
54
|
|
|
* The field label. |
|
55
|
|
|
* |
|
56
|
|
|
* @throws ElementNotFoundException |
|
57
|
|
|
* If the collapsible field element does not exist on the page. |
|
58
|
|
|
* |
|
59
|
|
|
* @When I open the :field image browser |
|
60
|
|
|
*/ |
|
61
|
|
|
public function openImageBrowser($field) { |
|
62
|
|
|
$session = $this->getSession(); |
|
63
|
|
|
|
|
64
|
|
|
/** @var UtilityContext $context */ |
|
65
|
|
|
$context = $this->getContext(UtilityContext::class); |
|
66
|
|
|
|
|
67
|
|
|
$details = $context->findCollapsible($field); |
|
68
|
|
|
if ($details) { |
|
69
|
|
|
$details->pressButton('Select Image(s)'); |
|
70
|
|
|
$this->minkContext->iWaitForAjaxToFinish(); |
|
71
|
|
|
$session->switchToIFrame('entity_browser_iframe_image_browser'); |
|
72
|
|
|
// This might be vestigial. |
|
73
|
|
|
sleep(10); |
|
74
|
|
|
} |
|
75
|
|
|
else { |
|
76
|
|
|
throw new ElementNotFoundException($session->getDriver(), 'collapsible element'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Selects an item in an entity browser view. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $n |
|
84
|
|
|
* The one-based index of the item to select. |
|
85
|
|
|
* @param string $browser_id |
|
86
|
|
|
* (optional) The entity browser ID. |
|
87
|
|
|
* |
|
88
|
|
|
* @When I select item :n |
|
89
|
|
|
* @When I select item :n from the entity browser |
|
90
|
|
|
* @When I select item :n from the :browser_id entity browser |
|
91
|
|
|
*/ |
|
92
|
|
|
public function selectItem($n, $browser_id = NULL) { |
|
93
|
|
|
if ($browser_id) { |
|
|
|
|
|
|
94
|
|
|
$selector = 'form#entity-browser-' . Html::cleanCssIdentifier($browser_id) . '-form'; |
|
95
|
|
|
} |
|
96
|
|
|
else { |
|
97
|
|
|
$selector = 'form[data-entity-browser-uuid]'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** @var \Behat\Mink\Element\NodeElement[] $items */ |
|
101
|
|
|
$items = $this |
|
102
|
|
|
->assertSession() |
|
103
|
|
|
->elementExists('css', $selector) |
|
104
|
|
|
->findAll('css', '[data-selectable]'); |
|
105
|
|
|
|
|
106
|
|
|
$items[$n - 1]->click(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..