Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes

This commit is contained in:
Pantheon Automation 2016-04-20 09:56:34 -07:00 committed by Greg Anderson
parent b11a755ba8
commit c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Annotation\ImageEffect.
*/
namespace Drupal\image\Annotation;
use Drupal\Component\Annotation\Plugin;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ConfigurableImageEffectBase.
*/
namespace Drupal\image;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ConfigurableImageEffectInterface.
*/
namespace Drupal\image;
use Drupal\Core\Plugin\PluginFormInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Controller\ImageStyleDownloadController.
*/
namespace Drupal\image\Controller;
use Drupal\Component\Utility\Crypt;
@ -12,7 +7,6 @@ use Drupal\Core\Image\ImageFactory;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\image\ImageStyleInterface;
use Drupal\system\FileDownloadController;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
@ -53,13 +47,11 @@ class ImageStyleDownloadController extends FileDownloadController {
* The lock backend.
* @param \Drupal\Core\Image\ImageFactory $image_factory
* The image factory.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, LoggerInterface $logger) {
public function __construct(LockBackendInterface $lock, ImageFactory $image_factory) {
$this->lock = $lock;
$this->imageFactory = $image_factory;
$this->logger = $logger;
$this->logger = $this->getLogger('image');
}
/**
@ -68,8 +60,7 @@ class ImageStyleDownloadController extends FileDownloadController {
public static function create(ContainerInterface $container) {
return new static(
$container->get('lock'),
$container->get('image.factory'),
$container->get('logger.factory')->get('image')
$container->get('image.factory')
);
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Entity\ImageStyle.
*/
namespace Drupal\image\Entity;
use Drupal\Core\Cache\Cache;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageEffectAddForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageEffectDeleteForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\ConfirmFormBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageEffectEditForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageEffectFormBase.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\FormBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleAddForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleDeleteForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityDeleteForm;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleEditForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityStorageInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleFlushForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleFormBase.
*/
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityForm;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageEffectBase.
*/
namespace Drupal\image;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageEffectInterface.
*/
namespace Drupal\image;
use Drupal\Component\Plugin\ConfigurablePluginInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageEffectManager.
*/
namespace Drupal\image;
use Drupal\Core\Cache\CacheBackendInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageEffectPluginCollection.
*/
namespace Drupal\image;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageStyleInterface.
*/
namespace Drupal\image;
use Drupal\Core\Config\Entity\ConfigEntityInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageStyleListBuilder.
*/
namespace Drupal\image;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageStyleStorage.
*/
namespace Drupal\image;
use Drupal\Core\Config\Entity\ConfigEntityStorage;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\ImageStyleStorageInterface.
*/
namespace Drupal\image;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\PageCache\DenyPrivateImageStyleDownload.
*/
namespace Drupal\image\PageCache;
use Drupal\Core\PageCache\ResponsePolicyInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\PathProcessor\PathProcessorImageStyles.
*/
namespace Drupal\image\PathProcessor;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter.
*/
namespace Drupal\image\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityStorageInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase.
*/
namespace Drupal\image\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\Field\FieldType\ImageItem.
*/
namespace Drupal\image\Plugin\Field\FieldType;
use Drupal\Component\Utility\Random;
@ -213,7 +208,7 @@ class ImageItem extends FileItem {
'#weight' => 4.1,
'#field_prefix' => '<div class="container-inline">',
'#field_suffix' => '</div>',
'#description' => t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href=":url">EXIF data</a> in the image.', array(':url' => 'http://en.wikipedia.org/wiki/Exchangeable_image_file_format')),
'#description' => t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
);
$element['max_resolution']['x'] = array(
'#type' => 'number',

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\Field\FieldWidget\ImageWidget.
*/
namespace Drupal\image\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
@ -98,7 +93,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->fieldDefinition->getDescription();
$file_upload_help['#description'] = $this->getFilteredDescription();
$elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\ConvertImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Component\Utility\Unicode;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\CropImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\DesaturateImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\ResizeImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;

View file

@ -1,13 +1,9 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\RotateImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Component\Utility\Color;
use Drupal\Component\Utility\Rectangle;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ConfigurableImageEffectBase;
@ -43,14 +39,13 @@ class RotateImageEffect extends ConfigurableImageEffectBase {
* {@inheritdoc}
*/
public function transformDimensions(array &$dimensions, $uri) {
// If the rotate is not random and the angle is a multiple of 90 degrees,
// If the rotate is not random and current dimensions are set,
// then the new dimensions can be determined.
if (!$this->configuration['random'] && ((int) ($this->configuration['degrees']) == $this->configuration['degrees']) && ($this->configuration['degrees'] % 90 == 0)) {
if ($this->configuration['degrees'] % 180 != 0) {
$temp = $dimensions['width'];
$dimensions['width'] = $dimensions['height'];
$dimensions['height'] = $temp;
}
if (!$this->configuration['random'] && $dimensions['width'] && $dimensions['height']) {
$rect = new Rectangle($dimensions['width'], $dimensions['height']);
$rect = $rect->rotate($this->configuration['degrees']);
$dimensions['width'] = $rect->getBoundingWidth();
$dimensions['height'] = $rect->getBoundingHeight();
}
else {
$dimensions['width'] = $dimensions['height'] = NULL;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\ScaleAndCropImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\ImageEffect\ScaleImageEffect.
*/
namespace Drupal\image\Plugin\ImageEffect;
use Drupal\Component\Utility\Image;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\migrate\destination\EntityImageStyle.
*/
namespace Drupal\image\Plugin\migrate\destination;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* contains \Drupal\image\Plugin\migrate\process\d6\ImageCacheActions.
*/
namespace Drupal\image\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?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;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Plugin\migrate\source\d7\ImageStyles.
*/
namespace Drupal\image\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Routing\ImageStyleRoutes.
*/
namespace Drupal\image\Routing;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;

View file

@ -1,12 +1,8 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\FileMoveTest.
*/
namespace Drupal\image\Tests;
use Drupal\file\Entity\File;
use Drupal\simpletest\WebTestBase;
use Drupal\image\Entity\ImageStyle;
@ -29,7 +25,7 @@ class FileMoveTest extends WebTestBase {
*/
function testNormal() {
// Pick a file for testing.
$file = entity_create('file', (array) current($this->drupalGetTestFiles('image')));
$file = File::create((array) current($this->drupalGetTestFiles('image')));
// Create derivative image.
$styles = ImageStyle::loadMultiple();

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageAdminStylesTest.
*/
namespace Drupal\image\Tests;
use Drupal\Component\Utility\SafeMarkup;
@ -339,7 +334,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// Create a new style.
$style_name = strtolower($this->randomMachineName(10));
$style_label = $this->randomString();
$style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label));
$style = ImageStyle::create(array('name' => $style_name, 'label' => $style_label));
$style->save();
$style_path = 'admin/config/media/image-styles/manage/';
@ -444,7 +439,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// Create a new style.
$style_name = strtolower($this->randomMachineName(10));
$style = entity_create('image_style', array('name' => $style_name, 'label' => $this->randomString()));
$style = ImageStyle::create(array('name' => $style_name, 'label' => $this->randomString()));
$style->save();
// Create an image to make sure it gets flushed.
@ -474,7 +469,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// Create a new style.
$style_name = strtolower($this->randomMachineName(10));
$style_label = $this->randomString();
$style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label));
$style = ImageStyle::create(array('name' => $style_name, 'label' => $style_label));
$style->save();
// Create an image field that uses the new style.
@ -520,7 +515,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
* Tests access for the image style listing.
*/
public function testImageStyleAccess() {
$style = entity_create('image_style', array('name' => 'style_foo', 'label' => $this->randomString()));
$style = ImageStyle::create(array('name' => 'style_foo', 'label' => $this->randomString()));
$style->save();
$this->drupalGet('admin/config/media/image-styles');

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageDimensionsTest.
*/
namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;
@ -38,7 +33,7 @@ class ImageDimensionsTest extends WebTestBase {
// Create a style.
/** @var $style \Drupal\image\ImageStyleInterface */
$style = entity_create('image_style', array('name' => 'test', 'label' => 'Test'));
$style = ImageStyle::create(array('name' => 'test', 'label' => 'Test'));
$style->save();
$generated_uri = 'public://styles/test/public/'. \Drupal::service('file_system')->basename($original_uri);
$url = file_url_transform_relative($style->buildUrl($original_uri));
@ -213,11 +208,14 @@ class ImageDimensionsTest extends WebTestBase {
$effect_id = $style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" alt="" class="image-style-test" />');
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="41" height="41" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($this->getAbsoluteUrl($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(), 41);
$this->assertEqual($image_file->getHeight(), 41);
$effect_plugin = $style->getEffect($effect_id);
$style->deleteImageEffect($effect_plugin);

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageEffectsTest.
*/
namespace Drupal\image\Tests;
use Drupal\system\Tests\Image\ToolkitTestBase;

View file

@ -1,14 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageFieldDefaultImagesTest.
*/
namespace Drupal\image\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests setting up default images both to the field and field field.
@ -36,12 +33,12 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$filename = $this->randomMachineName() . "$i";
$desired_filepath = 'public://' . $filename;
file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR);
$file = entity_create('file', array('uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename));
$file = File::create(['uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename]);
$file->save();
}
$default_images = array();
foreach (array('field', 'field', 'field2', 'field_new', 'field_new') as $image_target) {
$file = entity_create('file', (array) array_pop($files));
$file = File::create((array) array_pop($files));
$file->save();
$default_images[$image_target] = $file;
}
@ -82,7 +79,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$this->assertEqual($field_storage->getSettings()['default_image']['uuid'], $default_images['field']->uuid());
// Add another field with another default image to the page content type.
$field2 = entity_create('field_config', array(
$field2 = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => $field->label(),
@ -96,7 +93,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
'height' => 0,
),
),
));
]);
$field2->save();
$widget_settings = entity_get_form_display('node', $field->getTargetBundle(), 'default')->getComponent($field_name);
@ -319,7 +316,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
* Tests image field and field having an invalid default image.
*/
public function testInvalidDefaultImage() {
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => Unicode::strtolower($this->randomMachineName()),
'entity_type' => 'node',
'type' => 'image',
@ -334,7 +331,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
// The non-existent default image should not be saved.
$this->assertNull($settings['default_image']['uuid']);
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => $this->randomMachineName(),
@ -343,7 +340,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
'uuid' => 100000,
)
),
));
]);
$field->save();
$settings = $field->getSettings();
// The non-existent default image should not be saved.

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageFieldDisplayTest.
*/
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

View file

@ -1,13 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageFieldTestBase.
*/
namespace Drupal\image\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* TODO: Test the following functions.
@ -69,9 +66,11 @@ abstract class ImageFieldTestBase extends WebTestBase {
* Widget settings to be added to the widget defaults.
* @param array $formatter_settings
* Formatter settings to be added to the formatter defaults.
* @param string $description
* A description for the field.
*/
function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array()) {
entity_create('field_storage_config', array(
function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
FieldStorageConfig::create(array(
'field_name' => $name,
'entity_type' => 'node',
'type' => 'image',
@ -79,14 +78,15 @@ abstract class ImageFieldTestBase extends WebTestBase {
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
))->save();
$field_config = entity_create('field_config', array(
$field_config = FieldConfig::create([
'field_name' => $name,
'label' => $name,
'entity_type' => 'node',
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
));
'description' => $description,
]);
$field_config->save();
entity_get_form_display('node', $type_name, 'default')
@ -135,7 +135,7 @@ abstract class ImageFieldTestBase extends WebTestBase {
* @param $type
* The type of node to create.
* @param $alt
* The alt text for the image. Use if the field settings require alt text.
* The alt text for the image. Use if the field settings require alt text.
*/
function uploadNodeImage($image, $field_name, $type, $alt = '') {
$edit = array(

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageFieldValidateTest.
*/
namespace Drupal\image\Tests;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageFieldWidgetTest.
*/
namespace Drupal\image\Tests;
/**
@ -27,9 +22,10 @@ class ImageFieldWidgetTest extends ImageFieldTestBase {
'min_resolution' => $min_resolution . 'x' . $min_resolution,
'alt_field' => 0,
);
$this->createImageField($field_name, 'article', array(), $field_settings);
$this->createImageField($field_name, 'article', array(), $field_settings, array(), array(), 'Image test on [site:name]');
$this->drupalGet('node/add/article');
$this->assertNotEqual(0, count($this->xpath('//div[contains(@class, "field--widget-image-image")]')), 'Image field widget found on add/node page', 'Browser');
$this->assertNoText('Image test on [site:name]');
}
}

View file

@ -1,51 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageImportTest.
*/
namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\KernelTestBase;
/**
* Tests config import for Image styles.
*
* @group image
*/
class ImageImportTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'image', 'image_module_test'];
/**
* Tests importing image styles.
*/
public function testImport() {
$style = ImageStyle::create([
'name' => 'test'
]);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->save();
$this->assertEqual(count($style->getEffects()), 2);
$uuid = \Drupal::service('uuid')->generate();
$style->set('effects', [
$uuid => [
'id' => 'image_module_test_null',
],
]);
$style->save();
$style = ImageStyle::load('test');
$this->assertEqual(count($style->getEffects()), 1);
}
}

View file

@ -1,129 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageItemTest.
*/
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\FieldUnitTestBase;
/**
* Tests using entity fields of the image field type.
*
* @group image
*/
class ImageItemTest extends FieldUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('file', 'image');
/**
* Created file entity.
*
* @var \Drupal\file\Entity\File
*/
protected $image;
/**
* @var \Drupal\Core\Image\ImageFactory
*/
protected $imageFactory;
protected function setUp() {
parent::setUp();
$this->installEntitySchema('file');
$this->installSchema('file', array('file_usage'));
entity_create('field_storage_config', array(
'entity_type' => 'entity_test',
'field_name' => 'image_test',
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => 'image_test',
'bundle' => 'entity_test',
))->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array(
'uri' => 'public://example.jpg',
));
$this->image->save();
$this->imageFactory = $this->container->get('image.factory');
}
/**
* Tests using entity fields of the image field type.
*/
public function testImageItem() {
// Create a test entity with the image field set.
$entity = entity_create('entity_test');
$entity->image_test->target_id = $this->image->id();
$entity->image_test->alt = $alt = $this->randomMachineName();
$entity->image_test->title = $title = $this->randomMachineName();
$entity->name->value = $this->randomMachineName();
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->image_test->target_id, $this->image->id());
$this->assertEqual($entity->image_test->alt, $alt);
$this->assertEqual($entity->image_test->title, $title);
$image = $this->imageFactory->get('public://example.jpg');
$this->assertEqual($entity->image_test->width, $image->getWidth());
$this->assertEqual($entity->image_test->height, $image->getHeight());
$this->assertEqual($entity->image_test->entity->id(), $this->image->id());
$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/druplicon.png', 'public://example-2.jpg');
$image2 = entity_create('file', array(
'uri' => 'public://example-2.jpg',
));
$image2->save();
$entity->image_test->target_id = $image2->id();
$entity->image_test->alt = $new_alt = $this->randomMachineName();
// The width and height is only updated when width is not set.
$entity->image_test->width = NULL;
$entity->save();
$this->assertEqual($entity->image_test->entity->id(), $image2->id());
$this->assertEqual($entity->image_test->entity->getFileUri(), $image2->getFileUri());
$image = $this->imageFactory->get('public://example-2.jpg');
$this->assertEqual($entity->image_test->width, $image->getWidth());
$this->assertEqual($entity->image_test->height, $image->getHeight());
$this->assertEqual($entity->image_test->alt, $new_alt);
// Check that the image item can be set to the referenced file directly.
$entity->image_test = $this->image;
$this->assertEqual($entity->image_test->target_id, $this->image->id());
// Delete the image and try to save the entity again.
$this->image->delete();
$entity = entity_create('entity_test', array('mame' => $this->randomMachineName()));
$entity->save();
// Test image item properties.
$expected = array('target_id', 'entity', 'alt', 'title', 'width', 'height');
$properties = $entity->getFieldDefinition('image_test')->getFieldStorageDefinition()->getPropertyDefinitions();
$this->assertEqual(array_keys($properties), $expected);
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity->image_test->generateSampleItems();
$this->entityValidateAndSave($entity);
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageOnTranslatedEntityTest.
*/
namespace Drupal\image\Tests;
use Drupal\file\Entity\File;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageStyleDeleteTest.
*/
namespace Drupal\image\Tests;
use Drupal\Core\Entity\Entity\EntityFormDisplay;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageStyleFlushTest.
*/
namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;

View file

@ -1,12 +1,8 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageStylesPathAndUrlTest.
*/
namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\WebTestBase;
/**
@ -31,7 +27,7 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->style = entity_create('image_style', array('name' => 'style_foo', 'label' => $this->randomString()));
$this->style = ImageStyle::create(array('name' => 'style_foo', 'label' => $this->randomString()));
$this->style->save();
}
@ -237,7 +233,7 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
// image derivative using the first one as a source.
$nested_url = $this->style->buildUrl($generated_uri, $clean_url);
$matches_expected_url_format = (boolean) preg_match('/styles\/' . $this->style->id() . '\/' . $scheme . '\/styles\/' . $this->style->id() . '\/' . $scheme . '/', $nested_url);
$this->assertTrue($matches_expected_url_format, "Url for a derivative of an image style matches expected format.");
$this->assertTrue($matches_expected_url_format, "URL for a derivative of an image style matches expected format.");
$nested_url_with_wrong_token = str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $nested_url);
$this->drupalGet($nested_url_with_wrong_token);
$this->assertResponse(403, 'Image generated from an earlier derivative was inaccessible at the URL with a missing token.');

View file

@ -1,15 +1,15 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageThemeFunctionTest.
*/
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests image theme functions.
@ -40,21 +40,21 @@ class ImageThemeFunctionTest extends WebTestBase {
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'image_test',
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'image_test',
'bundle' => 'entity_test',
))->save();
])->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array(
$this->image = File::create([
'uri' => 'public://example.jpg',
));
]);
$this->image->save();
$this->imageFactory = $this->container->get('image.factory');
}
@ -72,12 +72,12 @@ class ImageThemeFunctionTest extends WebTestBase {
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
$style = entity_create('image_style', array('name' => 'test', 'label' => 'Test'));
$style = ImageStyle::create(array('name' => 'test', 'label' => 'Test'));
$style->save();
$url = file_url_transform_relative($style->buildUrl($original_uri));
// Create a test entity with the image field set.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->image_test->target_id = $this->image->id();
$entity->image_test->alt = NULL;
$entity->image_test->uri = $original_uri;
@ -134,7 +134,7 @@ class ImageThemeFunctionTest extends WebTestBase {
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
$style = entity_create('image_style', array('name' => 'image_test', 'label' => 'Test'));
$style = ImageStyle::create(array('name' => 'image_test', 'label' => 'Test'));
$style->save();
$url = file_url_transform_relative($style->buildUrl($original_uri));

View file

@ -1,181 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\Migrate\d6\MigrateImageCacheTest.
*/
namespace Drupal\image\Tests\Migrate\d6;
use Drupal\Core\Database\Database;
use Drupal\image\Entity\ImageStyle;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Tests migration of ImageCache presets to image styles.
*
* @group image
*/
class MigrateImageCacheTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['image']);
}
/**
* Tests that an exception is thrown when ImageCache is not installed.
*/
public function testMissingTable() {
$this->sourceDatabase->update('system')
->fields(array(
'status' => 0,
))
->condition('name', 'imagecache')
->condition('type', 'module')
->execute();
try {
Migration::load('d6_imagecache_presets')
->getSourcePlugin()
->checkRequirements();
$this->fail('Did not catch expected RequirementsException.');
}
catch (RequirementsException $e) {
$this->pass('Caught expected RequirementsException: ' . $e->getMessage());
}
}
/**
* 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');
}
}

View file

@ -1,40 +0,0 @@
<?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'));
}
}

View file

@ -1,78 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\Migrate\d7\MigrateImageStylesTest.
*/
namespace Drupal\image\Tests\Migrate\d7;
use Drupal\image\Entity\ImageStyle;
use Drupal\image\ImageStyleInterface;
use Drupal\image\ImageEffectBase;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test image styles migration to config entities.
*
* @group image
*/
class MigrateImageStylesTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('image');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigration('d7_image_styles');
}
/**
* Test the image styles migration.
*/
public function testImageStylesMigration() {
$this->assertEntity('custom_image_style_1', "Custom image style 1", ['image_scale_and_crop', 'image_desaturate'], [['width' => 55, 'height' => 55], []]);
$this->assertEntity('custom_image_style_2', "Custom image style 2", ['image_resize', 'image_rotate'], [['width' => 55, 'height' => 100], ['degrees' => 45, 'bgcolor' => '#FFFFFF', 'random' => false]]);
$this->assertEntity('custom_image_style_3', "Custom image style 3", ['image_scale', 'image_crop'], [['width' => 150, 'height' => NULL, 'upscale' => false], ['width' => 50, 'height' => 50, 'anchor' => 'left-top']]);
}
/**
* Asserts various aspects of an ImageStyle entity.
*
* @param string $id
* The expected image style ID.
* @param string $label
* The expected image style label.
* @param array $expected_effect_plugins
* An array of expected plugins attached to the image style entity
* @param array $expected_effect_config
* An array of expected configuration for each effect in the image style
*/
protected function assertEntity($id, $label, array $expected_effect_plugins, array $expected_effect_config) {
$style = ImageStyle::load($id);
$this->assertTrue($style instanceof ImageStyleInterface);
/** @var \Drupal\image\ImageStyleInterface $style */
$this->assertIdentical($id, $style->id());
$this->assertIdentical($label, $style->label());
// Check the number of effects associated with the style.
$effects = $style->getEffects();
$this->assertIdentical(count($effects), count($expected_effect_plugins));
$index = 0;
foreach ($effects as $effect) {
$this->assertTrue($effect instanceof ImageEffectBase);
$this->assertIdentical($expected_effect_plugins[$index], $effect->getPluginId());
$config = $effect->getConfiguration();
$this->assertIdentical($expected_effect_config[$index], $config['data']);
$index++;
}
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\Update\ImageUpdateTest.
*/
namespace Drupal\image\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;

View file

@ -1,97 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\Views\ImageViewsDataTest.
*/
namespace Drupal\image\Tests\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Views;
/**
* Tests image views data.
*
* @group image
*/
class ImageViewsDataTest extends ViewKernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('image', 'file', 'views', 'entity_test', 'user', 'field');
/**
* Tests views data generated for image field relationship.
*
* @see image_field_views_data()
* @see image_field_views_data_views_data_alter()
*/
public function testRelationshipViewsData() {
// Create image field to entity_test.
FieldStorageConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_base_image',
'type' => 'image',
))->save();
FieldConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_base_image',
'bundle' => 'entity_test',
))->save();
// Check the generated views data.
$views_data = Views::viewsData()->get('entity_test__field_base_image');
$relationship = $views_data['field_base_image_target_id']['relationship'];
$this->assertEqual($relationship['id'], 'standard');
$this->assertEqual($relationship['base'], 'file_managed');
$this->assertEqual($relationship['base field'], 'fid');
$this->assertEqual($relationship['entity type'], 'file');
// Check the backwards reference.
$views_data = Views::viewsData()->get('file_managed');
$relationship = $views_data['reverse_field_base_image_entity_test']['relationship'];
$this->assertEqual($relationship['id'], 'entity_reverse');
$this->assertEqual($relationship['base'], 'entity_test');
$this->assertEqual($relationship['base field'], 'id');
$this->assertEqual($relationship['field table'], 'entity_test__field_base_image');
$this->assertEqual($relationship['field field'], 'field_base_image_target_id');
$this->assertEqual($relationship['field_name'], 'field_base_image');
$this->assertEqual($relationship['entity_type'], 'entity_test');
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
// Create image field to entity_test_mul.
FieldStorageConfig::create(array(
'entity_type' => 'entity_test_mul',
'field_name' => 'field_data_image',
'type' => 'image',
))->save();
FieldConfig::create(array(
'entity_type' => 'entity_test_mul',
'field_name' => 'field_data_image',
'bundle' => 'entity_test_mul',
))->save();
// Check the generated views data.
$views_data = Views::viewsData()->get('entity_test_mul__field_data_image');
$relationship = $views_data['field_data_image_target_id']['relationship'];
$this->assertEqual($relationship['id'], 'standard');
$this->assertEqual($relationship['base'], 'file_managed');
$this->assertEqual($relationship['base field'], 'fid');
$this->assertEqual($relationship['entity type'], 'file');
// Check the backwards reference.
$views_data = Views::viewsData()->get('file_managed');
$relationship = $views_data['reverse_field_data_image_entity_test_mul']['relationship'];
$this->assertEqual($relationship['id'], 'entity_reverse');
$this->assertEqual($relationship['base'], 'entity_test_mul_property_data');
$this->assertEqual($relationship['base field'], 'id');
$this->assertEqual($relationship['field table'], 'entity_test_mul__field_data_image');
$this->assertEqual($relationship['field field'], 'field_data_image_target_id');
$this->assertEqual($relationship['field_name'], 'field_data_image');
$this->assertEqual($relationship['entity_type'], 'entity_test_mul');
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
}
}

View file

@ -1,15 +1,13 @@
<?php
/**
* @file
* Contains \Drupal\image\Tests\Views\RelationshipUserImageDataTest.
*/
namespace Drupal\image\Tests\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests image on user relationship handler.
@ -36,20 +34,20 @@ class RelationshipUserImageDataTest extends ViewTestBase {
parent::setUp();
// Create the user profile field and instance.
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'entity_type' => 'user',
'field_name' => 'user_picture',
'type' => 'image',
'translatable' => '0',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'label' => 'User Picture',
'description' => '',
'field_name' => 'user_picture',
'entity_type' => 'user',
'bundle' => 'user',
'required' => 0,
))->save();
])->save();
ViewTestData::createTestViews(get_class($this), array('image_test_views'));
}
@ -58,7 +56,7 @@ class RelationshipUserImageDataTest extends ViewTestBase {
* Tests using the views image relationship.
*/
public function testViewsHandlerRelationshipUserImageData() {
$file = entity_create('file', array(
$file = File::create([
'fid' => 2,
'uid' => 2,
'filename' => 'image-test.jpg',
@ -67,7 +65,7 @@ class RelationshipUserImageDataTest extends ViewTestBase {
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
));
]);
$file->enforceIsNew();
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
$file->save();