You are here

ImageBrowserContext.behat.inc in Lightning Media 8.3

File

tests/contexts/ImageBrowserContext.behat.inc
View source
<?php

namespace Acquia\LightningExtension\Context;

use Behat\Mink\Exception\ElementNotFoundException;
use Drupal\DrupalExtension\Context\DrupalSubContextBase;

/**
 * Contains step definitions for interacting with Lightning's image browsers.
 *
 * @internal
 *   This is an internal part of Lightning Media's testing system and may be
 *   changed or removed at any time without warning. It should not be extended,
 *   instantiated, or used in any way by external code! If you need to use this
 *   functionality, you should copy the relevant code into your own project.
 */
final class ImageBrowserContext extends DrupalSubContextBase {
  use AwaitTrait;

  /**
   * Opens an image browser for a particular field.
   *
   * @param string $field
   *   The field label.
   *
   * @When I open the :field image browser
   */
  public function open($field) {

    /** @var ElementContext $context */
    $context = $this
      ->getContext(ElementContext::class);
    $context
      ->assertDetails($field)
      ->pressButton('Select Image(s)');
    $this
      ->awaitAjax();
    $context
      ->enterFrame('entity_browser_iframe_image_browser');
  }

  /**
   * Asserts that cropping is enabled for an uploaded image.
   *
   * @Then I should be able to crop the image
   */
  public function assertCrop() {

    /** @var \Acquia\LightningExtension\Context\ElementContext $context */
    $context = $this
      ->getContext(ElementContext::class);

    // There should always be a collapsible cropping area, but depending on the
    // circumstances, the Freeform crop widget might either be a vertical tab
    // inside that area, or its own cropping area. Try to account for both.
    $crop = $context
      ->assertOpenDetails('Crop image');
    try {
      $context
        ->assertVerticalTab('Freeform', $crop);
    } catch (ElementNotFoundException $e) {
      $context
        ->assertDetails('Freeform');
    }
  }

}

Classes

Namesort descending Description
ImageBrowserContext Contains step definitions for interacting with Lightning's image browsers.