You are here

public function ForumUninstallTest::testForumUninstallWithoutFieldStorage in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/forum/tests/src/Functional/ForumUninstallTest.php \Drupal\Tests\forum\Functional\ForumUninstallTest::testForumUninstallWithoutFieldStorage()
  2. 9 core/modules/forum/tests/src/Functional/ForumUninstallTest.php \Drupal\Tests\forum\Functional\ForumUninstallTest::testForumUninstallWithoutFieldStorage()

Tests uninstallation if the field storage has been deleted beforehand.

File

core/modules/forum/tests/src/Functional/ForumUninstallTest.php, line 141

Class

ForumUninstallTest
Tests forum module uninstallation.

Namespace

Drupal\Tests\forum\Functional

Code

public function testForumUninstallWithoutFieldStorage() {

  // Manually delete the taxonomy_forums field before module uninstallation.
  $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
  $this
    ->assertNotNull($field_storage, 'The taxonomy_forums field storage exists.');
  $field_storage
    ->delete();

  // Check that the field is now deleted.
  $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
  $this
    ->assertNull($field_storage, 'The taxonomy_forums field storage has been deleted.');

  // Delete all terms in the Forums vocabulary. Uninstalling the forum module
  // will fail unless this is done.
  $terms = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadByProperties([
    'vid' => 'forums',
  ]);
  foreach ($terms as $term) {
    $term
      ->delete();
  }

  // Ensure that uninstallation succeeds even if the field has already been
  // deleted manually beforehand.
  $this->container
    ->get('module_installer')
    ->uninstall([
    'forum',
  ]);
}