You are here

public function ProductLayoutBuilderIntegrationTest::testSampleValuesGeneratedImages in Commerce Core 8.2

Tests that configuring the default layout doesn't generate multiple images.

@link https://www.drupal.org/project/commerce/issues/3190799

File

modules/product/tests/src/FunctionalJavascript/ProductLayoutBuilderIntegrationTest.php, line 94

Class

ProductLayoutBuilderIntegrationTest
@group commerce

Namespace

Drupal\Tests\commerce_product\FunctionalJavascript

Code

public function testSampleValuesGeneratedImages() {

  // Add an image field to the  variation.
  FieldStorageConfig::create([
    'entity_type' => 'commerce_product_variation',
    'field_name' => 'field_images',
    'type' => 'image',
    'cardinality' => 1,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'entity_type' => 'commerce_product_variation',
    'field_name' => 'field_images',
    'bundle' => 'default',
  ]);
  $field_config
    ->save();
  $file_storage = \Drupal::entityTypeManager()
    ->getStorage('file');

  // Assert the baseline file count.
  $this
    ->assertEquals(0, $file_storage
    ->getQuery()
    ->accessCheck(FALSE)
    ->count()
    ->execute());
  $this
    ->enableLayoutsForBundle('default');
  $this
    ->configureDefaultLayout('default');

  // We should have one randomly generated image, for the variation.
  // @todo we end up with 5. I think it's due to the sample generated Product
  //   having sample variations also referenced.
  $files = $file_storage
    ->loadMultiple();
  $this
    ->assertCount(5, $files);
}