function ImageStyleTest::testBuildUri

Same name in other branches
  1. 9 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::testBuildUri()
  2. 8.9.x core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::testBuildUri()
  3. 11.x core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::testBuildUri()

@covers ::buildUri

File

core/modules/image/tests/src/Unit/ImageStyleTest.php, line 123

Class

ImageStyleTest
@coversDefaultClass \Drupal\image\Entity\ImageStyle

Namespace

Drupal\Tests\image\Unit

Code

public function testBuildUri() : void {
    // Image style that changes the extension.
    $image_effect_id = $this->randomMachineName();
    $logger = $this->getMockBuilder('\\Psr\\Log\\LoggerInterface')
        ->getMock();
    $image_effect = $this->getMockBuilder('\\Drupal\\image\\ImageEffectBase')
        ->setConstructorArgs([
        [],
        $image_effect_id,
        [],
        $logger,
    ])
        ->getMock();
    $image_effect->expects($this->any())
        ->method('getDerivativeExtension')
        ->willReturn('png');
    $image_style = $this->getImageStyleMock($image_effect_id, $image_effect);
    $this->assertEquals($image_style->buildUri('public://test.jpeg'), 'public://styles/' . $image_style->id() . '/public/test.jpeg.png');
    // Image style that doesn't change the extension.
    $image_effect_id = $this->randomMachineName();
    $image_effect = $this->getMockBuilder('\\Drupal\\image\\ImageEffectBase')
        ->setConstructorArgs([
        [],
        $image_effect_id,
        [],
        $logger,
    ])
        ->getMock();
    $image_effect->expects($this->any())
        ->method('getDerivativeExtension')
        ->willReturnArgument(0);
    $image_style = $this->getImageStyleMock($image_effect_id, $image_effect);
    $this->assertEquals($image_style->buildUri('public://test.jpeg'), 'public://styles/' . $image_style->id() . '/public/test.jpeg');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.