function ImageEffectsTest::testImageEffectsCaching

Same name in other branches
  1. 8.9.x core/modules/image/tests/src/Functional/ImageEffectsTest.php \Drupal\Tests\image\Functional\ImageEffectsTest::testImageEffectsCaching()
  2. 10 core/modules/image/tests/src/Kernel/ImageEffectsTest.php \Drupal\Tests\image\Kernel\ImageEffectsTest::testImageEffectsCaching()
  3. 11.x 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.