You are here

public function TextOverlayTest::testTextAlter in Image Effects 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/Effect/TextOverlayTest.php \Drupal\Tests\image_effects\Functional\Effect\TextOverlayTest::testTextAlter()
  2. 8.2 tests/src/Functional/Effect/TextOverlayTest.php \Drupal\Tests\image_effects\Functional\Effect\TextOverlayTest::testTextAlter()

Text alteration test.

File

tests/src/Functional/Effect/TextOverlayTest.php, line 145

Class

TextOverlayTest
Text overlay effect test.

Namespace

Drupal\Tests\image_effects\Functional\Effect

Code

public function testTextAlter() {

  // Add Text overlay effect to the test image style.
  $effect_config = [
    'id' => 'image_effects_text_overlay',
    'data' => [
      'text_default][text_string' => 'the quick brown fox jumps over the lazy dog',
      'font][uri' => drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf',
      'font][size' => 40,
      'layout][position][extended_color][container][transparent' => FALSE,
      'layout][position][extended_color][container][hex' => '#FF00FF',
      'layout][position][extended_color][container][opacity' => 100,
    ],
  ];
  $uuid = $this
    ->addEffectToTestStyle($effect_config);

  // Test text and HTML tags and entities.
  $effect = $this->testImageStyle
    ->getEffect($uuid);
  $this
    ->assertEquals('the quick brown fox jumps over the lazy dog', $effect
    ->getAlteredText($effect
    ->getConfiguration()['data']['text_string']));
  $this
    ->assertEquals('Para1 Para2', $effect
    ->getAlteredText('<p>Para1</p><!-- Comment --> Para2'));
  $this
    ->assertEquals('"Title" One …', $effect
    ->getAlteredText('&quot;Title&quot; One &hellip;'));
  $this
    ->removeEffectFromTestStyle($uuid);
  $effect_config['data'] += [
    'text_default][strip_tags' => FALSE,
    'text_default][decode_entities' => FALSE,
  ];
  $uuid = $this
    ->addEffectToTestStyle($effect_config);
  $effect = $this->testImageStyle
    ->getEffect($uuid);
  $this
    ->assertEquals('<p>Para1</p><!-- Comment --> Para2', $effect
    ->getAlteredText('<p>Para1</p><!-- Comment --> Para2'));
  $this
    ->assertEquals('&quot;Title&quot; One &hellip;', $effect
    ->getAlteredText('&quot;Title&quot; One &hellip;'));

  // Test converting to uppercase and trimming text.
  $this
    ->removeEffectFromTestStyle($uuid);
  $effect_config['data'] += [
    'text][maximum_chars' => 9,
    'text][case_format' => 'upper',
  ];
  $uuid = $this
    ->addEffectToTestStyle($effect_config);
  $effect = $this->testImageStyle
    ->getEffect($uuid);
  $this
    ->assertEquals('THE QUICK…', $effect
    ->getAlteredText($effect
    ->getConfiguration()['data']['text_string']));

  // Test converting to each word starting uppercase.
  $this
    ->removeEffectFromTestStyle($uuid);
  $effect_config['data']['text][case_format'] = 'ucwords';
  $effect_config['data']['text][maximum_chars'] = '';
  $uuid = $this
    ->addEffectToTestStyle($effect_config);
  $effect = $this->testImageStyle
    ->getEffect($uuid);
  $this
    ->assertEquals('The Quick Brown Fox Jumps Over The Lazy Dog', $effect
    ->getAlteredText($effect
    ->getConfiguration()['data']['text_string']));

  // Test converting to starting uppercase.
  $this
    ->removeEffectFromTestStyle($uuid);
  $effect_config['data']['text][case_format'] = 'ucfirst';
  $uuid = $this
    ->addEffectToTestStyle($effect_config);
  $effect = $this->testImageStyle
    ->getEffect($uuid);
  $this
    ->assertEquals('The quick brown fox jumps over the lazy dog', $effect
    ->getAlteredText($effect
    ->getConfiguration()['data']['text_string']));
}