You are here

public function ImageAdminStylesTest::testFlushUserInterface in Drupal 8

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

Test flush user interface.

File

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

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
    ->assertEqual($this
    ->getImageCount($style), 1);

  // 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
    ->assertLinkByHref($flush_path);

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

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