public function testGetImageHook()
{
define('TL_ROOT', $this->getRootDir());
$GLOBALS['TL_CONFIG']['validImageTypes'] = 'jpg';
System::setContainer($this->mockContainerWithContaoScopes());
$path = $this->getRootDir() . '/images/dummy.jpg';
$resizer = new LegacyResizer($this->getRootDir() . '/assets/images', new ResizeCalculator());
$imagine = new Imagine();
$framework = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\ContaoFramework')->disableOriginalConstructor()->getMock();
$filesModel = $this->getMock('Contao\\FilesModel');
$filesAdapter = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\Adapter')->disableOriginalConstructor()->getMock();
$filesAdapter->expects($this->any())->method('__call')->willReturn($filesModel);
$framework->expects($this->any())->method('getAdapter')->willReturn($filesAdapter);
$imageFactory = $this->createImageFactory($resizer, $imagine, $imagine, null, $framework);
$GLOBALS['TL_HOOKS'] = ['executeResize' => [[get_class($this), 'executeResizeHookCallback']]];
// Build cache before adding the hook
$imageFactory->create($path, [50, 50, ResizeConfiguration::MODE_CROP]);
$GLOBALS['TL_HOOKS'] = ['getImage' => [[get_class($this), 'getImageHookCallback']]];
$image = $imageFactory->create($path, [100, 100, ResizeConfiguration::MODE_CROP]);
$this->assertEquals($this->getRootDir() . '/assets/images/dummy.jpg&getImage_100_100_crop_Contao-File__Contao-Image.jpg', $image->getPath());
$image = $imageFactory->create($path, [50, 50, ResizeConfiguration::MODE_CROP]);
$this->assertRegExp('(/images/.*dummy.*.jpg$)', $image->getPath(), 'Hook should not get called for cached images');
$image = $imageFactory->create($path, [200, 200, ResizeConfiguration::MODE_CROP]);
$this->assertEquals($this->getRootDir() . '/images/dummy.jpg', $image->getPath(), 'Hook should not get called if no resize is necessary');
unset($GLOBALS['TL_HOOKS']);
}