function ForumUninstallTest::testForumUninstallWithoutFieldStorage

Same name and namespace in other branches
  1. 9 core/modules/forum/tests/src/Functional/ForumUninstallTest.php \Drupal\Tests\forum\Functional\ForumUninstallTest::testForumUninstallWithoutFieldStorage()
  2. 10 core/modules/forum/tests/src/Functional/ForumUninstallTest.php \Drupal\Tests\forum\Functional\ForumUninstallTest::testForumUninstallWithoutFieldStorage()
  3. 11.x 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 138

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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.