Author: Martin Auswöger (martin@auswoeger.com)
Inheritance: extends Contao\Image\Resizer, use trait Contao\CoreBundle\Framework\FrameworkAwareTrait
Esempio n. 1
0
 /**
  * Tests empty getImage and executeResize hooks.
  *
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testEmptyHooks()
 {
     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);
     $configAdapter = $this->getMockBuilder('Contao\\CoreBundle\\Framework\\Adapter')->disableOriginalConstructor()->getMock();
     $configAdapter->expects($this->any())->method('__call')->willReturn(3000);
     $framework->expects($this->any())->method('getAdapter')->will($this->returnCallback(function ($key) use($filesAdapter, $configAdapter) {
         return ['Contao\\FilesModel' => $filesAdapter, 'Contao\\Config' => $configAdapter][$key];
     }));
     $resizer->setFramework($framework);
     $imageFactory = $this->createImageFactory($resizer, $imagine, $imagine, null, $framework);
     $GLOBALS['TL_HOOKS'] = ['executeResize' => [[get_class($this), 'emptyHookCallback']]];
     $GLOBALS['TL_HOOKS'] = ['getImage' => [[get_class($this), 'emptyHookCallback']]];
     $image = $imageFactory->create($path, [100, 100, ResizeConfiguration::MODE_CROP]);
     $this->assertRegExp('(/images/.*dummy.*.jpg$)', $image->getPath(), 'Empty hook should be ignored');
     $this->assertEquals(100, $image->getDimensions()->getSize()->getWidth());
     $this->assertEquals(100, $image->getDimensions()->getSize()->getHeight());
     unset($GLOBALS['TL_HOOKS']);
 }
Esempio n. 2
0
 /**
  * Adds image services to the container.
  *
  * @param Container $container
  * @param string    $rootDir
  */
 protected function addImageServicesToContainer(Container $container, $rootDir = null)
 {
     $imagine = new ImagineGd();
     $imagineSvg = new ImagineSvg();
     $calculator = new ResizeCalculator();
     $filesystem = new Filesystem();
     $framework = $this->mockContaoFramework();
     $resizer = new LegacyResizer(($rootDir ?: $this->getRootDir()) . '/' . $container->getParameter('contao.image.target_path'), $calculator);
     $resizer->setFramework($framework);
     $imageFactory = new ImageFactory($resizer, $imagine, $imagineSvg, $filesystem, $framework, $container->getParameter('contao.image.bypass_cache'), $container->getParameter('contao.image.imagine_options'), $container->getParameter('contao.image.valid_extensions'));
     $pictureGenerator = new PictureGenerator($resizer, $container->getParameter('contao.image.bypass_cache'), $rootDir ?: $this->getRootDir());
     $pictureFactory = new PictureFactory($pictureGenerator, $imageFactory, $framework, $container->getParameter('contao.image.bypass_cache'), $container->getParameter('contao.image.imagine_options'));
     $container->set('filesystem', $filesystem);
     $container->set('contao.image.imagine', $imagine);
     $container->set('contao.image.imagine_svg', $imagineSvg);
     $container->set('contao.image.resize_calculator', $calculator);
     $container->set('contao.image.resizer', $resizer);
     $container->set('contao.image.image_factory', $imageFactory);
     $container->set('contao.image.picture_generator', $pictureGenerator);
     $container->set('contao.image.picture_factory', $pictureFactory);
 }