You are here

public function ImageWidgetCropTest::testCropUi in Image Widget Crop 8

Test Image Widget Crop UI.

File

src/Tests/ImageWidgetCropTest.php, line 61

Class

ImageWidgetCropTest
Minimal test case for the image_widget_crop module.

Namespace

Drupal\image_widget_crop\Tests

Code

public function testCropUi() {

  // Test that when a crop has more than one usage we have a warning.
  $this
    ->createImageField('field_image_crop_test', 'crop_test', 'image_widget_crop', [], [], [
    'crop_list' => [
      'crop_16_9' => 'crop_16_9',
    ],
  ]);
  $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/crop_test');
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'files[field_image_crop_test_0]' => \Drupal::service('file_system')
      ->realpath('public://image-test.jpg'),
  ];
  $this
    ->drupalPostAjaxForm(NULL, $edit, $this
    ->getButtonName('//input[@type="submit" and @value="Upload" and @data-drupal-selector="edit-field-image-crop-test-0-upload-button"]'));
  $node = Node::create([
    'title' => '2nd node using it',
    'type' => 'crop_test',
    'field_image_crop_test' => 1,
    'alt' => $this
      ->randomMachineName(),
  ]);
  $node
    ->save();

  /** @var \Drupal\file\FileUsage\FileUsageInterface $usage */
  $usage = \Drupal::service('file.usage');
  $usage
    ->add(\Drupal::service('entity_type.manager')
    ->getStorage('file')
    ->load(1), 'image_widget_crop', 'node', $node
    ->id());
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertRaw(t('This crop definition affects more usages of this image'));
}