Code Duplication    Length = 19-20 lines in 3 locations

src/Drupal/DrupalExtension/Context/MinkContext.php 3 locations

@@ 197-215 (lines=19) @@
194
  /**
195
   * @Then I should see the link :link
196
   */
197
  public function assertLinkVisible($link) {
198
    $element = $this->getSession()->getPage();
199
    $result = $element->findLink($link);
200
201
    try {
202
      if ($result && !$result->isVisible()) {
203
        throw new \Exception(sprintf("No link to '%s' on the page %s", $link, $this->getSession()->getCurrentUrl()));
204
      }
205
    }
206
    catch (UnsupportedDriverActionException $e) {
207
      // We catch the UnsupportedDriverActionException exception in case
208
      // this step is not being performed by a driver that supports javascript.
209
      // All other exceptions are valid.
210
    }
211
212
    if (empty($result)) {
213
      throw new \Exception(sprintf("No link to '%s' on the page %s", $link, $this->getSession()->getCurrentUrl()));
214
    }
215
  }
216
217
  /**
218
   * Links are not loaded on the page.
@@ 222-240 (lines=19) @@
219
   *
220
   * @Then I should not see the link :link
221
   */
222
  public function assertNotLinkVisible($link) {
223
    $element = $this->getSession()->getPage();
224
    $result = $element->findLink($link);
225
226
    try {
227
      if ($result && $result->isVisible()) {
228
        throw new \Exception(sprintf("The link '%s' was present on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
229
      }
230
    }
231
    catch (UnsupportedDriverActionException $e) {
232
      // We catch the UnsupportedDriverActionException exception in case
233
      // this step is not being performed by a driver that supports javascript.
234
      // All other exceptions are valid.
235
    }
236
237
    if ($result) {
238
      throw new \Exception(sprintf("The link '%s' was present on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
239
    }
240
  }
241
242
  /**
243
   * Links are loaded but not visually visible (e.g they have display: hidden applied).
@@ 247-266 (lines=20) @@
244
   *
245
   * @Then I should not visibly see the link :link
246
   */
247
  public function assertNotLinkVisuallyVisible($link) {
248
    $element = $this->getSession()->getPage();
249
    $result = $element->findLink($link);
250
251
    try {
252
      if ($result && $result->isVisible()) {
253
        throw new \Exception(sprintf("The link '%s' was visually visible on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
254
      }
255
    }
256
    catch (UnsupportedDriverActionException $e) {
257
      // We catch the UnsupportedDriverActionException exception in case
258
      // this step is not being performed by a driver that supports javascript.
259
      // All other exceptions are valid.
260
    }
261
262
    if (!$result) {
263
      throw new \Exception(sprintf("The link '%s' was not loaded on the page %s at all", $link, $this->getSession()->getCurrentUrl()));
264
    }
265
266
  }
267
268
  /**
269
   * @Then I (should )see the heading :heading