You are here

public function EditorFilterIntegrationTest::testTextFormatIntegration in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/editor/tests/src/Kernel/EditorFilterIntegrationTest.php \Drupal\Tests\editor\Kernel\EditorFilterIntegrationTest::testTextFormatIntegration()
  2. 10 core/modules/editor/tests/src/Kernel/EditorFilterIntegrationTest.php \Drupal\Tests\editor\Kernel\EditorFilterIntegrationTest::testTextFormatIntegration()

Tests text format removal or disabling.

File

core/modules/editor/tests/src/Kernel/EditorFilterIntegrationTest.php, line 24

Class

EditorFilterIntegrationTest
Tests integration with filter module.

Namespace

Drupal\Tests\editor\Kernel

Code

public function testTextFormatIntegration() {

  // Create an arbitrary text format.
  $format = FilterFormat::create([
    'format' => mb_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()));
}