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
|
@ -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.
|
||||
|
|
Reference in a new issue