You are here

public function ImageEffectsTest::testImageEffectsCaching in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/image/tests/src/Kernel/ImageEffectsTest.php \Drupal\Tests\image\Kernel\ImageEffectsTest::testImageEffectsCaching()

Tests image effect caching.

File

core/modules/image/tests/src/Kernel/ImageEffectsTest.php, line 197

Class

ImageEffectsTest
Tests image effects.

Namespace

Drupal\Tests\image\Kernel

Code

public function testImageEffectsCaching() {
  $state = $this->container
    ->get('state');

  // The 'image_module_test.counter' state variable value is incremented in
  // image_module_test_image_effect_info_alter() every time the image effect
  // plugin definitions are recomputed.
  // @see image_module_test_image_effect_info_alter()
  $state
    ->set('image_module_test.counter', 0);

  // First call should grab a fresh copy of the data.
  $effects = $this->imageEffectPluginManager
    ->getDefinitions();
  $this
    ->assertEquals(1, $state
    ->get('image_module_test.counter'));

  // Second call should come from cache.
  $state
    ->set('image_module_test.counter', 0);
  $cached_effects = $this->imageEffectPluginManager
    ->getDefinitions();
  $this
    ->assertEquals(0, $state
    ->get('image_module_test.counter'));

  // Check that cached effects are the same as the processed.
  $this
    ->assertSame($effects, $cached_effects);
}