You are here

public function TextimageApiTest::testTextAlteration in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/TextimageApiTest.php \Drupal\Tests\textimage\Kernel\TextimageApiTest::testTextAlteration()

Test text altering via the effect's alter hook.

File

tests/src/Kernel/TextimageApiTest.php, line 359

Class

TextimageApiTest
Kernel tests for Textimage API.

Namespace

Drupal\Tests\textimage\Kernel

Code

public function testTextAlteration() {
  $effects = [];
  $effects[] = [
    'id' => 'image_effects_text_overlay',
    'data' => [
      'text' => [
        'strip_tags' => TRUE,
        'decode_entities' => TRUE,
        'maximum_chars' => 12,
        'excess_chars_text' => ' [more]',
        'case_format' => 'upper',
      ],
      'text_string' => 'Test preview',
    ],
  ];
  $textimage = $this->textimageFactory
    ->get();
  $textimage
    ->setEffects($effects)
    ->process('the quick brown fox jumps over the lazy dog');
  $this
    ->assertSame([
    'THE QUICK BR [more]',
  ], $textimage
    ->getText());
  $effects = [];
  $effects[] = [
    'id' => 'image_effects_text_overlay',
    'data' => [
      'text' => [
        'strip_tags' => TRUE,
        'decode_entities' => TRUE,
        'case_format' => '',
        'maximum_chars' => NULL,
      ],
      'text_string' => 'Test preview',
    ],
  ];
  $textimage = $this->textimageFactory
    ->get();
  $textimage
    ->setEffects($effects)
    ->process('<p>Para1</p><!-- Comment --> Para2');
  $this
    ->assertSame([
    'Para1 Para2',
  ], $textimage
    ->getText());
  $textimage = $this->textimageFactory
    ->get();
  $textimage
    ->setEffects($effects)
    ->process('&quot;Title&quot; One &hellip;');
  $this
    ->assertSame([
    '"Title" One …',
  ], $textimage
    ->getText());
}