View source
<?php
namespace Drupal\Tests\editor\Functional\Rest;
use Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase;
abstract class EditorResourceTestBase extends ConfigEntityResourceTestBase {
protected static $modules = [
'ckeditor5',
'editor',
];
protected static $entityTypeId = 'editor';
protected $entity;
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer filters',
]);
}
protected function createEntity() {
$llama_format = FilterFormat::create([
'name' => 'Llama',
'format' => 'llama',
'langcode' => 'es',
'filters' => [
'filter_html' => [
'status' => TRUE,
'settings' => [
'allowed_html' => '<p> <a> <b> <lo>',
],
],
],
]);
$llama_format
->save();
$camelids = Editor::create([
'format' => 'llama',
'editor' => 'ckeditor5',
]);
$camelids
->setImageUploadSettings([
'status' => FALSE,
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
'width' => '',
'height' => '',
],
])
->save();
return $camelids;
}
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [
'config' => [
'filter.format.llama',
],
'module' => [
'ckeditor5',
],
],
'editor' => 'ckeditor5',
'format' => 'llama',
'image_upload' => [
'status' => FALSE,
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
'width' => NULL,
'height' => NULL,
],
],
'langcode' => 'en',
'settings' => [
'toolbar' => [
'items' => [
'heading',
'bold',
'italic',
],
],
'plugins' => [
'ckeditor5_heading' => Heading::DEFAULT_CONFIGURATION,
],
],
'status' => TRUE,
'uuid' => $this->entity
->uuid(),
];
}
protected function getNormalizedPostEntity() {
return [];
}
protected function getExpectedCacheContexts() {
return [
'user.permissions',
];
}
protected function getExpectedUnauthorizedAccessMessage($method) {
return "The 'administer filters' permission is required.";
}
}