You are here

public function SelectorPluginTest::testFontSelector in Image Effects 8.3

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

Image selector test.

File

tests/src/Functional/SelectorPluginTest.php, line 73

Class

SelectorPluginTest
Selector plugins test.

Namespace

Drupal\Tests\image_effects\Functional

Code

public function testFontSelector() {
  $font_path = 'dummy-remote://';
  $font_file = 'LinLibertine_Rah.ttf';
  $font_name = 'Linux Libertine';

  // Copy all the font files to the test path.
  $handle = opendir(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/');
  while ($file = readdir($handle)) {
    if (preg_match("/\\.[ot]tf\$/i", $file) == 1) {
      $this->fileSystem
        ->copy(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/' . $file, $font_path, FileSystemInterface::EXISTS_REPLACE);
    }
  }
  closedir($handle);

  // Test the Basic plugin.
  // Add an effect with the font selector.
  $effect = [
    'id' => 'image_effects_module_test_font_selection',
    'data' => [
      'font_uri' => $font_path . $font_file,
    ],
  ];
  $uuid = $this
    ->addEffectToTestStyle($effect);

  // Check that the font name is in the effect summary.
  $this
    ->assertSession()
    ->pageTextContains($font_name);

  // Test the Dropdown plugin.
  // Remove the effect.
  $this
    ->removeEffectFromTestStyle($uuid);

  // Change the settings.
  $config = \Drupal::configFactory()
    ->getEditable('image_effects.settings');
  $config
    ->set('font_selector.plugin_id', 'dropdown')
    ->set('font_selector.plugin_settings.dropdown.path', $font_path)
    ->save();

  // Add an effect with the font selector.
  $effect = [
    'id' => 'image_effects_module_test_font_selection',
    'data' => [
      'font_uri' => $font_file,
    ],
  ];
  $this
    ->addEffectToTestStyle($effect);

  // Check that the font name is in the effect summary.
  $this
    ->assertSession()
    ->pageTextContains($font_name);
}