Code Duplication    Length = 19-20 lines in 3 locations

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

@@ 229-247 (lines=19) @@
226
  /**
227
   * @Then I should see the link :link
228
   */
229
  public function assertLinkVisible($link) {
230
    $element = $this->getSession()->getPage();
231
    $result = $element->findLink($link);
232
233
    try {
234
      if ($result && !$result->isVisible()) {
235
        throw new \Exception(sprintf("No link to '%s' on the page %s", $link, $this->getSession()->getCurrentUrl()));
236
      }
237
    }
238
    catch (UnsupportedDriverActionException $e) {
239
      // We catch the UnsupportedDriverActionException exception in case
240
      // this step is not being performed by a driver that supports javascript.
241
      // All other exceptions are valid.
242
    }
243
244
    if (empty($result)) {
245
      throw new \Exception(sprintf("No link to '%s' on the page %s", $link, $this->getSession()->getCurrentUrl()));
246
    }
247
  }
248
249
  /**
250
   * Links are not loaded on the page.
@@ 254-272 (lines=19) @@
251
   *
252
   * @Then I should not see the link :link
253
   */
254
  public function assertNotLinkVisible($link) {
255
    $element = $this->getSession()->getPage();
256
    $result = $element->findLink($link);
257
258
    try {
259
      if ($result && $result->isVisible()) {
260
        throw new \Exception(sprintf("The link '%s' was present on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
261
      }
262
    }
263
    catch (UnsupportedDriverActionException $e) {
264
      // We catch the UnsupportedDriverActionException exception in case
265
      // this step is not being performed by a driver that supports javascript.
266
      // All other exceptions are valid.
267
    }
268
269
    if ($result) {
270
      throw new \Exception(sprintf("The link '%s' was present on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
271
    }
272
  }
273
274
  /**
275
   * Links are loaded but not visually visible (e.g they have display: hidden applied).
@@ 279-298 (lines=20) @@
276
   *
277
   * @Then I should not visibly see the link :link
278
   */
279
  public function assertNotLinkVisuallyVisible($link) {
280
    $element = $this->getSession()->getPage();
281
    $result = $element->findLink($link);
282
283
    try {
284
      if ($result && $result->isVisible()) {
285
        throw new \Exception(sprintf("The link '%s' was visually visible on the page %s and was not supposed to be", $link, $this->getSession()->getCurrentUrl()));
286
      }
287
    }
288
    catch (UnsupportedDriverActionException $e) {
289
      // We catch the UnsupportedDriverActionException exception in case
290
      // this step is not being performed by a driver that supports javascript.
291
      // All other exceptions are valid.
292
    }
293
294
    if (!$result) {
295
      throw new \Exception(sprintf("The link '%s' was not loaded on the page %s at all", $link, $this->getSession()->getCurrentUrl()));
296
    }
297
298
  }
299
300
  /**
301
   * @Then I (should )see the heading :heading