function ImageStyleTest::testFlush
Same name and namespace in other branches
- 11.x core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::testFlush()
- 10 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::testFlush()
Tests flush.
File
-
core/
modules/ image/ tests/ src/ Unit/ ImageStyleTest.php, line 206
Class
Namespace
Drupal\Tests\image\UnitCode
public function testFlush() : void {
$cache_tag_invalidator = $this->createMock('\\Drupal\\Core\\Cache\\CacheTagsInvalidator');
$file_system = $this->createStub(FileSystemInterface::class);
$module_handler = $this->createStub(ModuleHandlerInterface::class);
$stream_wrapper_manager = $this->createStub(StreamWrapperManagerInterface::class);
$stream_wrapper_manager->method('getWrappers')
->willReturn([]);
$theme_registry = $this->createMock('\\Drupal\\Core\\Theme\\Registry');
$container = new ContainerBuilder();
$container->set('cache_tags.invalidator', $cache_tag_invalidator);
$container->set('file_system', $file_system);
$container->set('module_handler', $module_handler);
$container->set('stream_wrapper_manager', $stream_wrapper_manager);
$container->set('theme.registry', $theme_registry);
\Drupal::setContainer($container);
$image_effect_id = $this->randomMachineName();
$image_effect = $this->createStub(ImageEffectBase::class);
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, [
'buildUri',
'getCacheTagsToInvalidate',
]);
$image_style->expects($this->atLeastOnce())
->method('buildUri')
->willReturn('test.jpg');
$image_style->expects($this->atLeastOnce())
->method('getCacheTagsToInvalidate')
->willReturn([]);
// Assert the theme registry is reset.
$theme_registry->expects($this->once())
->method('reset');
// Assert the cache tags are invalidated.
$cache_tag_invalidator->expects($this->once())
->method('invalidateTags');
$image_style->flush();
// Assert the theme registry is not reset a path is flushed.
$theme_registry->expects($this->never())
->method('reset');
// Assert the cache tags are not reset a path is flushed.
$cache_tag_invalidator->expects($this->never())
->method('invalidateTags');
$image_style->flush('test.jpg');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.