EditorFilterIntegrationTest.php 1.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

/**
 * @file
 * Contains \Drupal\Tests\editor\Kernel\EditorFilterIntegration.
 */

namespace Drupal\Tests\editor\Kernel;

use Drupal\Component\Utility\Unicode;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests integration with filter module.
 *
 * @group editor
 */
class EditorFilterIntegrationTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = ['filter', 'editor', 'editor_test'];

  /**
   * Tests text format removal or disabling.
   */
  public function testTextFormatIntegration() {
    // Create an arbitrary text format.
    $format = FilterFormat::create([
      'format' => Unicode::strtolower($this->randomMachineName()),
      'name' => $this->randomString(),
    ]);
    $format->save();

    // Create a paired editor.
    Editor::create(['format' => $format->id(), 'editor' => 'unicorn'])->save();

    // Disable the text format.
    $format->disable()->save();

    // The paired editor should be disabled too.
    $this->assertFalse(Editor::load($format->id())->status());

    // Re-enable the text format.
    $format->enable()->save();

    // The paired editor should be enabled too.
    $this->assertTrue(Editor::load($format->id())->status());

    // Completely remove the text format. Usually this cannot occur via UI, but
    // can be triggered from API.
    $format->delete();

    // The paired editor should be removed.
    $this->assertNull(Editor::load($format->id()));
  }

}