You are here

public function MediaBrowserContext::createFromUpload in Lightning Media 8.2

Same name and namespace in other branches
  1. 8.3 tests/contexts/MediaBrowserContext.behat.inc \Acquia\LightningExtension\Context\MediaBrowserContext::createFromUpload()

@When I create media named :title by uploading :file

Parameters

$title:

$file:

File

tests/contexts/MediaBrowserContext.behat.inc, line 205

Class

MediaBrowserContext
Contains step definitions for interacting with Lightning's media browser.

Namespace

Acquia\LightningExtension\Context

Code

public function createFromUpload($title, $file) {

  /** @var MinkContext $mink_context */
  $mink_context = $this
    ->getContext(MinkContext::class);
  $mink_context
    ->assertAtPath('/entity-browser/iframe/media_browser');
  $this
    ->upload($file);

  // If the file is an image, assert that cropping is available.
  $extension = pathinfo($file, PATHINFO_EXTENSION);
  $extension = strtolower($extension);
  if (in_array($extension, [
    'jpg',
    'jpeg',
    'gif',
    'png',
  ])) {

    /** @var \Acquia\LightningExtension\Context\ImageBrowserContext $context */
    $context = $this
      ->getContext(ImageBrowserContext::class);
    $context
      ->assertCrop();
  }
  $assert = $this
    ->assertSession();
  $assert
    ->fieldExists('Name')
    ->setValue($title);
  $assert
    ->elementExists('named', [
    'button',
    'Place',
  ])
    ->press();
}