You are here

public function TextimageThemeTest::testTextimageFormatterTheme in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Kernel/TextimageThemeTest.php \Drupal\Tests\textimage\Kernel\TextimageThemeTest::testTextimageFormatterTheme()

Test the Textimage formatter theme.

File

tests/src/Kernel/TextimageThemeTest.php, line 50

Class

TextimageThemeTest
Tests Textimage theme functions.

Namespace

Drupal\Tests\textimage\Kernel

Code

public function testTextimageFormatterTheme() {
  $textimage = $this->textimageFactory
    ->get();
  $textimage
    ->setStyle(ImageStyle::load('medium'))
    ->process([
    'one',
    'two',
  ])
    ->buildImage();

  // Test output of theme textimage_formatter.
  $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);

  // @todo changing behaviour in D8.1, need to watch #2646744
  $elements = $this
    ->cssSelect("a[href='{$abs_url}'] div.textimage-container-test img[src='{$rel_url}']");
  $this
    ->assertNotEmpty($elements, 'Textimage formatted correctly.');
}