GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 8.x-2.x ( bdb6af...21ed67 )
by Devin
56:27
created

EntityBrowserContext::submit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getContext(\Drupa...ext\MinkContext::class) of type object<Behat\Behat\Context\Context> or false is incompatible with the declared type object<Drupal\DrupalExte...on\Context\MinkContext> of property $minkContext.

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..

Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $browser_id of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
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