Skip to content
Snippets Groups Projects
Verified Commit fc4d59e3 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3276965 by guiu.rocafort.ferrer, andregp, roberttabigue, quietone,...

Issue #3276965 by guiu.rocafort.ferrer, andregp, roberttabigue, quietone, rootwork, smustgrave: generate sample values get dimensions wrong when min_resolution is bigger than 600x600

(cherry picked from commit 4578bbd6)
parent 9d43f7ad
No related branches found
No related tags found
22 merge requests!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4942Issue #3365945: Errors: The following table(s) do not have a primary key: forum_index,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4788Issue #3272985: RSS Feed header reverts to text/html when cached,!4716Issue #3362929: Improve 400 responses for broken/invalid image style routes,!4553Draft: Issue #2980951: Permission to see own unpublished comments in comment thread,!4273Add UUID to sections,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!2851Issue #2264739: Allow multiple field widgets to not use tabledrag,!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
......@@ -344,6 +344,17 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
$max_resolution = empty($settings['max_resolution']) ? '600x600' : $settings['max_resolution'];
$extensions = array_intersect(explode(' ', $settings['file_extensions']), ['png', 'gif', 'jpg', 'jpeg']);
$extension = array_rand(array_combine($extensions, $extensions));
$min = explode('x', $min_resolution);
$max = explode('x', $max_resolution);
if (intval($min[0]) > intval($max[0])) {
$max[0] = $min[0];
}
if (intval($min[1]) > intval($max[1])) {
$max[1] = $min[1];
}
$max_resolution = "$max[0]x$max[1]";
// Generate a max of 5 different images.
if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= 5) {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
......
......@@ -63,6 +63,13 @@ protected function setUp(): void {
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])->save();
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'image_test_generation',
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'image_test',
......@@ -71,6 +78,15 @@ protected function setUp(): void {
'file_extensions' => 'jpg',
],
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'image_test_generation',
'bundle' => 'entity_test',
'settings' => [
'min_resolution' => '800x800',
],
])->save();
\Drupal::service('file_system')->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create([
'uri' => 'public://example.jpg',
......@@ -136,11 +152,25 @@ public function testImageItem() {
$properties = $entity->getFieldDefinition('image_test')->getFieldStorageDefinition()->getPropertyDefinitions();
$this->assertEquals($expected, array_keys($properties));
// Test the generateSampleValue() method.
}
/**
* Tests generateSampleItems() method under different resolutions.
*/
public function testImageItemSampleValueGeneration() {
// Default behaviour. No resolution configuration.
$entity = EntityTest::create();
$entity->image_test->generateSampleItems();
$this->entityValidateAndSave($entity);
$this->assertEquals('image/jpeg', $entity->image_test->entity->get('filemime')->value);
// Max resolution bigger than 600x600.
$entity->image_test_generation->generateSampleItems();
$this->entityValidateAndSave($entity);
$imageItem = $entity->image_test_generation->first()->getValue();
$this->assertEquals('800', $imageItem['width']);
$this->assertEquals('800', $imageItem['height']);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment