function 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\KernelCode
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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.