View source
<?php
namespace Drupal\Tests\image_effects\Functional;
class SelectorPluginTest extends ImageEffectsTestBase {
public static $modules = [
'image',
'image_effects',
'image_effects_module_test',
'file_test',
'file_mdm',
'file_mdm_font',
];
public function testImageSelector() {
$image_path = drupal_get_path('module', 'image_effects') . '/tests/images';
$image_file = 'portrait-painting.jpe';
$effect = [
'id' => 'image_effects_module_test_image_selection',
'data' => [
'image_uri' => $image_path . '/' . $image_file,
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$this
->assertText($image_path . '/' . $image_file);
$this
->removeEffectFromTestStyle($uuid);
$config = \Drupal::configFactory()
->getEditable('image_effects.settings');
$config
->set('image_selector.plugin_id', 'dropdown')
->set('image_selector.plugin_settings.dropdown.path', $image_path)
->save();
$effect = [
'id' => 'image_effects_module_test_image_selection',
'data' => [
'image_uri' => $image_file,
],
];
$this
->addEffectToTestStyle($effect);
$this
->assertText($image_path . '/' . $image_file);
}
public function testFontSelector() {
$font_path = 'dummy-remote://';
$font_file = 'LinLibertine_Rah.ttf';
$font_name = 'Linux Libertine';
$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) {
file_unmanaged_copy(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/' . $file, $font_path, FILE_EXISTS_REPLACE);
}
}
closedir($handle);
$effect = [
'id' => 'image_effects_module_test_font_selection',
'data' => [
'font_uri' => $font_path . $font_file,
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$this
->assertText($font_name);
$this
->removeEffectFromTestStyle($uuid);
$config = \Drupal::configFactory()
->getEditable('image_effects.settings');
$config
->set('font_selector.plugin_id', 'dropdown')
->set('font_selector.plugin_settings.dropdown.path', $font_path)
->save();
$effect = [
'id' => 'image_effects_module_test_font_selection',
'data' => [
'font_uri' => $font_file,
],
];
$this
->addEffectToTestStyle($effect);
$this
->assertText($font_name);
}
}