function ImageImportTest::testImport

Same name in other branches
  1. 9 core/modules/image/tests/src/Kernel/ImageImportTest.php \Drupal\Tests\image\Kernel\ImageImportTest::testImport()
  2. 8.9.x core/modules/image/tests/src/Kernel/ImageImportTest.php \Drupal\Tests\image\Kernel\ImageImportTest::testImport()
  3. 10 core/modules/image/tests/src/Kernel/ImageImportTest.php \Drupal\Tests\image\Kernel\ImageImportTest::testImport()

Tests importing image styles.

File

core/modules/image/tests/src/Kernel/ImageImportTest.php, line 25

Class

ImageImportTest
Tests config import for Image styles.

Namespace

Drupal\Tests\image\Kernel

Code

public function testImport() : void {
    $style = ImageStyle::create([
        'name' => 'test',
        'label' => 'Test',
    ]);
    $style->addImageEffect([
        'id' => 'image_module_test_null',
        'weight' => 0,
    ]);
    $style->addImageEffect([
        'id' => 'image_module_test_null',
        'weight' => 1,
    ]);
    $style->save();
    $this->assertCount(2, $style->getEffects());
    $uuid = \Drupal::service('uuid')->generate();
    $style->set('effects', [
        $uuid => [
            'id' => 'image_module_test_null',
            'weight' => 0,
        ],
    ]);
    $style->save();
    $style = ImageStyle::load('test');
    $this->assertCount(1, $style->getEffects());
}

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