Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -10,7 +10,7 @@ use Drupal\image\ImageStyleInterface;
|
|||
function image_module_test_file_download($uri) {
|
||||
$default_uri = \Drupal::state()->get('image.test_file_download') ?: FALSE;
|
||||
if ($default_uri == $uri) {
|
||||
return array('X-Image-Owned-By' => 'image_module_test');
|
||||
return ['X-Image-Owned-By' => 'image_module_test'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
202
web/core/modules/image/tests/src/Functional/ImageEffectsTest.php
Normal file
202
web/core/modules/image/tests/src/Functional/ImageEffectsTest.php
Normal file
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Functional;
|
||||
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
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 = ['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.
|
||||
*/
|
||||
public function testResizeEffect() {
|
||||
$this->assertImageEffect('image_resize', [
|
||||
'width' => 1,
|
||||
'height' => 2,
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public function testScaleEffect() {
|
||||
// @todo: need to test upscaling.
|
||||
$this->assertImageEffect('image_scale', [
|
||||
'width' => 10,
|
||||
'height' => 10,
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public function testCropEffect() {
|
||||
// @todo should test the keyword offsets.
|
||||
$this->assertImageEffect('image_crop', [
|
||||
'anchor' => 'top-1',
|
||||
'width' => 3,
|
||||
'height' => 4,
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public function testConvertEffect() {
|
||||
// Test jpeg.
|
||||
$this->assertImageEffect('image_convert', [
|
||||
'extension' => 'jpeg',
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public function testScaleAndCropEffect() {
|
||||
$this->assertImageEffect('image_scale_and_crop', [
|
||||
'width' => 5,
|
||||
'height' => 10,
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public function testDesaturateEffect() {
|
||||
$this->assertImageEffect('image_desaturate', []);
|
||||
$this->assertToolkitOperationsCalled(['desaturate']);
|
||||
|
||||
// Check the parameters.
|
||||
$calls = $this->imageTestGetAllCalls();
|
||||
$this->assertEqual(count($calls['desaturate'][0]), 0, 'No parameters were passed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the image_rotate_effect() function.
|
||||
*/
|
||||
public function testRotateEffect() {
|
||||
// @todo: need to test with 'random' => TRUE
|
||||
$this->assertImageEffect('image_rotate', [
|
||||
'degrees' => 90,
|
||||
'bgcolor' => '#fff',
|
||||
]);
|
||||
$this->assertToolkitOperationsCalled(['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.
|
||||
*/
|
||||
public 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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if validation errors are passed plugin form to the parent form.
|
||||
*/
|
||||
public function testEffectFormValidationErrors() {
|
||||
$account = $this->drupalCreateUser(['administer image styles']);
|
||||
$this->drupalLogin($account);
|
||||
/** @var \Drupal\image\ImageStyleInterface $style */
|
||||
$style = ImageStyle::load('thumbnail');
|
||||
// Image Scale is the only effect shipped with 'thumbnail', by default.
|
||||
$uuids = $style->getEffects()->getInstanceIds();
|
||||
$uuid = key($uuids);
|
||||
|
||||
// We are posting the form with both, width and height, empty.
|
||||
$edit = ['data[width]' => '', 'data[height]' => ''];
|
||||
$path = 'admin/config/media/image-styles/manage/thumbnail/effects/' . $uuid;
|
||||
$this->drupalPostForm($path, $edit, t('Update effect'));
|
||||
// Check that the error message has been displayed.
|
||||
$this->assertText(t('Width and height can not both be blank.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, ['data' => $data]);
|
||||
return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Functional;
|
||||
|
||||
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* TODO: Test the following functions.
|
||||
*
|
||||
* image.effects.inc:
|
||||
* image_style_generate()
|
||||
* \Drupal\image\ImageStyleInterface::createDerivative()
|
||||
*
|
||||
* image.module:
|
||||
* image_style_options()
|
||||
* \Drupal\image\ImageStyleInterface::flush()
|
||||
* image_filter_keyword()
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides methods specifically for testing Image's field handling.
|
||||
*/
|
||||
abstract class ImageFieldTestBase extends BrowserTestBase {
|
||||
|
||||
use ImageFieldCreationTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'image', 'field_ui', 'image_module_test'];
|
||||
|
||||
/**
|
||||
* An user with permissions to administer content types and image styles.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(['access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer node fields', 'administer nodes', 'create article content', 'edit any article content', 'delete any article content', 'administer image styles', 'administer node display']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview an image in a node.
|
||||
*
|
||||
* @param \Drupal\Core\Image\ImageInterface $image
|
||||
* A file object representing the image to upload.
|
||||
* @param string $field_name
|
||||
* Name of the image field the image should be attached to.
|
||||
* @param string $type
|
||||
* The type of node to create.
|
||||
*/
|
||||
public function previewNodeImage($image, $field_name, $type) {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an image to a node.
|
||||
*
|
||||
* @param $image
|
||||
* A file object representing the image to upload.
|
||||
* @param $field_name
|
||||
* Name of the image field the image should be attached to.
|
||||
* @param $type
|
||||
* The type of node to create.
|
||||
* @param $alt
|
||||
* The alt text for the image. Use if the field settings require alt text.
|
||||
*/
|
||||
public function uploadNodeImage($image, $field_name, $type, $alt = '') {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish'));
|
||||
if ($alt) {
|
||||
// Add alt text.
|
||||
$this->drupalPostForm(NULL, [$field_name . '[0][alt]' => $alt], t('Save and publish'));
|
||||
}
|
||||
|
||||
// Retrieve ID of the newly created node from the current URL.
|
||||
$matches = [];
|
||||
preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches);
|
||||
return isset($matches[1]) ? $matches[1] : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the fid of the last inserted file.
|
||||
*/
|
||||
protected function getLastFileId() {
|
||||
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Functional;
|
||||
|
||||
/**
|
||||
* 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 = [
|
||||
'max_resolution' => $max_resolution . 'x' . $max_resolution,
|
||||
'min_resolution' => $min_resolution . 'x' . $min_resolution,
|
||||
'alt_field' => 0,
|
||||
];
|
||||
$this->createImageField($field_name, 'article', [], $field_settings, [], [], '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->assertNotEqual(0, count($this->xpath('//input[contains(@accept, "image/*")]')), 'Image field widget limits accepted files.', 'Browser');
|
||||
$this->assertNoText('Image test on [site:name]');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Functional;
|
||||
|
||||
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.'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\FunctionalJavascript;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests the JavaScript functionality of the "image" in-place editor.
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class QuickEditImageTest extends JavascriptTestBase {
|
||||
|
||||
use ImageFieldCreationTrait;
|
||||
use TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'image', 'field_ui', 'contextual', 'quickedit', 'toolbar'];
|
||||
|
||||
/**
|
||||
* A user with permissions to edit Articles and use Quick Edit.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $contentAuthorUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create the Article node type.
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Log in as a content author who can use Quick Edit and edit Articles.
|
||||
$this->contentAuthorUser = $this->drupalCreateUser([
|
||||
'access contextual links',
|
||||
'access toolbar',
|
||||
'access in-place editing',
|
||||
'access content',
|
||||
'create article content',
|
||||
'edit any article content',
|
||||
'delete any article content',
|
||||
]);
|
||||
$this->drupalLogin($this->contentAuthorUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if an image can be uploaded inline with Quick Edit.
|
||||
*/
|
||||
public function testUpload() {
|
||||
// Create a field with a basic filetype restriction.
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$field_settings = [
|
||||
'file_extensions' => 'png',
|
||||
];
|
||||
$formatter_settings = [
|
||||
'image_style' => 'large',
|
||||
'image_link' => '',
|
||||
];
|
||||
$this->createImageField($field_name, 'article', [], $field_settings, [], $formatter_settings);
|
||||
|
||||
// Find images that match our field settings.
|
||||
$valid_images = [];
|
||||
foreach ($this->getTestFiles('image') as $image) {
|
||||
// This regex is taken from file_validate_extensions().
|
||||
$regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($field_settings['file_extensions'])) . ')$/i';
|
||||
if (preg_match($regex, $image->filename)) {
|
||||
$valid_images[] = $image;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we have at least two valid images.
|
||||
$this->assertGreaterThanOrEqual(2, count($valid_images));
|
||||
|
||||
// Create a File entity for the initial image.
|
||||
$file = File::create([
|
||||
'uri' => $valid_images[0]->uri,
|
||||
'uid' => $this->contentAuthorUser->id(),
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
// Use the first valid image to create a new Node.
|
||||
$image_factory = $this->container->get('image.factory');
|
||||
$image = $image_factory->get($valid_images[0]->uri);
|
||||
$node = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'title' => t('Test Node'),
|
||||
$field_name => [
|
||||
'target_id' => $file->id(),
|
||||
'alt' => 'Hello world',
|
||||
'title' => '',
|
||||
'width' => $image->getWidth(),
|
||||
'height' => $image->getHeight(),
|
||||
],
|
||||
]);
|
||||
|
||||
// Visit the new Node.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
// Assemble common CSS selectors.
|
||||
$entity_selector = '[data-quickedit-entity-id="node/' . $node->id() . '"]';
|
||||
$field_selector = '[data-quickedit-field-id="node/' . $node->id() . '/' . $field_name . '/' . $node->language()->getId() . '/full"]';
|
||||
$original_image_selector = 'img[src*="' . $valid_images[0]->filename . '"][alt="Hello world"]';
|
||||
$new_image_selector = 'img[src*="' . $valid_images[1]->filename . '"][alt="New text"]';
|
||||
|
||||
// Assert that the initial image is present.
|
||||
$this->assertSession()->elementExists('css', $entity_selector . ' ' . $field_selector . ' ' . $original_image_selector);
|
||||
|
||||
// Wait until Quick Edit loads.
|
||||
$condition = "jQuery('" . $entity_selector . " .quickedit').length > 0";
|
||||
$this->assertJsCondition($condition, 10000);
|
||||
|
||||
// Initiate Quick Editing.
|
||||
$this->click('.contextual-toolbar-tab button');
|
||||
$this->click($entity_selector . ' [data-contextual-id] > button');
|
||||
$this->click($entity_selector . ' [data-contextual-id] .quickedit > a');
|
||||
$this->click($field_selector);
|
||||
|
||||
// Wait for the field info to load and set new alt text.
|
||||
$condition = "jQuery('.quickedit-image-field-info').length > 0";
|
||||
$this->assertJsCondition($condition, 10000);
|
||||
$input = $this->assertSession()->elementExists('css', '.quickedit-image-field-info input[name="alt"]');
|
||||
$input->setValue('New text');
|
||||
|
||||
// Check that our Dropzone element exists.
|
||||
$this->assertSession()->elementExists('css', $field_selector . ' .quickedit-image-dropzone');
|
||||
|
||||
// Our headless browser can't drag+drop files, but we can mock the event.
|
||||
// Append a hidden upload element to the DOM.
|
||||
$script = 'jQuery("<input id=\"quickedit-image-test-input\" type=\"file\" />").appendTo("body")';
|
||||
$this->getSession()->executeScript($script);
|
||||
|
||||
// Find the element, and set its value to our new image.
|
||||
$input = $this->assertSession()->elementExists('css', '#quickedit-image-test-input');
|
||||
$filepath = $this->container->get('file_system')->realpath($valid_images[1]->uri);
|
||||
$input->attachFile($filepath);
|
||||
|
||||
// Trigger the upload logic with a mock "drop" event.
|
||||
$script = 'var e = jQuery.Event("drop");'
|
||||
. 'e.originalEvent = {dataTransfer: {files: jQuery("#quickedit-image-test-input").get(0).files}};'
|
||||
. 'e.preventDefault = e.stopPropagation = function () {};'
|
||||
. 'jQuery(".quickedit-image-dropzone").trigger(e);';
|
||||
$this->getSession()->executeScript($script);
|
||||
|
||||
// Wait for the dropzone element to be removed (i.e. loading is done).
|
||||
$condition = "jQuery('" . $field_selector . " .quickedit-image-dropzone').length == 0";
|
||||
$this->assertJsCondition($condition, 20000);
|
||||
|
||||
// To prevent 403s on save, we re-set our request (cookie) state.
|
||||
$this->prepareRequest();
|
||||
|
||||
// Save the change.
|
||||
$this->click('.quickedit-button.action-save');
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
|
||||
// Re-visit the page to make sure the edit worked.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
// Check that the new image appears as expected.
|
||||
$this->assertSession()->elementNotExists('css', $entity_selector . ' ' . $field_selector . ' ' . $original_image_selector);
|
||||
$this->assertSession()->elementExists('css', $entity_selector . ' ' . $field_selector . ' ' . $new_image_selector);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,14 +30,14 @@ trait ImageFieldCreationTrait {
|
|||
* @param string $description
|
||||
* (optional) A description for the field. Defaults to ''.
|
||||
*/
|
||||
protected function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
|
||||
FieldStorageConfig::create(array(
|
||||
protected function createImageField($name, $type_name, $storage_settings = [], $field_settings = [], $widget_settings = [], $formatter_settings = [], $description = '') {
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'image',
|
||||
'settings' => $storage_settings,
|
||||
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
$field_config = FieldConfig::create([
|
||||
'field_name' => $name,
|
||||
|
@ -51,17 +51,17 @@ trait ImageFieldCreationTrait {
|
|||
$field_config->save();
|
||||
|
||||
entity_get_form_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
->setComponent($name, [
|
||||
'type' => 'image_image',
|
||||
'settings' => $widget_settings,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
->setComponent($name, [
|
||||
'type' => 'image',
|
||||
'settings' => $formatter_settings,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
return $field_config;
|
||||
|
|
|
@ -21,7 +21,7 @@ class ImageFormatterTest extends FieldKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file', 'image');
|
||||
public static $modules = ['file', 'image'];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
@ -52,18 +52,18 @@ class ImageFormatterTest extends FieldKernelTestBase {
|
|||
$this->installConfig(['field']);
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
|
||||
$this->entityType = 'entity_test';
|
||||
$this->bundle = $this->entityType;
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName());
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => $this->entityType,
|
||||
'field_name' => $this->fieldName,
|
||||
'type' => 'image',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityType,
|
||||
'field_name' => $this->fieldName,
|
||||
|
@ -84,7 +84,7 @@ class ImageFormatterTest extends FieldKernelTestBase {
|
|||
/**
|
||||
* Tests the cache tags from image formatters.
|
||||
*/
|
||||
function testImageFormatterCacheTags() {
|
||||
public function testImageFormatterCacheTags() {
|
||||
// Create a test entity with the image field set.
|
||||
$entity = EntityTest::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
|
|
|
@ -23,7 +23,7 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file', 'image');
|
||||
public static $modules = ['file', 'image'];
|
||||
|
||||
/**
|
||||
* Created file entity.
|
||||
|
@ -41,14 +41,14 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'image_test',
|
||||
'type' => 'image',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'image_test',
|
||||
|
@ -114,11 +114,11 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
|
||||
// Delete the image and try to save the entity again.
|
||||
$this->image->delete();
|
||||
$entity = EntityTest::create(array('mame' => $this->randomMachineName()));
|
||||
$entity = EntityTest::create(['mame' => $this->randomMachineName()]);
|
||||
$entity->save();
|
||||
|
||||
// Test image item properties.
|
||||
$expected = array('target_id', 'entity', 'alt', 'title', 'width', 'height');
|
||||
$expected = ['target_id', 'entity', 'alt', 'title', 'width', 'height'];
|
||||
$properties = $entity->getFieldDefinition('image_test')->getFieldStorageDefinition()->getPropertyDefinitions();
|
||||
$this->assertEqual(array_keys($properties), $expected);
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testMissingTable() {
|
||||
$this->sourceDatabase->update('system')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'status' => 0,
|
||||
))
|
||||
])
|
||||
->condition('name', 'imagecache')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
|
@ -88,14 +88,14 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testMissingEffectPlugin() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
|
@ -121,14 +121,14 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testInvalidCropValues() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
|
|
|
@ -17,7 +17,7 @@ class MigrateImageStylesTest extends MigrateDrupal7TestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('image');
|
||||
public static $modules = ['image'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -38,7 +38,7 @@ class ImageStylesTest extends MigrateSqlSourceTestBase {
|
|||
'isid' => 1,
|
||||
'weight' => 1,
|
||||
'name' => 'image_desaturate',
|
||||
'data' => serialize(array()),
|
||||
'data' => serialize([]),
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class ImageViewsDataTest extends ViewsKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('image', 'file', 'views', 'entity_test', 'user', 'field');
|
||||
public static $modules = ['image', 'file', 'views', 'entity_test', 'user', 'field'];
|
||||
|
||||
/**
|
||||
* Tests views data generated for image field relationship.
|
||||
|
@ -29,16 +29,16 @@ class ImageViewsDataTest extends ViewsKernelTestBase {
|
|||
*/
|
||||
public function testRelationshipViewsData() {
|
||||
// Create image field to entity_test.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_base_image',
|
||||
'type' => 'image',
|
||||
))->save();
|
||||
FieldConfig::create(array(
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_base_image',
|
||||
'bundle' => 'entity_test',
|
||||
))->save();
|
||||
])->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'];
|
||||
|
@ -59,16 +59,16 @@ class ImageViewsDataTest extends ViewsKernelTestBase {
|
|||
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
|
||||
|
||||
// Create image field to entity_test_mul.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test_mul',
|
||||
'field_name' => 'field_data_image',
|
||||
'type' => 'image',
|
||||
))->save();
|
||||
FieldConfig::create(array(
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test_mul',
|
||||
'field_name' => 'field_data_image',
|
||||
'bundle' => 'entity_test_mul',
|
||||
))->save();
|
||||
])->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'];
|
||||
|
|
|
@ -44,7 +44,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
* @return \Drupal\image\ImageStyleInterface
|
||||
* The mocked image style.
|
||||
*/
|
||||
protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = array()) {
|
||||
protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = []) {
|
||||
$effectManager = $this->getMockBuilder('\Drupal\image\ImageEffectManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -52,17 +52,17 @@ class ImageStyleTest extends UnitTestCase {
|
|||
->method('createInstance')
|
||||
->with($image_effect_id)
|
||||
->will($this->returnValue($image_effect));
|
||||
$default_stubs = array(
|
||||
$default_stubs = [
|
||||
'getImageEffectPluginManager',
|
||||
'fileUriScheme',
|
||||
'fileUriTarget',
|
||||
'fileDefaultScheme',
|
||||
);
|
||||
];
|
||||
$image_style = $this->getMockBuilder('\Drupal\image\Entity\ImageStyle')
|
||||
->setConstructorArgs(array(
|
||||
array('effects' => array($image_effect_id => array('id' => $image_effect_id))),
|
||||
->setConstructorArgs([
|
||||
['effects' => [$image_effect_id => ['id' => $image_effect_id]]],
|
||||
$this->entityTypeId,
|
||||
))
|
||||
])
|
||||
->setMethods(array_merge($default_stubs, $stubs))
|
||||
->getMock();
|
||||
|
||||
|
@ -71,13 +71,13 @@ class ImageStyleTest extends UnitTestCase {
|
|||
->will($this->returnValue($effectManager));
|
||||
$image_style->expects($this->any())
|
||||
->method('fileUriScheme')
|
||||
->will($this->returnCallback(array($this, 'fileUriScheme')));
|
||||
->will($this->returnCallback([$this, 'fileUriScheme']));
|
||||
$image_style->expects($this->any())
|
||||
->method('fileUriTarget')
|
||||
->will($this->returnCallback(array($this, 'fileUriTarget')));
|
||||
->will($this->returnCallback([$this, 'fileUriTarget']));
|
||||
$image_style->expects($this->any())
|
||||
->method('fileDefaultScheme')
|
||||
->will($this->returnCallback(array($this, 'fileDefaultScheme')));
|
||||
->will($this->returnCallback([$this, 'fileDefaultScheme']));
|
||||
|
||||
return $image_style;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
$image_effect_id = $this->randomMachineName();
|
||||
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
|
||||
$image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase')
|
||||
->setConstructorArgs(array(array(), $image_effect_id, array(), $logger))
|
||||
->setConstructorArgs([[], $image_effect_id, [], $logger])
|
||||
->getMock();
|
||||
$image_effect->expects($this->any())
|
||||
->method('getDerivativeExtension')
|
||||
|
@ -114,7 +114,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
|
||||
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect);
|
||||
|
||||
$extensions = array('jpeg', 'gif', 'png');
|
||||
$extensions = ['jpeg', 'gif', 'png'];
|
||||
foreach ($extensions as $extension) {
|
||||
$extensionReturned = $image_style->getDerivativeExtension($extension);
|
||||
$this->assertEquals($extensionReturned, 'png');
|
||||
|
@ -129,7 +129,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
$image_effect_id = $this->randomMachineName();
|
||||
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
|
||||
$image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase')
|
||||
->setConstructorArgs(array(array(), $image_effect_id, array(), $logger))
|
||||
->setConstructorArgs([[], $image_effect_id, [], $logger])
|
||||
->getMock();
|
||||
$image_effect->expects($this->any())
|
||||
->method('getDerivativeExtension')
|
||||
|
@ -141,7 +141,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
// Image style that doesn't change the extension.
|
||||
$image_effect_id = $this->randomMachineName();
|
||||
$image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase')
|
||||
->setConstructorArgs(array(array(), $image_effect_id, array(), $logger))
|
||||
->setConstructorArgs([[], $image_effect_id, [], $logger])
|
||||
->getMock();
|
||||
$image_effect->expects($this->any())
|
||||
->method('getDerivativeExtension')
|
||||
|
@ -162,19 +162,19 @@ class ImageStyleTest extends UnitTestCase {
|
|||
// Image style that changes the extension.
|
||||
$image_effect_id = $this->randomMachineName();
|
||||
$image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase')
|
||||
->setConstructorArgs(array(array(), $image_effect_id, array(), $logger))
|
||||
->setConstructorArgs([[], $image_effect_id, [], $logger])
|
||||
->getMock();
|
||||
$image_effect->expects($this->any())
|
||||
->method('getDerivativeExtension')
|
||||
->will($this->returnValue('png'));
|
||||
|
||||
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, array('getPrivateKey', 'getHashSalt'));
|
||||
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, ['getPrivateKey', 'getHashSalt']);
|
||||
$image_style->expects($this->any())
|
||||
->method('getPrivateKey')
|
||||
->will($this->returnValue($private_key));
|
||||
->method('getPrivateKey')
|
||||
->will($this->returnValue($private_key));
|
||||
$image_style->expects($this->any())
|
||||
->method('getHashSalt')
|
||||
->will($this->returnValue($hash_salt));
|
||||
->method('getHashSalt')
|
||||
->will($this->returnValue($hash_salt));
|
||||
|
||||
// Assert the extension has been added to the URI before creating the token.
|
||||
$this->assertEquals($image_style->getPathToken('public://test.jpeg.png'), $image_style->getPathToken('public://test.jpeg'));
|
||||
|
@ -184,19 +184,19 @@ class ImageStyleTest extends UnitTestCase {
|
|||
// Image style that doesn't change the extension.
|
||||
$image_effect_id = $this->randomMachineName();
|
||||
$image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase')
|
||||
->setConstructorArgs(array(array(), $image_effect_id, array(), $logger))
|
||||
->setConstructorArgs([[], $image_effect_id, [], $logger])
|
||||
->getMock();
|
||||
$image_effect->expects($this->any())
|
||||
->method('getDerivativeExtension')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, array('getPrivateKey', 'getHashSalt'));
|
||||
$image_style = $this->getImageStyleMock($image_effect_id, $image_effect, ['getPrivateKey', 'getHashSalt']);
|
||||
$image_style->expects($this->any())
|
||||
->method('getPrivateKey')
|
||||
->will($this->returnValue($private_key));
|
||||
->method('getPrivateKey')
|
||||
->will($this->returnValue($private_key));
|
||||
$image_style->expects($this->any())
|
||||
->method('getHashSalt')
|
||||
->will($this->returnValue($hash_salt));
|
||||
->method('getHashSalt')
|
||||
->will($this->returnValue($hash_salt));
|
||||
// Assert no extension has been added to the uri before creating the token.
|
||||
$this->assertNotEquals($image_style->getPathToken('public://test.jpeg.png'), $image_style->getPathToken('public://test.jpeg'));
|
||||
$this->assertNotEquals(substr(Crypt::hmacBase64($image_style->id() . ':' . 'public://test.jpeg.png', $private_key . $hash_salt), 0, 8), $image_style->getPathToken('public://test.jpeg'));
|
||||
|
|
Reference in a new issue