diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..74e7c22 --- /dev/null +++ b/composer.json @@ -0,0 +1,10 @@ +{ + "name": "drupal/image_effects", + "type": "drupal-module", + "description": "Provides effects and operations for the Image API.", + "require": { + "drupal/core": ">=8.2.0", + "drupal/file_mdm_exif": "^1", + "drupal/file_mdm_font": "^1" + } +} diff --git a/image_effects.info.yml b/image_effects.info.yml index 471de38..a3a1987 100644 --- a/image_effects.info.yml +++ b/image_effects.info.yml @@ -7,6 +7,8 @@ configure: image_effects.settings dependencies: - drupal:image - drupal:system (>=8.2.0) + - file_mdm:file_mdm_exif + - file_mdm:file_mdm_font test_dependencies: - imagemagick:imagemagick - jquery_colorpicker:jquery_colorpicker diff --git a/image_effects.install b/image_effects.install index 9628638..a6e8d6b 100644 --- a/image_effects.install +++ b/image_effects.install @@ -11,25 +11,6 @@ function image_effects_requirements($phase) { $requirements = []; - // Check PHP EXIF extension for the auto_rotate image effect. - $requirements['image_effects_exif_extension'] = [ - 'title' => t('PHP EXIF extension'), - ]; - if (!extension_loaded('exif')) { - $requirements['image_effects_exif_extension'] += [ - 'value' => t('Not installed'), - 'description' => t('The PHP EXIF extension is not installed. Automatic image orientation effects will not be available with the GD image toolkit.'), - 'severity' => REQUIREMENT_WARNING, - ]; - } - else { - $requirements['image_effects_exif_extension'] += [ - 'value' => t('Enabled'), - 'severity' => REQUIREMENT_INFO, - ]; - - } - // Check PHP GD2 FreeType support. if (function_exists('gd_info')) { $info = gd_info(); diff --git a/src/Plugin/ImageEffect/AutoOrientImageEffect.php b/src/Plugin/ImageEffect/AutoOrientImageEffect.php index 3da623e..a2a446e 100644 --- a/src/Plugin/ImageEffect/AutoOrientImageEffect.php +++ b/src/Plugin/ImageEffect/AutoOrientImageEffect.php @@ -3,13 +3,12 @@ namespace Drupal\image_effects\Plugin\ImageEffect; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\image\ConfigurableImageEffectBase; +use Drupal\file_mdm\FileMetadataManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; /** * Automatically adjusts the orientation of an image resource. @@ -30,18 +29,11 @@ class AutoOrientImageEffect extends ConfigurableImageEffectBase implements ContainerFactoryPluginInterface { /** - * The MIME type guessing service. + * The file metadata manager service. * - * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface + * @var \Drupal\file_mdm\FileMetadataManagerInterface */ - protected $mimeTypeGuesser; - - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - protected $fileSystem; + protected $fileMetadataManager; /** * Constructs an AutoOrientImageEffect object. @@ -54,15 +46,12 @@ class AutoOrientImageEffect extends ConfigurableImageEffectBase implements Conta * The plugin implementation definition. * @param \Psr\Log\LoggerInterface $logger * A logger instance. - * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser - * The MIME type guessing service. - * @param \Drupal\Core\File\FileSystemInterface $file_system - * The file system service. + * @param \Drupal\file_mdm\FileMetadataManagerInterface $file_metadata_manager + * The file metadata manager service. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, LoggerInterface $logger, MimeTypeGuesserInterface $mime_type_guesser, FileSystemInterface $file_system) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, LoggerInterface $logger, FileMetadataManagerInterface $file_metadata_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition, $logger); - $this->mimeTypeGuesser = $mime_type_guesser; - $this->fileSystem = $file_system; + $this->fileMetadataManager = $file_metadata_manager; } /** @@ -74,8 +63,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $container->get('logger.factory')->get('image'), - $container->get('file.mime_type.guesser'), - $container->get('file_system') + $container->get('file_metadata_manager') ); } @@ -92,11 +80,6 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - if (!extension_loaded('exif')) { - // Issue a warning if the PHP EXIF extension is not enabled. - drupal_set_message($this->t('This image effect requires the PHP EXIF extension to be enabled to work properly.'), 'warning'); - } - $form['info'] = [ '#type' => 'details', '#title' => $this->t('Information'), @@ -161,30 +144,20 @@ public function applyEffect(ImageInterface $image) { * {@inheritdoc} */ public function transformDimensions(array &$dimensions, $uri) { - // Test to see if EXIF is supported by the image format. - $mime_type = $this->mimeTypeGuesser->guess($uri); - if (!in_array($mime_type, ['image/jpeg', 'image/tiff'])) { - // Not an EXIF enabled image, return. - return; - } if ($dimensions['width'] && $dimensions['height'] && $this->configuration['scan_exif']) { // Both dimensions in input, and effect is configured to check the // the input file. Read EXIF data, and determine image orientation. - if (($file_path = $this->fileSystem->realpath($uri)) && function_exists('exif_read_data')) { - if ($exif_data = @exif_read_data($file_path)) { - $orientation = isset($exif_data['Orientation']) ? $exif_data['Orientation'] : NULL; - if (in_array($orientation, [5, 6, 7, 8])) { - $tmp = $dimensions['width']; - $dimensions['width'] = $dimensions['height']; - $dimensions['height'] = $tmp; - } - return; - } + $file = $this->fileMetadataManager->uri($uri); + $orientation = $file->getMetadata('exif', 'Orientation')['value']; + if (in_array($orientation, [5, 6, 7, 8])) { + $tmp = $dimensions['width']; + $dimensions['width'] = $dimensions['height']; + $dimensions['height'] = $tmp; } + return; } // Either no full dimensions in input, or effect is configured to skip - // checking the input file, or EXIF extension is missing. Set both - // dimensions to NULL. + // checking the input file. Set both dimensions to NULL. $dimensions['width'] = $dimensions['height'] = NULL; } diff --git a/src/Plugin/ImageToolkit/Operation/FontOperationTrait.php b/src/Plugin/ImageToolkit/Operation/FontOperationTrait.php index 1a6c42d..ded8d06 100644 --- a/src/Plugin/ImageToolkit/Operation/FontOperationTrait.php +++ b/src/Plugin/ImageToolkit/Operation/FontOperationTrait.php @@ -2,49 +2,17 @@ namespace Drupal\image_effects\Plugin\ImageToolkit\Operation; -use Drupal\Core\StreamWrapper\LocalStream; - /** * Base trait for image toolkit operations that require font handling. */ trait FontOperationTrait { - /** - * The stream wrapper manager service. - * - * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface - */ - protected $streamWrapperManagerForFontHandling; - - /** - * An array of resolved font file URIs. - * - * @var array - */ - protected static $fontPaths = []; - - /** - * Return the real path of the specified file. - * - * @param string $uri - * An URI. - * - * @return string - * The local path of the file. - */ - protected function getRealFontPath($uri) { - $uri_wrapper = $this->getStreamWrapperManagerForFontHandling()->getViaUri($uri); - if ($uri_wrapper instanceof LocalStream) { - return $uri_wrapper->realpath(); - } - else { - return is_file($uri) ? $uri : NULL; - } - } - /** * Return the path of the font file. * + * The imagettf* GD functions, and ImageMagick toolkit, do not allow use of + * URIs to specify files. Always resolve the font file to a local path. + * * @param string $font_uri * The font URI. * @@ -55,26 +23,36 @@ protected function getFontPath($font_uri) { if (!$font_uri) { throw new \InvalidArgumentException('Font file not specified'); } - if (!isset(static::$fontPaths[$font_uri])) { - if (!$ret = $this->getRealFontPath($font_uri)) { - throw new \InvalidArgumentException("Could not find the font file {$font_uri}"); - } - static::$fontPaths[$font_uri] = $ret; + + // Determine if the $font_uri is a real URI or a local path. + $uri_wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($font_uri); + + // If local path, return it. + if ($uri_wrapper === FALSE) { + return $font_uri; } - return static::$fontPaths[$font_uri]; - } - /** - * Returns the stream wrapper manager service. - * - * @return \Drupal\Core\StreamWrapper\streamWrapperManagerInterface - * The stream wrapper manager service. - */ - protected function getStreamWrapperManagerForFontHandling() { - if (!$this->streamWrapperManagerForFontHandling) { - $this->streamWrapperManagerForFontHandling = \Drupal::service('stream_wrapper_manager'); + // Determine if a local path can be resolved for the URI. If so, return it. + $local_path = $uri_wrapper->realpath(); + if ($local_path !== FALSE) { + return $local_path; } - return $this->streamWrapperManagerForFontHandling; + + // If no local path available, the file may be stored in a remote file + // system. Use the file metadata manager service to copy the file to local + // temp and keep it there for further access within same request. It is not + // necessary to load its metadata. + $file = \Drupal::service('file_metadata_manager')->uri($font_uri); + $local_path = $file->getLocalTempPath(); + if ($local_path !== NULL) { + return $local_path; + } + elseif ($file->copyUriToTemp() === TRUE) { + return $file->getLocalTempPath(); + } + + // None of the above worked, file can not be accessed. + throw new \InvalidArgumentException("Cannot access font file '$font_uri'"); } } diff --git a/src/Plugin/ImageToolkit/Operation/gd/AutoOrient.php b/src/Plugin/ImageToolkit/Operation/gd/AutoOrient.php index d2c77ff..c05d30d 100644 --- a/src/Plugin/ImageToolkit/Operation/gd/AutoOrient.php +++ b/src/Plugin/ImageToolkit/Operation/gd/AutoOrient.php @@ -34,15 +34,10 @@ protected function execute(array $arguments) { return TRUE; } - // Will not work without EXIF extension installed. - if (!function_exists('exif_read_data')) { - $this->logger->notice('The image %file could not be auto-rotated because the exif_read_data() function is not available in this PHP installation. Check if the PHP EXIF extension is enabled.', ['%file' => $this->getToolkit()->getSource()]); - return FALSE; - } - // Read EXIF data. - $exif = @exif_read_data(\Drupal::service('file_system')->realpath($source_path)); - if (isset($exif['Orientation'])) { + $file = \Drupal::service('file_metadata_manager')->uri($source_path); + $orientation = $file->getMetadata('exif', 'Orientation')['value']; + if ($orientation !== NULL) { // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html: // 1 = Horizontal (normal) [top-left]. // 2 = Mirror horizontal [top-right]. @@ -52,7 +47,7 @@ protected function execute(array $arguments) { // 6 = Rotate 90 CW [right-top]. // 7 = Mirror horizontal and rotate 90 CW [right-bottom]. // 8 = Rotate 270 CW [left-bottom]. - switch ($exif['Orientation']) { + switch ($orientation) { case 2: return $this->getToolkit()->apply('mirror', ['x_axis' => TRUE]); diff --git a/src/Plugin/image_effects/FontSelector/Basic.php b/src/Plugin/image_effects/FontSelector/Basic.php index e3096dd..549b189 100644 --- a/src/Plugin/image_effects/FontSelector/Basic.php +++ b/src/Plugin/image_effects/FontSelector/Basic.php @@ -2,10 +2,13 @@ namespace Drupal\image_effects\Plugin\image_effects\FontSelector; -use Drupal\Component\Utility\Unicode; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\file_mdm\FileMetadataManagerInterface; use Drupal\image_effects\Plugin\ImageEffectsFontSelectorPluginInterface; use Drupal\image_effects\Plugin\ImageEffectsPluginBase; +use Psr\Log\LoggerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Basic font selector plugin. @@ -21,6 +24,48 @@ */ class Basic extends ImageEffectsPluginBase implements ImageEffectsFontSelectorPluginInterface { + /** + * The file metadata manager service. + * + * @var \Drupal\file_mdm\FileMetadataManagerInterface + */ + protected $fileMetadataManager; + + /** + * Constructs a ImageEffectsPluginBase object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The configuration factory. + * @param \Psr\Log\LoggerInterface $logger + * The image_effects logger. + * @param \Drupal\file_mdm\FileMetadataManagerInterface $file_metadata_manager + * The file metadata manager service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LoggerInterface $logger, FileMetadataManagerInterface $file_metadata_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $logger); + $this->fileMetadataManager = $file_metadata_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory'), + $container->get('logger.channel.image_effects'), + $container->get('file_metadata_manager') + ); + } + /** * {@inheritdoc} */ @@ -49,114 +94,7 @@ public function validateSelectorUri($element, FormStateInterface $form_state, $f * {@inheritdoc} */ public function getDescription($uri) { - return $this->getData($uri)['name']; - } - - /** - * Return the font information. - * - * Scans the font file to return tags information. - * - * @param string $uri - * the URI of the font file. - * - * @return array - * an associative array with the following keys: - * 'copyright' => Copyright information - * 'family' => Font family - * 'subfamily' => Font subfamily - * 'name' => Font name - * 'file' => Font file URI - */ - protected function getData($uri) { - $realpath = drupal_realpath($uri); - $fd = fopen($realpath, "r"); - $text = fread($fd, filesize($realpath)); - fclose($fd); - - $number_of_tabs = $this->dec2hex(ord($text[4])) . $this->dec2hex(ord($text[5])); - for ($i = 0; $i < hexdec($number_of_tabs); $i++) { - $tag = $text[12 + $i * 16] . $text[12 + $i * 16 + 1] . $text[12 + $i * 16 + 2] . $text[12 + $i * 16 + 3]; - if ($tag == "name") { - $offset_name_table_hex = $this->dec2hex(ord($text[12 + $i * 16 + 8])) . $this->dec2hex(ord($text[12 + $i * 16 + 8 + 1])) . $this->dec2hex(ord($text[12 + $i * 16 + 8 + 2])) . $this->dec2hex(ord($text[12 + $i * 16 + 8 + 3])); - $offset_name_table_dec = hexdec($offset_name_table_hex); - $offset_storage_hex = $this->dec2hex(ord($text[$offset_name_table_dec + 4])) . $this->dec2hex(ord($text[$offset_name_table_dec + 5])); - $offset_storage_dec = hexdec($offset_storage_hex); - $number_name_records_hex = $this->dec2hex(ord($text[$offset_name_table_dec + 2])) . $this->dec2hex(ord($text[$offset_name_table_dec + 3])); - $number_name_records_dec = hexdec($number_name_records_hex); - break; - } - } - - $storage_dec = $offset_storage_dec + $offset_name_table_dec; - $font = [ - 'copyright' => '', - 'family' => '', - 'subfamily' => '', - 'name' => '', - 'file' => $uri, - ]; - - for ($j = 0; $j < $number_name_records_dec; $j++) { - $name_id_hex = $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 6])) . $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 7])); - $name_id_dec = hexdec($name_id_hex); - $string_length_hex = $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 8])) . $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 9])); - $string_length_dec = hexdec($string_length_hex); - $string_offset_hex = $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 10])) . $this->dec2hex(ord($text[$offset_name_table_dec + 6 + $j * 12 + 11])); - $string_offset_dec = hexdec($string_offset_hex); - - if ($name_id_dec == 0 && empty($font['copyright'])) { - for ($l = 0; $l < $string_length_dec; $l++) { - if (ord($text[$storage_dec + $string_offset_dec + $l]) >= 32) { - $font['copyright'] .= $text[$storage_dec + $string_offset_dec + $l]; - } - } - } - - if ($name_id_dec == 1 && empty($font['family'])) { - for ($l = 0; $l < $string_length_dec; $l++) { - if (ord($text[$storage_dec + $string_offset_dec + $l]) >= 32) { - $font['family'] .= $text[$storage_dec + $string_offset_dec + $l]; - } - } - } - - if ($name_id_dec == 2 && empty($font['subfamily'])) { - for ($l = 0; $l < $string_length_dec; $l++) { - if (ord($text[$storage_dec + $string_offset_dec + $l]) >= 32) { - $font['subfamily'] .= $text[$storage_dec + $string_offset_dec + $l]; - } - } - } - - if ($name_id_dec == 4 && empty($font['name'])) { - for ($l = 0; $l < $string_length_dec; $l++) { - if (ord($text[$storage_dec + $string_offset_dec + $l]) >= 32) { - $font['name'] .= $text[$storage_dec + $string_offset_dec + $l]; - } - } - } - - if ($font['copyright'] != "" && $font['family'] != "" && $font['subfamily'] != "" && $font['name'] != "") { - break; - } - } - - return $font; - } - - /** - * Convert a dec to a hex. - * - * @param int $dec - * An integer number. - * - * @return string - * the number represented as hex - */ - protected function dec2hex($dec) { - $hex = dechex($dec); - return str_repeat("0", 2 - Unicode::strlen($hex)) . Unicode::strtoupper($hex); + return $this->fileMetadataManager->uri($uri)->getMetadata('font', 'FullName'); } } diff --git a/src/Plugin/image_effects/FontSelector/Dropdown.php b/src/Plugin/image_effects/FontSelector/Dropdown.php index 962e904..45803c2 100644 --- a/src/Plugin/image_effects/FontSelector/Dropdown.php +++ b/src/Plugin/image_effects/FontSelector/Dropdown.php @@ -108,10 +108,12 @@ protected function getList() { if (is_dir($this->configuration['path']) && $handle = opendir($this->configuration['path'])) { while ($file_name = readdir($handle)) { if (preg_match("/\.[ot]tf$/i", $file_name) == 1) { - $filelist[$file_name] = trim(substr($file_name, 0, -4)); - $font = $this->getData($this->configuration['path'] . '/' . $file_name); - if (!empty($font['name'])) { - $filelist[$file_name] = $font['name']; + $font_name = $this->getDescription($this->configuration['path'] . '/' . $file_name); + if ($font_name !== NULL) { + $filelist[$file_name] = $font_name; + } + else { + $filelist[$file_name] = trim(substr($file_name, 0, -4)); } } } diff --git a/src/Tests/Update/TextOverlayUpdateTest.php b/src/Tests/Update/TextOverlayUpdateTest.php index fa8a6fe..3a8a128 100644 --- a/src/Tests/Update/TextOverlayUpdateTest.php +++ b/src/Tests/Update/TextOverlayUpdateTest.php @@ -16,7 +16,9 @@ class TextOverlayUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} */ - protected static $modules = ['image_effects']; + protected static $modules = [ + 'image_effects', + ]; /** * {@inheritdoc} @@ -40,6 +42,8 @@ public function testTextOverlayUpdate() { $this->assertFalse(array_key_exists('decode_entities', $effect_data['text'])); // Run updates. + $modules = ['file_mdm', 'file_mdm_exif', 'file_mdm_font']; + $this->container->get('module_installer')->install($modules, TRUE); $this->runUpdates(); // Test that Text overlay effect has parameters introduced after diff --git a/src/Tests/Update/WatermarkUpdateTest.php b/src/Tests/Update/WatermarkUpdateTest.php index dd8d981..5b1ea55 100644 --- a/src/Tests/Update/WatermarkUpdateTest.php +++ b/src/Tests/Update/WatermarkUpdateTest.php @@ -49,6 +49,8 @@ public function testWatermarkUpdate() { $this->assertNull($effect_data['watermark_scale']); // Run updates. + $modules = ['file_mdm', 'file_mdm_exif', 'file_mdm_font']; + $this->container->get('module_installer')->install($modules, TRUE); $this->runUpdates(); // Test that Watermark effect has parameters as introduced in diff --git a/tests/src/Functional/Effect/AutoOrientTest.php b/tests/src/Functional/Effect/AutoOrientTest.php index 178f4b6..5eb8ee6 100644 --- a/tests/src/Functional/Effect/AutoOrientTest.php +++ b/tests/src/Functional/Effect/AutoOrientTest.php @@ -11,6 +11,14 @@ */ class AutoOrientTest extends ImageEffectsTestBase { + /** + * {@inheritdoc} + */ + public function setUp() { + static::$modules = array_merge(static::$modules, ['file_mdm', 'file_mdm_exif']); + parent::setUp(); + } + /** * Test effect on required toolkits. * diff --git a/tests/src/Functional/Effect/TextOverlayTest.php b/tests/src/Functional/Effect/TextOverlayTest.php index 3c46bd1..1a412cf 100644 --- a/tests/src/Functional/Effect/TextOverlayTest.php +++ b/tests/src/Functional/Effect/TextOverlayTest.php @@ -11,6 +11,14 @@ */ class TextOverlayTest extends ImageEffectsTestBase { + /** + * {@inheritdoc} + */ + public function setUp() { + static::$modules = array_merge(static::$modules, ['file_mdm', 'file_mdm_font', 'file_test']); + parent::setUp(); + } + /** * {@inheritdoc} */ @@ -43,7 +51,12 @@ public function testOnToolkits($toolkit_id, $toolkit_config, array $toolkit_sett * @depends testOnToolkits */ public function testTextOverlayEffect() { - // Add Text overlay effect to the test image style. + // Copy the font file to the test path. + file_unmanaged_copy(drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02/LinLibertine_Rah.ttf', 'dummy-remote://', FILE_EXISTS_REPLACE); + + // Add Text overlay effects to the test image style. + // Different ways to access the same font file, via URI (local and remote), + // and local path. $effect_config = [ 'id' => 'image_effects_text_overlay', 'data' => [ @@ -56,6 +69,30 @@ public function testTextOverlayEffect() { ], ]; $this->addEffectToTestStyle($effect_config); + $effect_config = [ + 'id' => 'image_effects_text_overlay', + 'data' => [ + 'text_default][text_string' => 'the quick brown fox jumps over the lazy dog', + 'font][uri' => 'public://LinLibertine_Rah.ttf', + 'font][size' => 10, + 'layout][position][extended_color][container][transparent' => FALSE, + 'layout][position][extended_color][container][hex' => '#FF00FF', + 'layout][position][extended_color][container][opacity' => 100, + ], + ]; + $this->addEffectToTestStyle($effect_config); + $effect_config = [ + 'id' => 'image_effects_text_overlay', + 'data' => [ + 'text_default][text_string' => 'the quick brown fox jumps over the lazy dog', + 'font][uri' => 'dummy-remote://LinLibertine_Rah.ttf', + 'font][size' => 10, + 'layout][position][extended_color][container][transparent' => FALSE, + 'layout][position][extended_color][container][hex' => '#FF00FF', + 'layout][position][extended_color][container][opacity' => 100, + ], + ]; + $this->addEffectToTestStyle($effect_config); $test_data = [ [ diff --git a/tests/src/Functional/SelectorPluginTest.php b/tests/src/Functional/SelectorPluginTest.php index 419447b..389e941 100644 --- a/tests/src/Functional/SelectorPluginTest.php +++ b/tests/src/Functional/SelectorPluginTest.php @@ -9,11 +9,19 @@ */ class SelectorPluginTest extends ImageEffectsTestBase { + /** + * Modules to install. + * + * @var array + */ public static $modules = [ 'image', 'image_effects', 'simpletest', 'image_effects_module_test', + 'file_test', + 'file_mdm', + 'file_mdm_font', ]; /** @@ -64,16 +72,25 @@ public function testImageSelector() { * Image selector test. */ public function testFontSelector() { - $font_path = drupal_get_path('module', 'image_effects') . '/tests/fonts/LinLibertineTTF_5.3.0_2012_07_02'; + $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) { + 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); + // 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, + 'font_uri' => $font_path . $font_file, ], ]; $uuid = $this->addEffectToTestStyle($effect); diff --git a/tests/src/Functional/SettingsFormTest.php b/tests/src/Functional/SettingsFormTest.php index 589bd68..9557aeb 100644 --- a/tests/src/Functional/SettingsFormTest.php +++ b/tests/src/Functional/SettingsFormTest.php @@ -11,7 +11,13 @@ */ class SettingsFormTest extends BrowserTestBase { - public static $modules = ['image_effects', 'jquery_colorpicker']; + public static $modules = [ + 'image_effects', + 'jquery_colorpicker', + 'file_mdm', + 'file_mdm_exif', + 'file_mdm_font', + ]; /** * {@inheritdoc}