ConvertTest.php in Drupal 10
File
core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
View source
<?php
namespace Drupal\Tests\image\Functional\ImageEffect;
use Drupal\Core\File\FileSystemInterface;
use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;
class ConvertTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'image',
];
public function testConvertFileInRoot() {
$image_style = ImageStyle::create([
'name' => 'image_effect_test',
'label' => 'Image Effect Test',
]);
$this
->assertEquals(SAVED_NEW, $image_style
->save());
$image_style
->addImageEffect([
'id' => 'image_convert',
'data' => [
'extension' => 'jpeg',
],
]);
$this
->assertEquals(SAVED_UPDATED, $image_style
->save());
$test_uri = 'public://image-test-do.png';
\Drupal::service('file_system')
->copy('core/tests/fixtures/files/image-test.png', $test_uri, FileSystemInterface::EXISTS_REPLACE);
$this
->assertFileExists($test_uri);
$derivative_uri = 'public://styles/image_effect_test/public/image-test-do.png.jpeg';
$this
->assertFileDoesNotExist($derivative_uri);
$url = \Drupal::service('file_url_generator')
->transformRelative($image_style
->buildUrl($test_uri));
$this
->drupalGet($this
->getAbsoluteUrl($url));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertFileExists($derivative_uri);
}
}