Code Duplication    Length = 19-20 lines in 3 locations

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

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