View source
<?php
namespace Drupal\Tests\textimage\Kernel;
use Drupal\image\Entity\ImageStyle;
use Drupal\KernelTests\KernelTestBase;
class TextimageThemeTest extends KernelTestBase {
use TextimageTestTrait;
protected static $modules = [
'system',
'textimage',
'image',
'image_effects',
'user',
'file_mdm',
'file_mdm_font',
];
public function setUp() {
parent::setUp();
$this
->installConfig([
'system',
'textimage',
'image',
'image_effects',
'user',
'file_mdm',
'file_mdm_font',
]);
$this
->initTextimageTest();
}
public function testTextimageFormatterTheme() {
$textimage = $this->textimageFactory
->get();
$textimage
->setStyle(ImageStyle::load('medium'))
->process([
'one',
'two',
])
->buildImage();
$output = [
'#theme' => 'textimage_formatter',
'#uri' => $textimage
->getUri(),
'#width' => $textimage
->getWidth(),
'#height' => $textimage
->getHeight(),
'#alt' => 'Alternate text',
'#title' => 'Textimage title',
'#attributes' => [
'class' => 'textimage-test',
],
'#image_container_attributes' => [
'class' => [
'textimage-container-test',
],
],
'#anchor_url' => $textimage
->getUrl(),
];
$this
->setRawContent($this->renderer
->renderRoot($output));
$abs_url = $textimage
->getUrl()
->toString();
$rel_url = file_url_transform_relative($abs_url);
$elements = $this
->cssSelect("a[href='{$abs_url}'] div.textimage-container-test img[src='{$rel_url}']");
$this
->assertNotEmpty($elements, 'Textimage formatted correctly.');
}
}