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:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Ajax\EditorDialogSave.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\CommandInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Ajax\GetUntransformedTextCommand.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\BaseCommand;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Annotation\Editor.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\EditorController.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\EditorInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\EditorXssFilter\Standard.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\EditorXssFilter;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\EditorXssFilterInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor;
|
||||
|
||||
use Drupal\filter\FilterFormatInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Element.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor;
|
||||
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Entity\Editor.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Form\EditorImageDialog.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Form;
|
||||
|
||||
use Drupal\Component\Utility\Bytes;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Form\EditorLinkDialog.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Plugin\EditorBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Plugin;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Plugin\EditorManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Plugin;
|
||||
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Plugin\EditorPluginInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Plugin\Filter\EditorFileReference.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Plugin\Filter;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Plugin\InPlaceEditor\Editor.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Plugin\InPlaceEditor;
|
||||
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorAdminTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
@ -38,7 +33,7 @@ class EditorAdminTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Add text format.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorFileReferenceFilterTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\filter\FilterPluginCollection;
|
||||
|
||||
/**
|
||||
* Tests Editor module's file reference filter.
|
||||
*
|
||||
* @group editor
|
||||
*/
|
||||
class EditorFileReferenceFilterTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'filter', 'editor', 'field', 'file', 'user');
|
||||
|
||||
/**
|
||||
* @var \Drupal\filter\Plugin\FilterInterface[]
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(array('system'));
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
|
||||
$manager = $this->container->get('plugin.manager.filter');
|
||||
$bag = new FilterPluginCollection($manager, array());
|
||||
$this->filters = $bag->getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the editor file reference filter.
|
||||
*/
|
||||
function testEditorFileReferenceFilter() {
|
||||
$filter = $this->filters['editor_file_reference'];
|
||||
|
||||
$test = function($input) use ($filter) {
|
||||
return $filter->process($input, 'und');
|
||||
};
|
||||
|
||||
file_put_contents('public://llama.jpg', $this->randomMachineName());
|
||||
$image = entity_create('file', array('uri' => 'public://llama.jpg'));
|
||||
$image->save();
|
||||
$id = $image->id();
|
||||
$uuid = $image->uuid();
|
||||
$cache_tag = ['file:' . $id];
|
||||
|
||||
file_put_contents('public://alpaca.jpg', $this->randomMachineName());
|
||||
$image_2 = entity_create('file', array('uri' => 'public://alpaca.jpg'));
|
||||
$image_2->save();
|
||||
$id_2 = $image_2->id();
|
||||
$uuid_2 = $image_2->uuid();
|
||||
$cache_tag_2 = ['file:' . $id_2];
|
||||
|
||||
$this->pass('No data-entity-type and no data-entity-uuid attribute.');
|
||||
$input = '<img src="llama.jpg" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
|
||||
$this->pass('A non-file data-entity-type attribute value.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="invalid-entity-type-value" data-entity-uuid="' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
|
||||
$this->pass('One data-entity-uuid attribute.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual($cache_tag, $output->getCacheTags());
|
||||
|
||||
$this->pass('One data-entity-uuid attribute with odd capitalization.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="file" DATA-entity-UUID = "' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual($cache_tag, $output->getCacheTags());
|
||||
|
||||
$this->pass('One data-entity-uuid attribute on a non-image tag.');
|
||||
$input = '<video src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual($cache_tag, $output->getCacheTags());
|
||||
|
||||
$this->pass('One data-entity-uuid attribute with an invalid value.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="invalid-' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual(array(), $output->getCacheTags());
|
||||
|
||||
$this->pass('Two different data-entity-uuid attributes.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
|
||||
$input .= '<img src="alpaca.jpg" data-entity-type="file" data-entity-uuid="' . $uuid_2 . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual(Cache::mergeTags($cache_tag, $cache_tag_2), $output->getCacheTags());
|
||||
|
||||
$this->pass('Two identical data-entity-uuid attributes.');
|
||||
$input = '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
|
||||
$input .= '<img src="llama.jpg" data-entity-type="file" data-entity-uuid="' . $uuid . '" />';
|
||||
$output = $test($input);
|
||||
$this->assertIdentical($input, $output->getProcessedText());
|
||||
$this->assertEqual($cache_tag, $output->getCacheTags());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorFileUsageTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Tests tracking of file usage by the Text Editor module.
|
||||
*
|
||||
* @group editor
|
||||
*/
|
||||
class EditorFileUsageTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('editor', 'editor_test', 'node', 'file');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('node', array('node_access'));
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
$this->installConfig(['node']);
|
||||
|
||||
// Add text formats.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
|
||||
// Set cardinality for body field.
|
||||
FieldStorageConfig::loadByName('node', 'body')
|
||||
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
|
||||
->save();
|
||||
|
||||
// Set up text editor.
|
||||
$editor = entity_create('editor', array(
|
||||
'format' => 'filtered_html',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
$editor->save();
|
||||
|
||||
// Create a node type for testing.
|
||||
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
|
||||
$type->save();
|
||||
node_add_body_field($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the configurable text editor manager.
|
||||
*/
|
||||
public function testEditorEntityHooks() {
|
||||
$image_paths = array(
|
||||
0 => 'core/misc/druplicon.png',
|
||||
1 => 'core/misc/tree.png',
|
||||
2 => 'core/misc/help.png',
|
||||
);
|
||||
|
||||
$image_entities = array();
|
||||
foreach ($image_paths as $key => $image_path) {
|
||||
$image = entity_create('file');
|
||||
$image->setFileUri($image_path);
|
||||
$image->setFilename(drupal_basename($image->getFileUri()));
|
||||
$image->save();
|
||||
|
||||
$file_usage = $this->container->get('file.usage');
|
||||
$this->assertIdentical(array(), $file_usage->listUsage($image), 'The image ' . $image_paths[$key] . ' has zero usages.');
|
||||
|
||||
$image_entities[] = $image;
|
||||
}
|
||||
|
||||
$body = array();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
// Don't be rude, say hello.
|
||||
$body_value = '<p>Hello, world!</p>';
|
||||
// Test handling of a valid image entry.
|
||||
$body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="' . $image_entity->uuid() . '" />';
|
||||
// Test handling of an invalid data-entity-uuid attribute.
|
||||
$body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="invalid-entity-uuid-value" />';
|
||||
// Test handling of an invalid data-entity-type attribute.
|
||||
$body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="invalid-entity-type-value" data-entity-uuid="' . $image_entity->uuid() . '" />';
|
||||
// Test handling of a non-existing UUID.
|
||||
$body_value .= '<img src="awesome-llama-' . $key . '.jpg" data-entity-type="file" data-entity-uuid="30aac704-ba2c-40fc-b609-9ed121aa90f4" />';
|
||||
|
||||
$body[] = array(
|
||||
'value' => $body_value,
|
||||
'format' => 'filtered_html',
|
||||
);
|
||||
}
|
||||
|
||||
// Test editor_entity_insert(): increment.
|
||||
$this->createUser();
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'page',
|
||||
'title' => 'test',
|
||||
'body' => $body,
|
||||
'uid' => 1,
|
||||
));
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '1'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 1 usage.');
|
||||
}
|
||||
|
||||
// Test editor_entity_update(): increment, twice, by creating new revisions.
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
$second_revision_id = $node->getRevisionId();
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
|
||||
}
|
||||
|
||||
// Test hook_entity_update(): decrement, by modifying the last revision:
|
||||
// remove the data-entity-type attribute from the body field.
|
||||
$original_values = array();
|
||||
for ($i = 0; $i < count($image_entities); $i++) {
|
||||
$original_value = $node->body[$i]->value;
|
||||
$new_value = str_replace('data-entity-type', 'data-entity-type-modified', $original_value);
|
||||
$node->body[$i]->value = $new_value;
|
||||
$original_values[$i] = $original_value;
|
||||
}
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
|
||||
}
|
||||
|
||||
// Test editor_entity_update(): increment again by creating a new revision:
|
||||
// read the data- attributes to the body field.
|
||||
$node->setNewRevision(TRUE);
|
||||
foreach ($original_values as $key => $original_value) {
|
||||
$node->body[$key]->value = $original_value;
|
||||
}
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
|
||||
}
|
||||
|
||||
// Test hook_entity_update(): decrement, by modifying the last revision:
|
||||
// remove the data-entity-uuid attribute from the body field.
|
||||
foreach ($original_values as $key => $original_value) {
|
||||
$original_value = $node->body[$key]->value;
|
||||
$new_value = str_replace('data-entity-type', 'data-entity-type-modified', $original_value);
|
||||
$node->body[$key]->value = $new_value;
|
||||
}
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
|
||||
}
|
||||
|
||||
// Test hook_entity_update(): increment, by modifying the last revision:
|
||||
// read the data- attributes to the body field.
|
||||
foreach ($original_values as $key => $original_value) {
|
||||
$node->body[$key]->value = $original_value;
|
||||
}
|
||||
$node->save();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '3'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 3 usages.');
|
||||
}
|
||||
|
||||
// Test editor_entity_revision_delete(): decrement, by deleting a revision.
|
||||
entity_revision_delete('node', $second_revision_id);
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array('editor' => array('node' => array(1 => '2'))), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has 2 usages.');
|
||||
}
|
||||
|
||||
// Test editor_entity_delete().
|
||||
$node->delete();
|
||||
foreach ($image_entities as $key => $image_entity) {
|
||||
$this->assertIdentical(array(), $file_usage->listUsage($image_entity), 'The image ' . $image_paths[$key] . ' has zero usages again.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorImageDialogTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\editor\Form\EditorImageDialog;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests EditorImageDialog validation and conversion functionality.
|
||||
*
|
||||
* @group editor
|
||||
*/
|
||||
class EditorImageDialogTest extends EntityUnitTestBase {
|
||||
|
||||
/**
|
||||
* Filter format for testing.
|
||||
*
|
||||
* @var \Drupal\filter\FilterFormatInterface
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'file', 'editor', 'editor_test', 'user', 'system'];
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('system', ['router', 'key_value_expire']);
|
||||
$this->installSchema('node', array('node_access'));
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
$this->installConfig(['node']);
|
||||
|
||||
// Add text formats.
|
||||
$this->format = FilterFormat::create([
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => [
|
||||
'filter_align' => ['status' => TRUE],
|
||||
'filter_caption' => ['status' => TRUE],
|
||||
],
|
||||
]);
|
||||
$this->format->save();
|
||||
|
||||
// Set up text editor.
|
||||
$editor = Editor::create([
|
||||
'format' => 'filtered_html',
|
||||
'editor' => 'unicorn',
|
||||
'image_upload' => [
|
||||
'max_size' => 100,
|
||||
'scheme' => 'public',
|
||||
'directory' => '',
|
||||
'status' => TRUE,
|
||||
],
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// Create a node type for testing.
|
||||
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
|
||||
$type->save();
|
||||
node_add_body_field($type);
|
||||
$this->installEntitySchema('user');
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that editor image dialog works as expected.
|
||||
*/
|
||||
public function testEditorImageDialog() {
|
||||
$input = [
|
||||
'editor_object' => [
|
||||
'src' => '/sites/default/files/inline-images/somefile.png',
|
||||
'alt' => 'fda',
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'data-entity-type' => 'file',
|
||||
'data-entity-uuid' => 'some-uuid',
|
||||
'data-align' => 'none',
|
||||
'hasCaption' => 'false',
|
||||
],
|
||||
'dialogOptions' => [
|
||||
'title' => 'Edit Image',
|
||||
'dialogClass' => 'editor-image-dialog',
|
||||
'autoResize' => 'true',
|
||||
],
|
||||
'_drupal_ajax' => '1',
|
||||
'ajax_page_state' => [
|
||||
'theme' => 'bartik',
|
||||
'theme_token' => 'some-token',
|
||||
'libraries' => '',
|
||||
],
|
||||
];
|
||||
$form_state = (new FormState())
|
||||
->setRequestMethod('POST')
|
||||
->setUserInput($input)
|
||||
->addBuildInfo('args', [$this->format]);
|
||||
|
||||
$form_builder = $this->container->get('form_builder');
|
||||
$form_object = new EditorImageDialog(\Drupal::entityManager()->getStorage('file'));
|
||||
$form_id = $form_builder->getFormId($form_object, $form_state);
|
||||
$form = $form_builder->retrieveForm($form_id, $form_state);
|
||||
$form_builder->prepareForm($form_id, $form, $form_state);
|
||||
$form_builder->processForm($form_id, $form, $form_state);
|
||||
|
||||
// Assert these two values are present and we don't get the 'not-this'
|
||||
// default back.
|
||||
$this->assertEqual(FALSE, $form_state->getValue(['attributes', 'hasCaption'], 'not-this'));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorLoadingTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Core\Entity\Entity;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests loading of text editors.
|
||||
|
@ -55,14 +51,14 @@ class EditorLoadingTest extends WebTestBase {
|
|||
\Drupal::service('plugin.manager.editor')->clearCachedDefinitions();
|
||||
|
||||
// Add text formats.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
$full_html_format = entity_create('filter_format', array(
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
|
@ -113,7 +109,7 @@ class EditorLoadingTest extends WebTestBase {
|
|||
*/
|
||||
public function testLoading() {
|
||||
// Only associate a text editor with the "Full HTML" text format.
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'full_html',
|
||||
'editor' => 'unicorn',
|
||||
'image_upload' => array(
|
||||
|
@ -123,7 +119,7 @@ class EditorLoadingTest extends WebTestBase {
|
|||
'max_size' => '',
|
||||
'max_dimensions' => array('width' => '', 'height' => ''),
|
||||
)
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// The normal user:
|
||||
|
@ -166,10 +162,10 @@ class EditorLoadingTest extends WebTestBase {
|
|||
$this->drupalLogout($this->privilegedUser);
|
||||
|
||||
// Also associate a text editor with the "Plain Text" text format.
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'plain_text',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// The untrusted user:
|
||||
|
@ -221,7 +217,7 @@ class EditorLoadingTest extends WebTestBase {
|
|||
*/
|
||||
public function testSupportedElementTypes() {
|
||||
// Associate the unicorn text editor with the "Full HTML" text format.
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'full_html',
|
||||
'editor' => 'unicorn',
|
||||
'image_upload' => array(
|
||||
|
@ -231,7 +227,7 @@ class EditorLoadingTest extends WebTestBase {
|
|||
'max_size' => '',
|
||||
'max_dimensions' => array('width' => '', 'height' => ''),
|
||||
)
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// Create an "page" node that uses the full_html text format.
|
||||
|
@ -255,10 +251,10 @@ class EditorLoadingTest extends WebTestBase {
|
|||
|
||||
// Associate the trex text editor with the "Full HTML" text format.
|
||||
$editor->delete();
|
||||
entity_create('editor', array(
|
||||
Editor::create([
|
||||
'format' => 'full_html',
|
||||
'editor' => 'trex',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
$this->drupalGet('node/1/edit');
|
||||
list( , $editor_settings_present, $editor_js_present, $field, $format_selector) = $this->getThingsToCheck('field-text', 'input');
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests detection of text editors and correct generation of attachments.
|
||||
*
|
||||
* @group editor
|
||||
*/
|
||||
class EditorManagerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'user', 'filter', 'editor');
|
||||
|
||||
/**
|
||||
* The manager for text editor plugins.
|
||||
*
|
||||
* @var \Drupal\Component\Plugin\PluginManagerInterface
|
||||
*/
|
||||
protected $editorManager;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Install the Filter module.
|
||||
$this->installSchema('system', 'url_alias');
|
||||
|
||||
// Add text formats.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$filtered_html_format->save();
|
||||
$full_html_format = entity_create('filter_format', array(
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
'filters' => array(),
|
||||
));
|
||||
$full_html_format->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the configurable text editor manager.
|
||||
*/
|
||||
public function testManager() {
|
||||
$this->editorManager = $this->container->get('plugin.manager.editor');
|
||||
|
||||
// Case 1: no text editor available:
|
||||
// - listOptions() should return an empty list of options
|
||||
// - getAttachments() should return an empty #attachments array (and not
|
||||
// a JS settings structure that is empty)
|
||||
$this->assertIdentical(array(), $this->editorManager->listOptions(), 'When no text editor is enabled, the manager works correctly.');
|
||||
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when no text editor is enabled and retrieving attachments for zero text formats.');
|
||||
$this->assertIdentical(array(), $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'No attachments when no text editor is enabled and retrieving attachments for multiple text formats.');
|
||||
|
||||
// Enable the Text Editor Test module, which has the Unicorn Editor and
|
||||
// clear the editor manager's cache so it is picked up.
|
||||
$this->enableModules(array('editor_test'));
|
||||
$this->editorManager = $this->container->get('plugin.manager.editor');
|
||||
$this->editorManager->clearCachedDefinitions();
|
||||
|
||||
// Case 2: a text editor available.
|
||||
$this->assertIdentical('Unicorn Editor', (string) $this->editorManager->listOptions()['unicorn'], 'When some text editor is enabled, the manager works correctly.');
|
||||
|
||||
// Case 3: a text editor available & associated (but associated only with
|
||||
// the 'Full HTML' text format).
|
||||
$unicorn_plugin = $this->editorManager->createInstance('unicorn');
|
||||
$editor = entity_create('editor', array(
|
||||
'format' => 'full_html',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
$editor->save();
|
||||
$this->assertIdentical(array(), $this->editorManager->getAttachments(array()), 'No attachments when one text editor is enabled and retrieving attachments for zero text formats.');
|
||||
$expected = array(
|
||||
'library' => array(
|
||||
0 => 'editor_test/unicorn',
|
||||
),
|
||||
'drupalSettings' => [
|
||||
'editor' => [
|
||||
'formats' => [
|
||||
'full_html' => [
|
||||
'format' => 'full_html',
|
||||
'editor' => 'unicorn',
|
||||
'editorSettings' => $unicorn_plugin->getJSSettings($editor),
|
||||
'editorSupportsContentFiltering' => TRUE,
|
||||
'isXssSafe' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'Correct attachments when one text editor is enabled and retrieving attachments for multiple text formats.');
|
||||
|
||||
// Case 4: a text editor available associated, but now with its JS settings
|
||||
// being altered via hook_editor_js_settings_alter().
|
||||
\Drupal::state()->set('editor_test_js_settings_alter_enabled', TRUE);
|
||||
$expected['drupalSettings']['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
|
||||
$this->assertIdentical($expected, $this->editorManager->getAttachments(array('filtered_html', 'full_html')), 'hook_editor_js_settings_alter() works correctly.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\EditorSecurityTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests XSS protection for content creators when using text editors.
|
||||
|
@ -86,7 +83,7 @@ class EditorSecurityTest extends WebTestBase {
|
|||
// With text formats 2, 3 and 5, we also associate a text editor that does
|
||||
// not guarantee XSS safety. "restricted" means the text format has XSS
|
||||
// filters on output, "unrestricted" means the opposite.
|
||||
$format = entity_create('filter_format', array(
|
||||
$format = FilterFormat::create(array(
|
||||
'format' => 'restricted_without_editor',
|
||||
'name' => 'Restricted HTML, without text editor',
|
||||
'weight' => 0,
|
||||
|
@ -101,7 +98,7 @@ class EditorSecurityTest extends WebTestBase {
|
|||
),
|
||||
));
|
||||
$format->save();
|
||||
$format = entity_create('filter_format', array(
|
||||
$format = FilterFormat::create(array(
|
||||
'format' => 'restricted_with_editor',
|
||||
'name' => 'Restricted HTML, with text editor',
|
||||
'weight' => 1,
|
||||
|
@ -116,12 +113,12 @@ class EditorSecurityTest extends WebTestBase {
|
|||
),
|
||||
));
|
||||
$format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'restricted_with_editor',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
$format = entity_create('filter_format', array(
|
||||
$format = FilterFormat::create(array(
|
||||
'format' => 'restricted_plus_dangerous_tag_with_editor',
|
||||
'name' => 'Restricted HTML, dangerous tag allowed, with text editor',
|
||||
'weight' => 1,
|
||||
|
@ -136,29 +133,29 @@ class EditorSecurityTest extends WebTestBase {
|
|||
),
|
||||
));
|
||||
$format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'restricted_plus_dangerous_tag_with_editor',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
$format = entity_create('filter_format', array(
|
||||
$format = FilterFormat::create(array(
|
||||
'format' => 'unrestricted_without_editor',
|
||||
'name' => 'Unrestricted HTML, without text editor',
|
||||
'weight' => 0,
|
||||
'filters' => array(),
|
||||
));
|
||||
$format->save();
|
||||
$format = entity_create('filter_format', array(
|
||||
$format = FilterFormat::create(array(
|
||||
'format' => 'unrestricted_with_editor',
|
||||
'name' => 'Unrestricted HTML, with text editor',
|
||||
'weight' => 1,
|
||||
'filters' => array(),
|
||||
));
|
||||
$format->save();
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => 'unrestricted_with_editor',
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\QuickEditIntegrationLoadingTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests Quick Edit module integration endpoints.
|
||||
|
@ -36,7 +32,7 @@ class QuickEditIntegrationLoadingTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create a text format.
|
||||
$filtered_html_format = entity_create('filter_format', array(
|
||||
$filtered_html_format = FilterFormat::create(array(
|
||||
'format' => 'filtered_html',
|
||||
'name' => 'Filtered HTML',
|
||||
'weight' => 0,
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\QuickEditIntegrationTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\quickedit\MetadataGenerator;
|
||||
use Drupal\quickedit\Tests\QuickEditTestBase;
|
||||
use Drupal\quickedit_test\MockEditEntityFieldAccessCheck;
|
||||
|
@ -17,6 +14,7 @@ use Drupal\editor\EditorController;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests Edit module integration (Editor module's inline editing support).
|
||||
|
@ -69,7 +67,6 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Install the Filter module.
|
||||
$this->installSchema('system', 'url_alias');
|
||||
|
||||
// Create a field.
|
||||
$this->fieldName = 'field_textarea';
|
||||
|
@ -86,7 +83,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
);
|
||||
|
||||
// Create text format.
|
||||
$full_html_format = entity_create('filter_format', array(
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
|
@ -95,14 +92,14 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
$full_html_format->save();
|
||||
|
||||
// Associate text editor with text format.
|
||||
$editor = entity_create('editor', array(
|
||||
$editor = Editor::create([
|
||||
'format' => $full_html_format->id(),
|
||||
'editor' => 'unicorn',
|
||||
));
|
||||
]);
|
||||
$editor->save();
|
||||
|
||||
// Also create a text format without an associated text editor.
|
||||
entity_create('filter_format', array(
|
||||
FilterFormat::create(array(
|
||||
'format' => 'no_editor',
|
||||
'name' => 'No Text Editor',
|
||||
'weight' => 2,
|
||||
|
@ -142,7 +139,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
$this->editorSelector = $this->container->get('quickedit.editor.selector');
|
||||
|
||||
// Create an entity with values for this text field.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$entity->{$this->fieldName}->value = 'Hello, world!';
|
||||
$entity->{$this->fieldName}->format = 'filtered_html';
|
||||
$entity->save();
|
||||
|
@ -171,7 +168,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
|
||||
|
||||
// Create an entity with values for the field.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$entity->{$this->fieldName}->value = 'Test';
|
||||
$entity->{$this->fieldName}->format = 'full_html';
|
||||
$entity->save();
|
||||
|
@ -208,7 +205,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
*/
|
||||
public function testGetUntransformedTextCommand() {
|
||||
// Create an entity with values for the field.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$entity->{$this->fieldName}->value = 'Test';
|
||||
$entity->{$this->fieldName}->format = 'full_html';
|
||||
$entity->save();
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\editor\Tests\Update\EditorUpdateTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\editor\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
|
Reference in a new issue