View source
<?php
namespace Drupal\Tests\editor\Functional;
use Drupal\Core\Url;
use Drupal\editor\Entity\Editor;
use Drupal\Tests\BrowserTestBase;
class EditorDialogAccessTest extends BrowserTestBase {
protected static $modules = [
'editor',
'filter',
'ckeditor',
];
protected $defaultTheme = 'stark';
public function testEditorImageDialogAccess() {
$url = Url::fromRoute('editor.image_dialog', [
'editor' => 'plain_text',
]);
$session = $this
->assertSession();
$this
->drupalGet($url);
$session
->statusCodeEquals(404);
$editor = Editor::create([
'editor' => 'ckeditor',
'format' => 'plain_text',
'settings' => [
'toolbar' => [
'rows' => [
[
[
'name' => 'Media',
'items' => [
'DrupalImage',
],
],
],
],
],
'plugins' => [],
],
'image_upload' => [
'status' => FALSE,
'scheme' => 'public',
'directory' => 'inline-images',
'max_size' => '',
'max_dimensions' => [
'width' => 0,
'height' => 0,
],
],
]);
$editor
->save();
$this
->resetAll();
$this
->drupalGet($url);
$this
->assertNotEmpty($this
->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads disabled: input[type=text][name="attributes[src]"] is present.');
$this
->assertEmpty($this
->cssSelect('input[type=file]'), 'Image uploads disabled: input[type=file] is absent.');
$session
->statusCodeEquals(200);
$editor
->setImageUploadSettings([
'status' => TRUE,
] + $editor
->getImageUploadSettings())
->save();
$this
->resetAll();
$this
->drupalGet($url);
$this
->assertEmpty($this
->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads enabled: input[type=text][name="attributes[src]"] is absent.');
$this
->assertNotEmpty($this
->cssSelect('input[type=file]'), 'Image uploads enabled: input[type=file] is present.');
$session
->statusCodeEquals(200);
}
}