Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -35,6 +35,14 @@ image.effect.image_crop:
|
|||
label: 'Anchor'
|
||||
type: string
|
||||
|
||||
image.effect.image_convert:
|
||||
type: mapping
|
||||
label: 'Convert'
|
||||
mapping:
|
||||
extension:
|
||||
label: 'Extension'
|
||||
type: string
|
||||
|
||||
image.effect.image_resize:
|
||||
type: image_size
|
||||
label: 'Image resize'
|
||||
|
|
3
core/modules/image/config/schema/image.source.schema.yml
Normal file
3
core/modules/image/config/schema/image.source.schema.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
migrate.source.d6_imagecache_presets:
|
||||
type: migrate_source_sql
|
||||
label: 'Drupal 6 ImageCache Presets'
|
|
@ -5,7 +5,6 @@
|
|||
* Administration pages for image settings.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
|
@ -20,8 +19,8 @@ use Drupal\Core\Render\Element;
|
|||
function template_preprocess_image_style_preview(&$variables) {
|
||||
// Style information.
|
||||
$style = $variables['style'];
|
||||
$variables['style_id'] = SafeMarkup::checkPlain($style->id());
|
||||
$variables['style_name'] = SafeMarkup::checkPlain($style->label());
|
||||
$variables['style_id'] = $style->id();
|
||||
$variables['style_name'] = $style->label();
|
||||
|
||||
// Cache bypass token.
|
||||
$variables['cache_bypass'] = REQUEST_TIME;
|
||||
|
|
|
@ -278,7 +278,7 @@ function template_preprocess_image_style(&$variables) {
|
|||
'height' => $variables['height'],
|
||||
);
|
||||
|
||||
$style->transformDimensions($dimensions);
|
||||
$style->transformDimensions($dimensions, $variables['uri']);
|
||||
|
||||
$variables['image'] = array(
|
||||
'#theme' => 'image',
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
id: d6_imagecache_presets
|
||||
label: Drupal 6 ImageCache Presets
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_imagecache_presets
|
||||
process:
|
||||
name:
|
||||
-
|
||||
plugin: machine_name
|
||||
source: presetname
|
||||
-
|
||||
plugin: dedupe_entity
|
||||
entity_type: image_style
|
||||
field: name
|
||||
length: 32
|
||||
label: presetname
|
||||
effects:
|
||||
plugin: d6_imagecache_actions
|
||||
source:
|
||||
- @plugin
|
||||
- data
|
||||
destination:
|
||||
plugin: entity:image_style
|
16
core/modules/image/migration_templates/d7_image_settings.yml
Executable file
16
core/modules/image/migration_templates/d7_image_settings.yml
Executable file
|
@ -0,0 +1,16 @@
|
|||
id: d7_image_settings
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- allow_insecure_derivatives
|
||||
- suppress_itok_output
|
||||
- image_style_preview_image
|
||||
process:
|
||||
suppress_itok_output: suppress_itok_output
|
||||
allow_insecure_derivatives: allow_insecure_derivatives
|
||||
preview_image: image_style_preview_image
|
||||
destination:
|
||||
plugin: config
|
||||
config_name: image.settings
|
|
@ -307,9 +307,9 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
foreach ($this->getEffects() as $effect) {
|
||||
$effect->transformDimensions($dimensions);
|
||||
$effect->transformDimensions($dimensions, $uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\image\ConfigurableImageEffectInterface;
|
||||
use Drupal\image\ImageEffectManager;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -99,7 +98,7 @@ class ImageStyleEditForm extends ImageStyleFormBase {
|
|||
'#tree' => FALSE,
|
||||
'data' => array(
|
||||
'label' => array(
|
||||
'#markup' => SafeMarkup::checkPlain($effect->label()),
|
||||
'#plain_text' => $effect->label(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -70,7 +70,7 @@ abstract class ImageEffectBase extends PluginBase implements ImageEffectInterfac
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
// Most image effects will not change the dimensions. This base
|
||||
// implementation represents this behavior. Override this method if your
|
||||
// image effect does change the dimensions.
|
||||
|
|
|
@ -43,8 +43,16 @@ interface ImageEffectInterface extends PluginInspectionInterface, ConfigurablePl
|
|||
* - height: the height in pixels, or NULL if unknown
|
||||
* When either of the dimensions are NULL, the corresponding HTML attribute
|
||||
* will be omitted when an image style using this image effect is used.
|
||||
* @param string $uri
|
||||
* Original image file URI. It is passed in to allow an effect to
|
||||
* optionally use this information to retrieve additional image metadata
|
||||
* to determine dimensions of the styled image.
|
||||
* ImageEffectInterface::transformDimensions key objective is to calculate
|
||||
* styled image dimensions without performing actual image operations, so
|
||||
* be aware that performing IO on the URI may lead to decrease in
|
||||
* performance.
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions);
|
||||
public function transformDimensions(array &$dimensions, $uri);
|
||||
|
||||
/**
|
||||
* Returns the extension the derivative would have have after applying this
|
||||
|
|
|
@ -127,8 +127,18 @@ interface ImageStyleInterface extends ConfigEntityInterface {
|
|||
* @param array $dimensions
|
||||
* Associative array passed by reference. Implementations have to store the
|
||||
* resulting width and height, in pixels.
|
||||
* @param string $uri
|
||||
* Original image file URI. It is passed in to allow effects to
|
||||
* optionally use this information to retrieve additional image metadata
|
||||
* to determine dimensions of the styled image.
|
||||
* ImageStyleInterface::transformDimensions key objective is to calculate
|
||||
* styled image dimensions without performing actual image operations, so
|
||||
* be aware that performing IO on the URI may lead to decrease in
|
||||
* performance.
|
||||
*
|
||||
* @see ImageEffectInterface::transformDimensions
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions);
|
||||
public function transformDimensions(array &$dimensions, $uri);
|
||||
|
||||
/**
|
||||
* Determines the extension of the derivative without generating it.
|
||||
|
|
|
@ -67,7 +67,7 @@ class ImageStyleListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $this->getLabel($entity);
|
||||
$row['label'] = $entity->label();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class ImageWidget extends FileWidget {
|
|||
if ($cardinality == 1) {
|
||||
// If there's only one field, return it as delta 0.
|
||||
if (empty($elements[0]['#default_value']['fids'])) {
|
||||
$file_upload_help['#description'] = $this->fieldFilterXss($this->fieldDefinition->getDescription());
|
||||
$file_upload_help['#description'] = $this->fieldDefinition->getDescription();
|
||||
$elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class ResizeImageEffect extends ConfigurableImageEffectBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
// The new image will have the exact dimensions defined for the effect.
|
||||
$dimensions['width'] = $this->configuration['width'];
|
||||
$dimensions['height'] = $this->configuration['height'];
|
||||
|
|
|
@ -42,7 +42,7 @@ class RotateImageEffect extends ConfigurableImageEffectBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
// If the rotate is not random and the angle is a multiple of 90 degrees,
|
||||
// then the new dimensions can be determined.
|
||||
if (!$this->configuration['random'] && ((int) ($this->configuration['degrees']) == $this->configuration['degrees']) && ($this->configuration['degrees'] % 90 == 0)) {
|
||||
|
|
|
@ -36,7 +36,7 @@ class ScaleImageEffect extends ResizeImageEffect {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
if ($dimensions['width'] && $dimensions['height']) {
|
||||
Image::scaleDimensions($dimensions, $this->configuration['width'], $this->configuration['height'], $this->configuration['upscale']);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\image\Plugin\migrate\destination\EntityImageStyle.
|
||||
*/
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Every migration that uses this destination must have an optional
|
||||
* dependency on the d6_file migration to ensure it runs first.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "entity:image_style"
|
||||
* )
|
||||
*/
|
||||
class EntityImageStyle extends EntityConfigBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$effects = [];
|
||||
|
||||
// Need to set the effects property to null on the row before the ImageStyle
|
||||
// is created, this prevents improper effect plugin initialization.
|
||||
if ($row->getDestinationProperty('effects')) {
|
||||
$effects = $row->getDestinationProperty('effects');
|
||||
$row->setDestinationProperty('effects', []);
|
||||
}
|
||||
|
||||
/** @var \Drupal\Image\Entity\ImageStyle $style */
|
||||
$style = $this->getEntity($row, $old_destination_id_values);
|
||||
|
||||
// Iterate the effects array so each effect plugin can be initialized.
|
||||
// Catch any missing plugin exceptions.
|
||||
foreach ($effects as $effect) {
|
||||
try {
|
||||
$style->addImageEffect($effect);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
throw new MigrateException($e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
$style->save();
|
||||
|
||||
return array($style->id());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* contains \Drupal\image\Plugin\migrate\process\d6\ImageCacheActions.
|
||||
*/
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_imagecache_actions"
|
||||
* )
|
||||
*/
|
||||
class ImageCacheActions extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$effects = [];
|
||||
|
||||
foreach($row->getSourceProperty('actions') as $action) {
|
||||
$id = preg_replace('/^imagecache/', 'image', $action['action']);
|
||||
|
||||
if ($id === 'image_crop') {
|
||||
$action['data']['anchor'] = $action['data']['xoffset'] . '-' . $action['data']['yoffset'];
|
||||
|
||||
if (!preg_match('/^[a-z]*\-[a-z]*/', $action['data']['anchor'])) {
|
||||
$migrate_executable->message->display(
|
||||
'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.',
|
||||
'error'
|
||||
);
|
||||
}
|
||||
|
||||
unset($action['data']['xoffset']);
|
||||
unset($action['data']['yoffset']);
|
||||
}
|
||||
|
||||
$effects[] = [
|
||||
'id' => $id,
|
||||
'weight' => $action['weight'],
|
||||
'data' => $action['data'],
|
||||
];
|
||||
}
|
||||
|
||||
return $effects;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\image\Plugin\migrate\source\d6\ImageCachePreset.
|
||||
*/
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Drupal 6 imagecache presets source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_imagecache_presets"
|
||||
* )
|
||||
*/
|
||||
class ImageCachePreset extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('imagecache_preset', 'icp')
|
||||
->fields('icp');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = [
|
||||
'presetid' => $this->t('Preset ID'),
|
||||
'presetname' => $this->t('Preset Name'),
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['presetid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$actions = array();
|
||||
|
||||
$results = $this->select('imagecache_action', 'ica')
|
||||
->fields('ica')
|
||||
->condition('presetid', $row->getSourceProperty('presetid'))
|
||||
->execute();
|
||||
|
||||
foreach($results as $key => $result) {
|
||||
$actions[$key] = $result;
|
||||
$actions[$key]['data'] = unserialize($result['data']);
|
||||
}
|
||||
|
||||
$row->setSourceProperty('actions', $actions);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\image\Tests;
|
||||
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +40,7 @@ class ImageDimensionsTest extends WebTestBase {
|
|||
/** @var $style \Drupal\image\ImageStyleInterface */
|
||||
$style = entity_create('image_style', array('name' => 'test', 'label' => 'Test'));
|
||||
$style->save();
|
||||
$generated_uri = 'public://styles/test/public/'. drupal_basename($original_uri);
|
||||
$generated_uri = 'public://styles/test/public/'. \Drupal::service('file_system')->basename($original_uri);
|
||||
$url = $style->buildUrl($original_uri);
|
||||
|
||||
$variables = array(
|
||||
|
@ -231,6 +232,48 @@ class ImageDimensionsTest extends WebTestBase {
|
|||
$style->addImageEffect($effect);
|
||||
$style->save();
|
||||
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" alt="" class="image-style-test" />');
|
||||
|
||||
// Test URI dependent image effect.
|
||||
$style = ImageStyle::create(['name' => 'test_uri', 'label' => 'Test URI']);
|
||||
$effect = [
|
||||
'id' => 'image_module_test_uri_dependent',
|
||||
'data' => [],
|
||||
'weight' => 0,
|
||||
];
|
||||
$style->addImageEffect($effect);
|
||||
$style->save();
|
||||
$variables = [
|
||||
'#theme' => 'image_style',
|
||||
'#style_name' => 'test_uri',
|
||||
'#uri' => $original_uri,
|
||||
'#width' => 40,
|
||||
'#height' => 20,
|
||||
];
|
||||
// PNG original image. Should be resized to 100x100.
|
||||
$generated_uri = 'public://styles/test_uri/public/'. \Drupal::service('file_system')->basename($original_uri);
|
||||
$url = $style->buildUrl($original_uri);
|
||||
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="100" height="100" alt="" class="image-style-test-uri" />');
|
||||
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
|
||||
$this->drupalGet($url);
|
||||
$this->assertResponse(200, 'Image was generated at the URL.');
|
||||
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
|
||||
$image_file = $image_factory->get($generated_uri);
|
||||
$this->assertEqual($image_file->getWidth(), 100);
|
||||
$this->assertEqual($image_file->getHeight(), 100);
|
||||
// GIF original image. Should be resized to 50x50.
|
||||
$file = $files[1];
|
||||
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
|
||||
$generated_uri = 'public://styles/test_uri/public/'. \Drupal::service('file_system')->basename($original_uri);
|
||||
$url = $style->buildUrl($original_uri);
|
||||
$variables['#uri'] = $original_uri;
|
||||
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="50" height="50" alt="" class="image-style-test-uri" />');
|
||||
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
|
||||
$this->drupalGet($url);
|
||||
$this->assertResponse(200, 'Image was generated at the URL.');
|
||||
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
|
||||
$image_file = $image_factory->get($generated_uri);
|
||||
$this->assertEqual($image_file->getWidth(), 50);
|
||||
$this->assertEqual($image_file->getHeight(), 50);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -337,7 +337,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
$this->drupalGet('node/' . $node->id());
|
||||
// Verify that no image is displayed on the page by checking for the class
|
||||
// that would be used on the image field.
|
||||
$this->assertNoPattern('<div class="(.*?)field-name-' . strtr($field_name, '_', '-') . '(.*?)">', 'No image displayed when no image is attached and no default image specified.');
|
||||
$this->assertNoPattern('<div class="(.*?)field--name-' . strtr($field_name, '_', '-') . '(.*?)">', 'No image displayed when no image is attached and no default image specified.');
|
||||
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
|
||||
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
|
||||
|
||||
|
|
|
@ -70,11 +70,11 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
|||
$this->uploadNodeImage($image, $field_name, 'article');
|
||||
|
||||
// Look for form-required for the alt text.
|
||||
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-alt" and @class="form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-alt"]');
|
||||
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-alt" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-alt"]');
|
||||
|
||||
$this->assertTrue(isset($elements[0]),'Required marker is shown for the required alt text.');
|
||||
|
||||
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-title" and @class="form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-title"]');
|
||||
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-title" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-title"]');
|
||||
|
||||
$this->assertTrue(isset($elements[0]), 'Required marker is shown for the required title text.');
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class ImageItemTest extends FieldUnitTestBase {
|
|||
$this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid());
|
||||
|
||||
// Make sure the computed entity reflects updates to the referenced file.
|
||||
file_unmanaged_copy(\Drupal::root() . '/core/misc/feed.png', 'public://example-2.jpg');
|
||||
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg');
|
||||
$image2 = entity_create('file', array(
|
||||
'uri' => 'public://example-2.jpg',
|
||||
));
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate_drupal\Tests\d6\MigrateImageCacheTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\image\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use \Drupal\image\ConfigurableImageEffectBase;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate ImageCache presets to Image styles
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class MigrateImageCacheTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('image');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->prepareMigrations(array(
|
||||
'd6_imagecache_presets' => [],
|
||||
));
|
||||
$this->installConfig(['image']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent to setup migration prior to run.
|
||||
*/
|
||||
public function testSourcePlugin() {
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
parent::testSourcePlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic passing migrations.
|
||||
*/
|
||||
public function testPassingMigration() {
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
|
||||
/** @var \Drupal\image\Entity\ImageStyle $style */
|
||||
$style = ImageStyle::load('big_blue_cheese');
|
||||
|
||||
// Check basic Style info.
|
||||
$this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly');
|
||||
$this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly');
|
||||
|
||||
// Test effects.
|
||||
$effects = $style->getEffects();
|
||||
|
||||
// Check crop effect.
|
||||
$this->assertImageEffect($effects, 'image_crop', [
|
||||
'width' => 555,
|
||||
'height' => 5555,
|
||||
'anchor' => 'center-center',
|
||||
]);
|
||||
|
||||
// Check resize effect.
|
||||
$this->assertImageEffect($effects, 'image_resize', [
|
||||
'width' => 55,
|
||||
'height' => 55,
|
||||
]);
|
||||
|
||||
// Check rotate effect.
|
||||
$this->assertImageEffect($effects, 'image_rotate', [
|
||||
'degrees' => 55,
|
||||
'random' => FALSE,
|
||||
'bgcolor' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing actions causes failures.
|
||||
*/
|
||||
public function testMissingEffectPlugin() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_deprecated_scale',
|
||||
'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}',
|
||||
])->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator();
|
||||
$count = 0;
|
||||
foreach ($messages as $message) {
|
||||
$count++;
|
||||
$this->assertEqual($message->message, 'The "image_deprecated_scale" plugin does not exist.');
|
||||
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
// There should be only the one message.
|
||||
$this->assertEqual($count, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing action's causes failures.
|
||||
*/
|
||||
public function testInvalidCropValues() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_crop',
|
||||
'data' => serialize([
|
||||
'xoffset' => '10',
|
||||
'yoffset' => '10',
|
||||
]),
|
||||
])->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$this->assertEqual(['error' => [
|
||||
'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.'
|
||||
]], $this->migrateMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a given image effect is migrated.
|
||||
*
|
||||
* @param array $collection
|
||||
* Collection of effects
|
||||
* @param $id
|
||||
* Id that should exist in the collection.
|
||||
* @param $config
|
||||
* Expected configuration for the collection.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function assertImageEffect($collection, $id, $config) {
|
||||
/** @var \Drupal\image\ConfigurableImageEffectBase $effect */
|
||||
foreach ($collection as $key => $effect) {
|
||||
$effect_config = $effect->getConfiguration();
|
||||
|
||||
if ($effect_config['id'] == $id && $effect_config['data'] == $config) {
|
||||
// We found this effect so succeed and return.
|
||||
return $this->pass('Effect ' . $id . ' imported correctly');
|
||||
}
|
||||
}
|
||||
// The loop did not find the effect so we it was not imported correctly.
|
||||
return $this->fail('Effect ' . $id . ' did not import correctly');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\image\Tests\Migrate\d7\MigrateImageSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\image\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of Image variables to configuration.
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class MigrateImageSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['image'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_image_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$config = $this->config('image.settings');
|
||||
// These settings are not recommended...
|
||||
$this->assertTrue($config->get('allow_insecure_derivatives'));
|
||||
$this->assertTrue($config->get('suppress_itok_output'));
|
||||
$this->assertIdentical("core/modules/image/testsample.png",$config->get('preview_image'));
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ namespace Drupal\image\Tests\Views;
|
|||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\views\Tests\ViewUnitTestBase;
|
||||
use Drupal\views\Tests\ViewKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ use Drupal\views\Views;
|
|||
*
|
||||
* @group image
|
||||
*/
|
||||
class ImageViewsDataTest extends ViewUnitTestBase {
|
||||
class ImageViewsDataTest extends ViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
|
|
|
@ -23,7 +23,7 @@ class NullTestImageEffect extends ImageEffectBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions) {
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
// Unset image dimensions.
|
||||
$dimensions['width'] = $dimensions['height'] = NULL;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\image_module_test\Plugin\ImageEffect\UriDependentTestImageEffect.
|
||||
*/
|
||||
|
||||
namespace Drupal\image_module_test\Plugin\ImageEffect;
|
||||
|
||||
use Drupal\Core\Image\ImageInterface;
|
||||
use Drupal\image\ImageEffectBase;
|
||||
|
||||
/**
|
||||
* Performs an image operation that depends on the URI of the original image.
|
||||
*
|
||||
* @ImageEffect(
|
||||
* id = "image_module_test_uri_dependent",
|
||||
* label = @Translation("URI dependent test image effect")
|
||||
* )
|
||||
*/
|
||||
class UriDependentTestImageEffect extends ImageEffectBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transformDimensions(array &$dimensions, $uri) {
|
||||
$dimensions = $this->getUriDependentDimensions($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyEffect(ImageInterface $image) {
|
||||
$dimensions = $this->getUriDependentDimensions($image->getSource());
|
||||
return $image->resize($dimensions['width'], $dimensions['height']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the image dimensions dependent on the image file extension.
|
||||
*
|
||||
* @param string $uri
|
||||
* Original image file URI.
|
||||
*
|
||||
* @return array
|
||||
* Associative array.
|
||||
* - width: Integer with the derivative image width.
|
||||
* - height: Integer with the derivative image height.
|
||||
*/
|
||||
protected function getUriDependentDimensions($uri) {
|
||||
$dimensions = [];
|
||||
$extension = pathinfo($uri, PATHINFO_EXTENSION);
|
||||
switch (strtolower($extension)) {
|
||||
case 'png':
|
||||
$dimensions['width'] = $dimensions['height'] = 100;
|
||||
break;
|
||||
|
||||
case 'gif':
|
||||
$dimensions['width'] = $dimensions['height'] = 50;
|
||||
break;
|
||||
|
||||
default:
|
||||
$dimensions['width'] = $dimensions['height'] = 20;
|
||||
break;
|
||||
|
||||
}
|
||||
return $dimensions;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue