function ImageStyleTest::testFlush
@covers ::flush
File
-
core/
modules/ image/ tests/ src/ Unit/ ImageStyleTest.php, line 205
Class
- ImageStyleTest
- @coversDefaultClass <a href="/api/drupal/core%21modules%21image%21src%21Entity%21ImageStyle.php/class/ImageStyle/11.x" title="Defines an image style configuration entity." class="local">\Drupal\image\Entity\ImageStyle</a>
Namespace
Drupal\Tests\image\UnitCode
public function testFlush() : void {
$cache_tag_invalidator = $this->createMock('\\Drupal\\Core\\Cache\\CacheTagsInvalidator');
$file_system = $this->createMock('\\Drupal\\Core\\File\\FileSystemInterface');
$module_handler = $this->createMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
$stream_wrapper_manager = $this->createMock('\\Drupal\\Core\\StreamWrapper\\StreamWrapperManagerInterface');
$stream_wrapper_manager->expects($this->any())
->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->getMockBuilder('\\Drupal\\image\\ImageEffectBase');
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, [
'buildUri',
'getCacheTagsToInvalidate',
]);
$image_style->expects($this->any())
->method('buildUri')
->willReturn('test.jpg');
$image_style->expects($this->any())
->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.