$path =
$this->
randomMachineName();
$base_element =
[ '#theme' => 'image_formatter',
'#image_style' => 'test',
'#item' =>
$entity->image_test,
'#url' => Url::
fromUri('base:' .
$path),
];
// Test using theme_image_formatter() with a NULL value for the alt option.
$element =
$base_element;
$this->
setRawContent($renderer->
renderRoot($element));
$elements =
$this->
xpath('//a[@href=:path]/img[@src=:url and @width=:width and @height=:height]',
[':path' =>
base_path() .
$path, ':url' =>
$url, ':width' =>
$image->
getWidth(), ':height' =>
$image->
getHeight()]);
$this->
assertCount(1,
$elements, 'theme_image_formatter() correctly renders with a NULL value for the alt option.'
);
// Test using theme_image_formatter() without an image title, alt text, or
// link options.
$element =
$base_element;
$element['#item'
]->alt = '';
$this->
setRawContent($renderer->
renderRoot($element));
$elements =
$this->
xpath('//a[@href=:path]/img[@src=:url and @width=:width and @height=:height and @alt=""]',
[':path' =>
base_path() .
$path, ':url' =>
$url, ':width' =>
$image->
getWidth(), ':height' =>
$image->
getHeight()]);
$this->
assertCount(1,
$elements, 'theme_image_formatter() correctly renders without title, alt, or path options.'
);
// Link the image to a fragment on the page, and not a full URL.