You are here

public function ImageAdminStylesTest::testEditEffect in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/Functional/ImageAdminStylesTest.php \Drupal\Tests\image\Functional\ImageAdminStylesTest::testEditEffect()

Verifies that editing an image effect does not cause it to be duplicated.

File

core/modules/image/tests/src/Functional/ImageAdminStylesTest.php, line 383

Class

ImageAdminStylesTest
Tests creation, deletion, and editing of image styles and effects.

Namespace

Drupal\Tests\image\Functional

Code

public function testEditEffect() {

  // Add a scale effect.
  $style_name = 'test_style_effect_edit';
  $this
    ->drupalGet('admin/config/media/image-styles/add');
  $this
    ->submitForm([
    'label' => 'Test style effect edit',
    'name' => $style_name,
  ], 'Create new style');
  $this
    ->submitForm([
    'new' => 'image_scale_and_crop',
  ], 'Add');
  $this
    ->submitForm([
    'data[width]' => '300',
    'data[height]' => '200',
  ], 'Add effect');
  $this
    ->assertSession()
    ->pageTextContains('Scale and crop 300×200');

  // There should normally be only one edit link on this page initially.
  $this
    ->clickLink('Edit');
  $this
    ->submitForm([
    'data[width]' => '360',
    'data[height]' => '240',
  ], 'Update effect');
  $this
    ->assertSession()
    ->pageTextContains('Scale and crop 360×240');

  // Check that the previous effect is replaced.
  $this
    ->assertSession()
    ->pageTextNotContains('Scale and crop 300×200');

  // Add another scale effect.
  $this
    ->drupalGet('admin/config/media/image-styles/add');
  $this
    ->submitForm([
    'label' => 'Test style scale edit scale',
    'name' => 'test_style_scale_edit_scale',
  ], 'Create new style');
  $this
    ->submitForm([
    'new' => 'image_scale',
  ], 'Add');
  $this
    ->submitForm([
    'data[width]' => '12',
    'data[height]' => '19',
  ], 'Add effect');

  // Edit the scale effect that was just added.
  $this
    ->clickLink('Edit');
  $this
    ->submitForm([
    'data[width]' => '24',
    'data[height]' => '19',
  ], 'Update effect');

  // Add another scale effect and make sure both exist. Click through from
  // the overview to make sure that it is possible to add new effect then.
  $this
    ->drupalGet('admin/config/media/image-styles');
  $rows = $this
    ->xpath('//table/tbody/tr');
  $i = 0;
  foreach ($rows as $row) {
    if ($row
      ->find('css', 'td')
      ->getText() === 'Test style scale edit scale') {
      $this
        ->clickLink('Edit', $i);
      break;
    }
    $i++;
  }
  $this
    ->submitForm([
    'new' => 'image_scale',
  ], 'Add');
  $this
    ->submitForm([
    'data[width]' => '12',
    'data[height]' => '19',
  ], 'Add effect');
  $this
    ->assertSession()
    ->pageTextContains('Scale 24×19');
  $this
    ->assertSession()
    ->pageTextContains('Scale 12×19');

  // Try to edit a nonexistent effect.
  $uuid = $this->container
    ->get('uuid');
  $this
    ->drupalGet('admin/config/media/image-styles/manage/' . $style_name . '/effects/' . $uuid
    ->generate());
  $this
    ->assertSession()
    ->statusCodeEquals(404);
}