updated core

This commit is contained in:
Bachir Soussi Chiadmi
2018-01-24 13:36:32 +01:00
parent cd7dea45a9
commit f9374cf96d
1997 changed files with 5175 additions and 127715 deletions
@@ -50,8 +50,7 @@ interface ImageEffectInterface extends PluginInspectionInterface, ConfigurablePl
public function transformDimensions(array &$dimensions, $uri);
/**
* Returns the extension the derivative would have have after applying this
* image effect.
* Returns the extension of the derivative after applying this image effect.
*
* @param string $extension
* The file extension the derivative has before applying.
@@ -173,7 +173,6 @@ class ImageDimensionsTest extends WebTestBase {
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
// Add a crop effect.
$effect = [
'id' => 'image_crop',
@@ -208,14 +207,18 @@ class ImageDimensionsTest extends WebTestBase {
$effect_id = $style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="41" height="41" alt="" class="image-style-test" />');
// @todo Uncomment this once
// https://www.drupal.org/project/drupal/issues/2670966 is resolved.
// $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);
// @todo Uncomment this once
// https://www.drupal.org/project/drupal/issues/2670966 is resolved.
// $this->assertEqual($image_file->getWidth(), 41);
// $this->assertEqual($image_file->getHeight(), 41);
$effect_plugin = $style->getEffect($effect_id);
$style->deleteImageEffect($effect_plugin);
@@ -1,181 +0,0 @@
<?php
namespace Drupal\image\Tests;
use Drupal\system\Tests\Image\ToolkitTestBase;
/**
* Tests that the image effects pass parameters to the toolkit correctly.
*
* @group image
*/
class ImageEffectsTest extends ToolkitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('image', 'image_test', 'image_module_test');
/**
* The image effect manager.
*
* @var \Drupal\image\ImageEffectManager
*/
protected $manager;
protected function setUp() {
parent::setUp();
$this->manager = $this->container->get('plugin.manager.image.effect');
}
/**
* Test the image_resize_effect() function.
*/
function testResizeEffect() {
$this->assertImageEffect('image_resize', array(
'width' => 1,
'height' => 2,
));
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['resize'][0][0], 1, 'Width was passed correctly');
$this->assertEqual($calls['resize'][0][1], 2, 'Height was passed correctly');
}
/**
* Test the image_scale_effect() function.
*/
function testScaleEffect() {
// @todo: need to test upscaling.
$this->assertImageEffect('image_scale', array(
'width' => 10,
'height' => 10,
));
$this->assertToolkitOperationsCalled(array('scale'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['scale'][0][0], 10, 'Width was passed correctly');
$this->assertEqual($calls['scale'][0][1], 10, 'Height was based off aspect ratio and passed correctly');
}
/**
* Test the image_crop_effect() function.
*/
function testCropEffect() {
// @todo should test the keyword offsets.
$this->assertImageEffect('image_crop', array(
'anchor' => 'top-1',
'width' => 3,
'height' => 4,
));
$this->assertToolkitOperationsCalled(array('crop'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['crop'][0][0], 0, 'X was passed correctly');
$this->assertEqual($calls['crop'][0][1], 1, 'Y was passed correctly');
$this->assertEqual($calls['crop'][0][2], 3, 'Width was passed correctly');
$this->assertEqual($calls['crop'][0][3], 4, 'Height was passed correctly');
}
/**
* Tests the ConvertImageEffect plugin.
*/
function testConvertEffect() {
// Test jpeg.
$this->assertImageEffect('image_convert', array(
'extension' => 'jpeg',
));
$this->assertToolkitOperationsCalled(array('convert'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['convert'][0][0], 'jpeg', 'Extension was passed correctly');
}
/**
* Test the image_scale_and_crop_effect() function.
*/
function testScaleAndCropEffect() {
$this->assertImageEffect('image_scale_and_crop', array(
'width' => 5,
'height' => 10,
));
$this->assertToolkitOperationsCalled(array('scale_and_crop'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['scale_and_crop'][0][0], 5, 'Width was computed and passed correctly');
$this->assertEqual($calls['scale_and_crop'][0][1], 10, 'Height was computed and passed correctly');
}
/**
* Test the image_desaturate_effect() function.
*/
function testDesaturateEffect() {
$this->assertImageEffect('image_desaturate', array());
$this->assertToolkitOperationsCalled(array('desaturate'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual(count($calls['desaturate'][0]), 0, 'No parameters were passed.');
}
/**
* Test the image_rotate_effect() function.
*/
function testRotateEffect() {
// @todo: need to test with 'random' => TRUE
$this->assertImageEffect('image_rotate', array(
'degrees' => 90,
'bgcolor' => '#fff',
));
$this->assertToolkitOperationsCalled(array('rotate'));
// Check the parameters.
$calls = $this->imageTestGetAllCalls();
$this->assertEqual($calls['rotate'][0][0], 90, 'Degrees were passed correctly');
$this->assertEqual($calls['rotate'][0][1], '#fff', 'Background color was passed correctly');
}
/**
* Test image effect caching.
*/
function testImageEffectsCaching() {
$image_effect_definitions_called = &drupal_static('image_module_test_image_effect_info_alter');
// First call should grab a fresh copy of the data.
$manager = $this->container->get('plugin.manager.image.effect');
$effects = $manager->getDefinitions();
$this->assertTrue($image_effect_definitions_called === 1, 'image_effect_definitions() generated data.');
// Second call should come from cache.
drupal_static_reset('image_module_test_image_effect_info_alter');
$cached_effects = $manager->getDefinitions();
$this->assertTrue($image_effect_definitions_called === 0, 'image_effect_definitions() returned data from cache.');
$this->assertTrue($effects == $cached_effects, 'Cached effects are the same as generated effects.');
}
/**
* Asserts the effect processing of an image effect plugin.
*
* @param string $effect_name
* The name of the image effect to test.
* @param array $data
* The data to pass to the image effect.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertImageEffect($effect_name, array $data) {
$effect = $this->manager->createInstance($effect_name, array('data' => $data));
return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.');
}
}
@@ -156,4 +156,26 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
];
}
/**
* Test the validation message is displayed only once for ajax uploads.
*/
public function testAJAXValidationMessage() {
$field_name = strtolower($this->randomMachineName());
$this->createImageField($field_name, 'article', ['cardinality' => -1]);
$this->drupalGet('node/add/article');
/** @var \Drupal\file\FileInterface[] $text_files */
$text_files = $this->drupalGetTestFiles('text');
$text_file = reset($text_files);
$edit = [
'files[' . $field_name . '_0][]' => $this->container->get('file_system')->realpath($text_file->uri),
'title[0][value]' => $this->randomMachineName(),
];
$this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button');
$elements = $this->xpath('//div[contains(@class, :class)]', [
':class' => 'messages--error',
]);
$this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.');
}
}
@@ -1,31 +0,0 @@
<?php
namespace Drupal\image\Tests;
/**
* Tests the image field widget.
*
* @group image
*/
class ImageFieldWidgetTest extends ImageFieldTestBase {
/**
* Tests file widget element.
*/
public function testWidgetElement() {
// Check for image widget in add/node/article page
$field_name = strtolower($this->randomMachineName());
$min_resolution = 50;
$max_resolution = 100;
$field_settings = array(
'max_resolution' => $max_resolution . 'x' . $max_resolution,
'min_resolution' => $min_resolution . 'x' . $min_resolution,
'alt_field' => 0,
);
$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]');
}
}
@@ -1,81 +0,0 @@
<?php
namespace Drupal\image\Tests;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
* Tests image style deletion using the UI.
*
* @group image
*/
class ImageStyleDeleteTest extends ImageFieldTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create an image field 'foo' having the image style 'medium' as widget
// preview and as formatter.
$this->createImageField('foo', 'page', [], [], ['preview_image_style' => 'medium'], ['image_style' => 'medium']);
}
/**
* Tests image style deletion.
*/
public function testDelete() {
$this->drupalGet('admin/config/media/image-styles/manage/medium/delete');
// Checks that the 'replacement' select element is displayed.
$this->assertFieldByName('replacement');
// Checks that UI messages are correct.
$this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
$this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
// Delete 'medium' image style but replace it with 'thumbnail'. This style
// is involved in 'node.page.default' display view and form.
$this->drupalPostForm(NULL, ['replacement' => 'thumbnail'], t('Delete'));
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
$view_display = EntityViewDisplay::load('node.page.default');
// Checks that the formatter setting is replaced.
if ($this->assertNotNull($component = $view_display->getComponent('foo'))) {
$this->assertIdentical($component['settings']['image_style'], 'thumbnail');
}
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = EntityFormDisplay::load('node.page.default');
// Check that the widget setting is replaced.
if ($this->assertNotNull($component = $form_display->getComponent('foo'))) {
$this->assertIdentical($component['settings']['preview_image_style'], 'thumbnail');
}
$this->drupalGet('admin/config/media/image-styles/manage/thumbnail/delete');
// Checks that the 'replacement' select element is displayed.
$this->assertFieldByName('replacement');
// Checks that UI messages are correct.
$this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
$this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
// Delete 'thumbnail' image style. Provide no replacement.
$this->drupalPostForm(NULL, [], t('Delete'));
$view_display = EntityViewDisplay::load('node.page.default');
// Checks that the formatter setting is disabled.
$this->assertNull($view_display->getComponent('foo'));
$this->assertNotNull($view_display->get('hidden')['foo']);
// Checks that widget setting is preserved with the image preview disabled.
$form_display = EntityFormDisplay::load('node.page.default');
$this->assertNotNull($widget = $form_display->getComponent('foo'));
$this->assertIdentical($widget['settings']['preview_image_style'], '');
// Now, there's only one image style configured on the system: 'large'.
$this->drupalGet('admin/config/media/image-styles/manage/large/delete');
// Checks that the 'replacement' select element is not displayed.
$this->assertNoFieldByName('replacement');
// Checks that UI messages are correct.
$this->assertNoRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
$this->assertRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
}
}
@@ -1,54 +0,0 @@
<?php
namespace Drupal\image\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Tests Image update path.
*
* @group image
*/
class ImageUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
];
}
/**
* Tests image_post_update_image_style_dependencies().
*
* @see image_post_update_image_style_dependencies()
*/
public function testPostUpdateImageStylesDependencies() {
$view = 'core.entity_view_display.node.article.default';
$form = 'core.entity_form_display.node.article.default';
// Check that view display 'node.article.default' doesn't depend on image
// style 'image.style.large'.
$dependencies = $this->config($view)->get('dependencies.config');
$this->assertFalse(in_array('image.style.large', $dependencies));
// Check that form display 'node.article.default' doesn't depend on image
// style 'image.style.thumbnail'.
$dependencies = $this->config($form)->get('dependencies.config');
$this->assertFalse(in_array('image.style.thumbnail', $dependencies));
// Run updates.
$this->runUpdates();
// Check that view display 'node.article.default' depend on image style
// 'image.style.large'.
$dependencies = $this->config($view)->get('dependencies.config');
$this->assertTrue(in_array('image.style.large', $dependencies));
// Check that form display 'node.article.default' depend on image style
// 'image.style.thumbnail'.
$dependencies = $this->config($view)->get('dependencies.config');
$this->assertTrue(in_array('image.style.large', $dependencies));
}
}