|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\DFExtension\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Acquia\LightningExtension\AwaitTrait; |
|
6
|
|
|
use Acquia\LightningExtension\Context\PanelsInPlaceContext; |
|
7
|
|
|
use Acquia\LightningExtension\Context\UtilityContext; |
|
8
|
|
|
use Drupal\DrupalExtension\Context\DrupalSubContextBase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A context with miscellaneous helpers. |
|
12
|
|
|
*/ |
|
13
|
|
|
class MiscellaneousContext extends DrupalSubContextBase { |
|
14
|
|
|
|
|
15
|
|
|
use AwaitTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Close the Panels IPE tray. |
|
19
|
|
|
* |
|
20
|
|
|
* @When I close the editor |
|
21
|
|
|
*/ |
|
22
|
|
|
public function closeEditor() { |
|
23
|
|
|
$assert = $this->assertSession(); |
|
24
|
|
|
|
|
25
|
|
|
$panelsinplace = $this->getContext(PanelsInPlaceContext::class); |
|
26
|
|
|
|
|
27
|
|
|
// Assert that the tab exists... |
|
28
|
|
|
$link = $assert->elementExists( |
|
29
|
|
|
'named', |
|
30
|
|
|
['link', 'Cancel'], |
|
31
|
|
|
$assert->elementExists('css', '.ipe-tabs', $panelsinplace->assertTray()) |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$link->click(); |
|
35
|
|
|
|
|
36
|
|
|
/** @var \Acquia\LightningExtension\Context\UtilityContext $utility */ |
|
37
|
|
|
$utility = $this->getContext(UtilityContext::class); |
|
38
|
|
|
$utility->acceptAlerts(function () { |
|
39
|
|
|
$this->awaitAjax(); |
|
40
|
|
|
}); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* "Manually" writes text into a field. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $text |
|
47
|
|
|
* The text to write into the field. |
|
48
|
|
|
* @param string $field |
|
49
|
|
|
* The label, placeholder, ID or name of the field. |
|
50
|
|
|
* |
|
51
|
|
|
* @Given I write :text into :field |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iWriteTextIntoField($text, $field) { |
|
54
|
|
|
$this->getSession() |
|
|
|
|
|
|
55
|
|
|
->getDriver() |
|
56
|
|
|
->getWebDriverSession() |
|
57
|
|
|
->element('xpath', $this->getSession()->getSelectorsHandler()->selectorToXpath('named_exact', array('field', $field))) |
|
58
|
|
|
->postValue(['value' => [$text]]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Asserts that the current page is an admin page. |
|
63
|
|
|
* |
|
64
|
|
|
* @Then The page should be an admin page |
|
65
|
|
|
*/ |
|
66
|
|
|
public function assertAdminPage() { |
|
67
|
|
|
/** @var \Drupal\Core\Routing\AdminContext $admin_context */ |
|
68
|
|
|
$admin_context = \Drupal::service('router.admin_context'); |
|
69
|
|
|
return $admin_context->isAdminRoute(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: