You are here

public function ImageAdminStylesTest::testFlushUserInterface in Drupal 10

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

Tests flush user interface.

File

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

Class

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

Namespace

Drupal\Tests\image\Functional

Code

public function testFlushUserInterface() {
  $admin_path = 'admin/config/media/image-styles';

  // Create a new style.
  $style_name = strtolower($this
    ->randomMachineName(10));
  $style = ImageStyle::create([
    'name' => $style_name,
    'label' => $this
      ->randomString(),
  ]);
  $style
    ->save();

  // Create an image to make sure it gets flushed.
  $files = $this
    ->drupalGetTestFiles('image');
  $image_uri = $files[0]->uri;
  $derivative_uri = $style
    ->buildUri($image_uri);
  $this
    ->assertTrue($style
    ->createDerivative($image_uri, $derivative_uri));
  $this
    ->assertEquals(1, $this
    ->getImageCount($style));

  // Go to image styles list page and check if the flush operation link
  // exists.
  $this
    ->drupalGet($admin_path);
  $flush_path = $admin_path . '/manage/' . $style_name . '/flush';
  $this
    ->assertSession()
    ->linkByHrefExists($flush_path);

  // Flush the image style derivatives using the user interface.
  $this
    ->drupalGet($flush_path);
  $this
    ->submitForm([], 'Flush');

  // The derivative image file should have been deleted.
  $this
    ->assertEquals(0, $this
    ->getImageCount($style));
}