dfa1f163f7ea918852edf300d65ac81c47c2b1d6
[yaffs-website] / web / core / modules / ckeditor / tests / src / Unit / CKEditorPluginManagerTest.php
1 <?php
2
3 namespace Drupal\Tests\ckeditor\Unit;
4
5 use Drupal\ckeditor\CKEditorPluginManager;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\ckeditor\CKEditorPluginManager
11  *
12  * @group ckeditor
13  */
14 class CKEditorPluginManagerTest extends UnitTestCase {
15
16   /**
17    * Provides a list of configs to test.
18    */
19   public function providerGetEnabledButtons() {
20     return [
21       'empty' => [
22         [],
23         [],
24       ],
25       '1 row, 1 group' => [
26         [
27           // Row 1.
28           [
29             // Group 1.
30             ['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
31           ],
32         ],
33         ['Bold', 'Italic'],
34       ],
35       '1 row, >1 groups' => [
36         [
37           // Row 1.
38           [
39             // Group 1.
40             ['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
41             // Group 2.
42             ['name' => 'Linking', 'items' => ['Link']],
43           ],
44         ],
45         ['Bold', 'Italic', 'Link'],
46       ],
47       '2 rows, 1 group each' => [
48         [
49           // Row 1.
50           [
51             // Group 1.
52             ['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
53           ],
54           // Row 2.
55           [
56             // Group 1.
57             ['name' => 'Tools', 'items' => ['Source']],
58           ],
59         ],
60         ['Bold', 'Italic', 'Source'],
61       ],
62       '2 rows, >1 groups each' => [
63         [
64           // Row 1.
65           [
66             // Group 1.
67             ['name' => 'Formatting', 'items' => ['Bold', 'Italic']],
68             // Group 2.
69             ['name' => 'Linking', 'items' => ['Link']],
70         ],
71           // Row 2.
72           [
73             // Group 1.
74             ['name' => 'Tools', 'items' => ['Source']],
75             // Group 2.
76             ['name' => 'Advanced', 'items' => ['Llama']],
77           ],
78         ],
79         ['Bold', 'Italic', 'Link', 'Source', 'Llama'],
80       ],
81     ];
82   }
83
84   /**
85    * @covers ::getEnabledButtons
86    * @dataProvider providerGetEnabledButtons
87    */
88   public function testGetEnabledButtons(array $toolbar_rows, array $expected_buttons) {
89     $editor = $this->prophesize(Editor::class);
90     $editor->getSettings()
91       ->willReturn(['toolbar' => ['rows' => $toolbar_rows]]);
92
93     $enabled_buttons = CKEditorPluginManager::getEnabledButtons($editor->reveal());
94     $this->assertEquals($expected_buttons, $enabled_buttons);
95   }
96
97 }