You are here

public function TextimageTestTrait::initTextimageTest in Textimage 8.4

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

Common test initialization tasks.

3 calls to TextimageTestTrait::initTextimageTest()
TextimageApiTest::setUp in tests/src/Kernel/TextimageApiTest.php
TextimageTestBase::setUp in tests/src/Functional/TextimageTestBase.php
TextimageThemeTest::setUp in tests/src/Kernel/TextimageThemeTest.php

File

tests/src/Kernel/TextimageTestTrait.php, line 43

Class

TextimageTestTrait
Trait to manage Textimage setup tasks common across tests.

Namespace

Drupal\Tests\textimage\Kernel

Code

public function initTextimageTest() {

  // Load services.
  $this->textimageFactory = \Drupal::service('textimage.factory');
  $this->renderer = \Drupal::service('renderer');
  $this->fileSystem = \Drupal::service('file_system');
  $this->entityDisplayRepository = \Drupal::service('entity_display.repository');

  // Change Image Effects settings.
  $config = \Drupal::configFactory()
    ->getEditable('image_effects.settings');
  $config
    ->set('image_selector.plugin_id', 'dropdown')
    ->set('image_selector.plugin_settings.dropdown.path', drupal_get_path('module', 'image_effects') . '/tests/images')
    ->set('font_selector.plugin_id', 'dropdown')
    ->set('font_selector.plugin_settings.dropdown.path', drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02')
    ->save();

  // Change Textimage settings.
  $config = \Drupal::configFactory()
    ->getEditable('textimage.settings');
  $config
    ->set('url_generation.enabled', TRUE)
    ->set('debug', TRUE)
    ->set('default_font.name', 'Linux Libertine')
    ->set('default_font.uri', drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf')
    ->save();

  // Create a test image style, with a image_effects_text_overlay effect.
  $style = ImageStyle::create([
    'name' => 'textimage_test',
    'label' => 'Textimage Test',
  ]);
  $style
    ->addImageEffect([
    'id' => 'image_effects_text_overlay',
    'data' => [
      'font' => [
        'name' => 'Linux Libertine',
        'uri' => drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf',
        'size' => 16,
        'angle' => 0,
        'color' => '#000000FF',
        'stroke_mode' => 'outline',
        'stroke_color' => '#000000FF',
        'outline_top' => 0,
        'outline_right' => 0,
        'outline_bottom' => 0,
        'outline_left' => 0,
        'shadow_x_offset' => 1,
        'shadow_y_offset' => 1,
        'shadow_width' => 0,
        'shadow_height' => 0,
      ],
      'layout' => [
        'padding_top' => 0,
        'padding_right' => 0,
        'padding_bottom' => 0,
        'padding_left' => 0,
        'x_pos' => 'center',
        'y_pos' => 'center',
        'x_offset' => 0,
        'y_offset' => 0,
        'background_color' => NULL,
        'overflow_action' => 'extend',
        'extended_color' => NULL,
      ],
      'text' => [
        'strip_tags' => TRUE,
        'decode_entities' => TRUE,
        'maximum_width' => 0,
        'fixed_width' => FALSE,
        'align' => 'left',
        'line_spacing' => 0,
        'case_format' => '',
        'maximum_chars' => NULL,
        'excess_chars_text' => '…',
      ],
      'text_string' => 'Test preview',
    ],
  ]);
  $style
    ->save();
}