c47b67b0b496f170a9e645cb401b9f4730f100ac
[yaffs-website] / web / core / modules / ckeditor / tests / src / Functional / CKEditorToolbarButtonTest.php
1 <?php
2
3 namespace Drupal\Tests\ckeditor\Functional;
4
5 use Drupal\filter\Entity\FilterFormat;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Component\Serialization\Json;
9
10 /**
11  * Tests CKEditor toolbar buttons when the language direction is RTL.
12  *
13  * @group ckeditor
14  */
15 class CKEditorToolbarButtonTest extends BrowserTestBase {
16
17   /**
18    * Modules to enable for this test.
19    *
20    * @var array
21    */
22   public static $modules = ['filter', 'editor', 'ckeditor', 'locale'];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     // Create a text format and associate this with CKEditor.
31     FilterFormat::create([
32       'format' => 'full_html',
33       'name' => 'Full HTML',
34       'weight' => 1,
35       'filters' => [],
36     ])->save();
37     Editor::create([
38       'format' => 'full_html',
39       'editor' => 'ckeditor',
40     ])->save();
41
42     // Create a new user with admin rights.
43     $this->admin_user = $this->drupalCreateUser([
44       'administer languages',
45       'access administration pages',
46       'administer site configuration',
47       'administer filters',
48     ]);
49   }
50
51   /**
52    * Method tests CKEditor image buttons.
53    */
54   public function testImageButtonDisplay() {
55     $this->drupalLogin($this->admin_user);
56
57     // Install the Arabic language (which is RTL) and configure as the default.
58     $edit = [];
59     $edit['predefined_langcode'] = 'ar';
60     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
61
62     $edit = ['site_default_language' => 'ar'];
63     $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
64     // Once the default language is changed, go to the tested text format
65     // configuration page.
66     $this->drupalGet('admin/config/content/formats/manage/full_html');
67
68     // Check if any image button is loaded in CKEditor json.
69     $json_encode = function ($html) {
70       return trim(Json::encode($html), '"');
71     };
72     $markup = $json_encode(file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/icons/drupalimage.png')));
73     $this->assertRaw($markup);
74   }
75
76 }