You are here

public function CropEntityProvidersTest::testCropEffect in Crop API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/CropEntityProvidersTest.php \Drupal\Tests\crop\Kernel\CropEntityProvidersTest::testCropEffect()

Tests file provider plugin.

File

tests/src/Kernel/CropEntityProvidersTest.php, line 24

Class

CropEntityProvidersTest
Tests entity provider plugins.

Namespace

Drupal\Tests\crop\Kernel

Code

public function testCropEffect() {
  $file = $this
    ->getTestFile();
  $file
    ->save();

  // Create crop.
  $values = [
    'type' => $this->cropType
      ->id(),
    'entity_id' => $file
      ->id(),
    'entity_type' => 'file',
    'uri' => $file
      ->getFileUri(),
    'x' => '190',
    'y' => '120',
    'width' => '50',
    'height' => '50',
  ];

  /** @var \Drupal\crop\CropInterface $crop */
  $crop = $this->container
    ->get('entity_type.manager')
    ->getStorage('crop')
    ->create($values);
  $crop
    ->save();
  try {
    $provider = $crop
      ->provider();
    $this
      ->assertTrue(TRUE, 'File entity provider plugin was found.');
  } catch (EntityProviderNotFoundException $e) {
    $this
      ->assertTrue(FALSE, 'File entity provider plugin was found.');
  }
  $this
    ->assertEquals($provider
    ->uri($file), $file
    ->getFileUri(), 'File provider plugin returned correct URI.');
}