Skip to content
Snippets Groups Projects
Commit 642a3243 authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3491278 by d34dman, philipprudloff: Aspect ratio configuration only...

Issue #3491278 by d34dman, philipprudloff: Aspect ratio configuration only supports integer numerator/denominator
parent b2356926
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,64 @@ class RiftPictureTest extends ExistingSiteBase {
* Test Aspect Ratio.
*/
public function testAspectRatioConfig() {
$media = $this->media;
$service = \Drupal::service('rift.picture');
$config = $this->getBaseConfig();
$config['aspect_ratios'] = '2x3 24x10 100x185';
$config['url_generation_strategy'] = 'dummyimage';
$elements = $service->responsivePicture($media, $config);
$this->assertEquals(10, count($elements['#context']['content']));
$map = [
0 => [
'https://dummyimage.com/100x150/eee/222?text=100w150h-avif-80',
'https://dummyimage.com/200x300/eee/222?text=200w300h-avif-40',
],
1 => [
'https://dummyimage.com/300x125/eee/222?text=300w125h-avif-80',
'https://dummyimage.com/600x250/eee/222?text=600w250h-avif-40',
],
2 => [
'https://dummyimage.com/500x925/eee/222?text=500w925h-avif-80',
'https://dummyimage.com/1000x1850/eee/222?text=1000w1850h-avif-40',
],
3 => [
'https://dummyimage.com/100x150/eee/222?text=100w150h-webp-80',
'https://dummyimage.com/200x300/eee/222?text=200w300h-webp-40',
],
4 => [
'https://dummyimage.com/300x125/eee/222?text=300w125h-webp-80',
'https://dummyimage.com/600x250/eee/222?text=600w250h-webp-40',
],
5 => [
'https://dummyimage.com/500x925/eee/222?text=500w925h-webp-80',
'https://dummyimage.com/1000x1850/eee/222?text=1000w1850h-webp-40',
],
6 => [
'https://dummyimage.com/100x150/eee/222?text=100w150h-jpeg-80',
'https://dummyimage.com/200x300/eee/222?text=200w300h-jpeg-40',
],
7 => [
'https://dummyimage.com/300x125/eee/222?text=300w125h-jpeg-80',
'https://dummyimage.com/600x250/eee/222?text=600w250h-jpeg-40',
],
8 => [
'https://dummyimage.com/500x925/eee/222?text=500w925h-jpeg-80',
'https://dummyimage.com/1000x1850/eee/222?text=1000w1850h-jpeg-40',
],
];
foreach ($elements["#context"]["content"] as $ndx => $content) {
/** @var \Drupal\Core\Template\Attribute $attributes */
$attribute = $content['#context']['attributes'];
if ($content['#context']['tag_name'] == "source") {
$srcset_string = (string) $attribute->offsetGet('srcset');
$srcset_items = explode(',', $srcset_string);
$this->assertEquals(2, count($srcset_items));
[$first_url] = explode(' ', $srcset_items[0]);
[$second_url] = explode(' ', $srcset_items[1]);
$this->assertEquals($map[$ndx][0], $first_url);
$this->assertEquals($map[$ndx][1], $second_url);
}
}
}
......
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