30f36e5a7295eaf28cb47e4af481110e296d5dea
[yaffs-website] / web / core / modules / editor / tests / src / Kernel / EditorFilterIntegrationTest.php
1 <?php
2
3 namespace Drupal\Tests\editor\Kernel;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\filter\Entity\FilterFormat;
8 use Drupal\KernelTests\KernelTestBase;
9
10 /**
11  * Tests integration with filter module.
12  *
13  * @group editor
14  */
15 class EditorFilterIntegrationTest extends KernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['filter', 'editor', 'editor_test'];
21
22   /**
23    * Tests text format removal or disabling.
24    */
25   public function testTextFormatIntegration() {
26     // Create an arbitrary text format.
27     $format = FilterFormat::create([
28       'format' => Unicode::strtolower($this->randomMachineName()),
29       'name' => $this->randomString(),
30     ]);
31     $format->save();
32
33     // Create a paired editor.
34     Editor::create(['format' => $format->id(), 'editor' => 'unicorn'])->save();
35
36     // Disable the text format.
37     $format->disable()->save();
38
39     // The paired editor should be disabled too.
40     $this->assertFalse(Editor::load($format->id())->status());
41
42     // Re-enable the text format.
43     $format->enable()->save();
44
45     // The paired editor should be enabled too.
46     $this->assertTrue(Editor::load($format->id())->status());
47
48     // Completely remove the text format. Usually this cannot occur via UI, but
49     // can be triggered from API.
50     $format->delete();
51
52     // The paired editor should be removed.
53     $this->assertNull(Editor::load($format->id()));
54   }
55
56 }