Contao\CoreBundle\Test\Image\PictureFactoryTest::testCreateLegacyMode PHP Method

testCreateLegacyMode() public method

Tests the create() method.
    public function testCreateLegacyMode()
    {
        $path = $this->getRootDir() . '/images/dummy.jpg';
        $pictureMock = $this->getMockBuilder('Contao\\Image\\Picture')->disableOriginalConstructor()->getMock();
        $pictureGenerator = $this->getMockBuilder('Contao\\Image\\PictureGenerator')->disableOriginalConstructor()->getMock();
        $pictureGenerator->expects($this->once())->method('generate')->with($this->callback(function (ImageInterface $image) {
            return true;
        }), $this->callback(function (PictureConfigurationInterface $config) {
            $this->assertEquals($config->getSizeItems(), []);
            $this->assertEquals(ResizeConfigurationInterface::MODE_CROP, $config->getSize()->getResizeConfig()->getMode());
            $this->assertEquals(100, $config->getSize()->getResizeConfig()->getWidth());
            $this->assertEquals(200, $config->getSize()->getResizeConfig()->getHeight());
            return true;
        }), $this->callback(function (ResizeOptionsInterface $options) {
            return true;
        }))->willReturn($pictureMock);
        $imageMock = $this->getMockBuilder('Contao\\Image\\Image')->disableOriginalConstructor()->getMock();
        $imageFactory = $this->getMockBuilder('Contao\\CoreBundle\\Image\\ImageFactory')->disableOriginalConstructor()->getMock();
        $imageFactory->expects($this->once())->method('create')->with($this->callback(function ($imagePath) use($path) {
            $this->assertEquals($path, $imagePath);
            return true;
        }))->willReturn($imageMock);
        $imageFactory->expects($this->once())->method('getImportantPartFromLegacyMode')->with($this->callback(function (ImageInterface $image) {
            return true;
        }), $this->callback(function ($mode) {
            $this->assertEquals('left_top', $mode);
            return true;
        }));
        $pictureFactory = $this->createPictureFactory($pictureGenerator, $imageFactory);
        $picture = $pictureFactory->create($path, [100, 200, 'left_top']);
        $this->assertSame($pictureMock, $picture);
    }