Version 1
[yaffs-website] / web / core / modules / editor / tests / src / Functional / EditorDialogAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\editor\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Test access to the editor dialog forms.
11  *
12  * @group editor
13  */
14 class EditorDialogAccessTest extends BrowserTestBase {
15
16   /**
17    * Modules to install.
18    *
19    * @var array
20    */
21   public static $modules = ['editor', 'filter', 'ckeditor'];
22
23   /**
24    * Test access to the editor image dialog.
25    */
26   public function testEditorImageDialogAccess() {
27     $url = Url::fromRoute('editor.image_dialog', ['editor' => 'plain_text']);
28     $session = $this->assertSession();
29
30     // With no text editor, expect a 404.
31     $this->drupalGet($url);
32     $session->statusCodeEquals(404);
33
34     // With a text editor but without image upload settings, expect a 200, but
35     // there should not be an input[type=file].
36     $editor = Editor::create([
37       'editor' => 'ckeditor',
38       'format' => 'plain_text',
39       'settings' => [
40         'toolbar' => [
41           'rows' => [
42             [
43               [
44                 'name' => 'Media',
45                 'items' => [
46                   'DrupalImage',
47                 ],
48               ],
49             ],
50           ],
51         ],
52         'plugins' => [],
53       ],
54       'image_upload' => [
55         'status' => FALSE,
56         'scheme' => 'public',
57         'directory' => 'inline-images',
58         'max_size' => '',
59         'max_dimensions' => [
60           'width' => 0,
61           'height' => 0,
62         ],
63       ],
64     ]);
65     $editor->save();
66     $this->resetAll();
67     $this->drupalGet($url);
68     $this->assertTrue($this->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads disabled: input[type=text][name="attributes[src]"] is present.');
69     $this->assertFalse($this->cssSelect('input[type=file]'), 'Image uploads disabled: input[type=file] is absent.');
70     $session->statusCodeEquals(200);
71
72     // With image upload settings, expect a 200, and now there should be an
73     // input[type=file].
74     $editor->setImageUploadSettings(['status' => TRUE] + $editor->getImageUploadSettings())
75       ->save();
76     $this->resetAll();
77     $this->drupalGet($url);
78     $this->assertFalse($this->cssSelect('input[type=text][name="attributes[src]"]'), 'Image uploads enabled: input[type=text][name="attributes[src]"] is absent.');
79     $this->assertTrue($this->cssSelect('input[type=file]'), 'Image uploads enabled: input[type=file] is present.');
80     $session->statusCodeEquals(200);
81   }
82
83 }