|
|
|
|
@ -78,6 +78,7 @@ final class ImageViewBuilderTest extends AbstractTestCase {
|
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => [], |
|
|
|
|
'#theme' => 'image', |
|
|
|
|
'#alt' => '', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [ |
|
|
|
|
'user', |
|
|
|
|
@ -93,13 +94,36 @@ final class ImageViewBuilderTest extends AbstractTestCase {
|
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<img src="/files/ocean.jpg" alt="" />', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- Without style, with alt. |
|
|
|
|
$build = $view_builder->build($public_image, NULL, [], FALSE, TRUE, 'The attribute'); |
|
|
|
|
$expected_build = [ |
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => [], |
|
|
|
|
'#theme' => 'image', |
|
|
|
|
'#alt' => 'The attribute', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [ |
|
|
|
|
'user', |
|
|
|
|
'user.permissions', |
|
|
|
|
], |
|
|
|
|
'tags' => [ |
|
|
|
|
'file:1', |
|
|
|
|
'tag_for_public://ocean.jpg', |
|
|
|
|
], |
|
|
|
|
'max-age' => 70, |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<img src="/files/ocean.jpg" alt="The attribute" />', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- With style. |
|
|
|
|
$build = $view_builder->build($public_image, 'large', ['alt' => 'Ocean']); |
|
|
|
|
$build = $view_builder->build($public_image, 'large', ['title' => 'The title']); |
|
|
|
|
$expected_build = [ |
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => ['alt' => 'Ocean'], |
|
|
|
|
'#attributes' => ['title' => 'The title'], |
|
|
|
|
'#theme' => 'image_style', |
|
|
|
|
'#style_name' => 'large', |
|
|
|
|
'#alt' => '', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [ |
|
|
|
|
'user', |
|
|
|
|
@ -113,13 +137,66 @@ final class ImageViewBuilderTest extends AbstractTestCase {
|
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<img alt="Ocean" src="/files/styles/large/public/ocean.jpg?itok=abc" />', $this->renderPlain($build)); |
|
|
|
|
self::assertSame('<img title="The title" src="/files/styles/large/public/ocean.jpg?itok=abc" alt="" />', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- With responsive style. |
|
|
|
|
$build = $view_builder->build($public_image, 'wide', ['alt' => 'Ocean'], TRUE); |
|
|
|
|
$build = $view_builder->build($public_image, 'wide', ['title' => 'The title'], TRUE); |
|
|
|
|
$expected_build = [ |
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => ['alt' => 'Ocean'], |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'title' => 'The title', |
|
|
|
|
'alt' => '', |
|
|
|
|
], |
|
|
|
|
'#type' => 'responsive_image', |
|
|
|
|
'#responsive_image_style_id' => 'wide', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [ |
|
|
|
|
'user', |
|
|
|
|
'user.permissions', |
|
|
|
|
], |
|
|
|
|
'tags' => [ |
|
|
|
|
'file:1', |
|
|
|
|
'tag_for_public://ocean.jpg', |
|
|
|
|
], |
|
|
|
|
'max-age' => 70, |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<picture><img src="/files/ocean.jpg" alt="" title="The title" /></picture>', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- With style and alt |
|
|
|
|
$build = $view_builder->build($public_image, 'large', ['title' => 'The title'], FALSE, TRUE, 'The attribute'); |
|
|
|
|
$expected_build = [ |
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'title' => 'The title', |
|
|
|
|
], |
|
|
|
|
'#theme' => 'image_style', |
|
|
|
|
'#style_name' => 'large', |
|
|
|
|
'#alt' => 'The attribute', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [ |
|
|
|
|
'user', |
|
|
|
|
'user.permissions', |
|
|
|
|
], |
|
|
|
|
'tags' => [ |
|
|
|
|
'file:1', |
|
|
|
|
'tag_for_public://ocean.jpg', |
|
|
|
|
], |
|
|
|
|
'max-age' => 70, |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<img title="The title" src="/files/styles/large/public/ocean.jpg?itok=abc" alt="The attribute" />', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- With responsive style and alt. |
|
|
|
|
$build = $view_builder->build($public_image, 'wide', ['title' => 'The title'], TRUE, TRUE, 'The attribute'); |
|
|
|
|
$expected_build = [ |
|
|
|
|
'#uri' => 'public://ocean.jpg', |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'title' => 'The title', |
|
|
|
|
'alt' => 'The attribute', |
|
|
|
|
], |
|
|
|
|
'#type' => 'responsive_image', |
|
|
|
|
'#responsive_image_style_id' => 'wide', |
|
|
|
|
'#cache' => [ |
|
|
|
|
@ -135,7 +212,7 @@ final class ImageViewBuilderTest extends AbstractTestCase {
|
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
self::assertRenderArray($expected_build, $build); |
|
|
|
|
self::assertSame('<picture><img src="/files/ocean.jpg" alt="Ocean" /></picture>', $this->renderPlain($build)); |
|
|
|
|
self::assertSame('<picture><img src="/files/ocean.jpg" alt="The attribute" title="The title" /></picture>', $this->renderPlain($build)); |
|
|
|
|
|
|
|
|
|
// -- Private image with access check. |
|
|
|
|
$build = $view_builder->build($private_image); |
|
|
|
|
@ -158,6 +235,7 @@ final class ImageViewBuilderTest extends AbstractTestCase {
|
|
|
|
|
'#uri' => 'private://sea.jpg', |
|
|
|
|
'#attributes' => [], |
|
|
|
|
'#theme' => 'image', |
|
|
|
|
'#alt' => '', |
|
|
|
|
'#cache' => [ |
|
|
|
|
'contexts' => [], |
|
|
|
|
'tags' => ['file:2'], |
|
|
|
|
|