EditorResourceTestBase.php

Same filename in other branches
  1. 9 core/modules/editor/tests/src/Functional/Rest/EditorResourceTestBase.php
  2. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php
  3. 8.9.x core/modules/editor/tests/src/Functional/Rest/EditorResourceTestBase.php
  4. 10 core/modules/editor/tests/src/Functional/Rest/EditorResourceTestBase.php

Namespace

Drupal\Tests\editor\Functional\Rest

File

core/modules/editor/tests/src/Functional/Rest/EditorResourceTestBase.php

View source
<?php

declare (strict_types=1);
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;

/**
 * ResourceTestBase for Editor entity.
 */
abstract class EditorResourceTestBase extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'ckeditor5',
        'editor',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'editor';
    
    /**
     * The Editor entity.
     *
     * @var \Drupal\editor\EditorInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        $this->grantPermissionsToTestedRole([
            'administer filters',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function createEntity() {
        // Create a "Llama" filter format.
        $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();
        // Create a "Camelids" editor.
        $camelids = Editor::create([
            'format' => 'llama',
            'editor' => 'ckeditor5',
            'image_upload' => [
                'status' => FALSE,
            ],
        ]);
        $camelids->setImageUploadSettings([
            'status' => TRUE,
            'scheme' => 'public',
            'directory' => 'inline-images',
            'max_size' => NULL,
            'max_dimensions' => [
                'width' => NULL,
                'height' => NULL,
            ],
        ])
            ->save();
        return $camelids;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedNormalizedEntity() {
        return [
            'dependencies' => [
                'config' => [
                    'filter.format.llama',
                ],
                'module' => [
                    'ckeditor5',
                ],
            ],
            'editor' => 'ckeditor5',
            'format' => 'llama',
            'image_upload' => [
                'status' => TRUE,
                'scheme' => 'public',
                'directory' => 'inline-images',
                'max_size' => NULL,
                '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(),
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getNormalizedPostEntity() {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedCacheContexts() {
        // @see ::createEntity()
        return [
            'user.permissions',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        return "The 'administer filters' permission is required.";
    }

}

Classes

Title Deprecated Summary
EditorResourceTestBase ResourceTestBase for Editor entity.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.