function UninstallDefaultContentTest::testReinstall

Same name in other branches
  1. 8.9.x core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::testReinstall()
  2. 10 core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::testReinstall()
  3. 11.x core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php \Drupal\Tests\demo_umami_content\Functional\UninstallDefaultContentTest::testReinstall()

Tests uninstalling content removes created entities.

File

core/profiles/demo_umami/modules/demo_umami_content/tests/src/Functional/UninstallDefaultContentTest.php, line 23

Class

UninstallDefaultContentTest
Tests that uninstalling default content removes created content.

Namespace

Drupal\Tests\demo_umami_content\Functional

Code

public function testReinstall() {
    $module_installer = $this->container
        ->get('module_installer');
    // Test imported blocks on profile install.
    $block_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('block_content');
    $this->assertImportedCustomBlock($block_storage);
    // Test imported nodes on profile install.
    $node_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('node');
    $this->assertRecipesImported($node_storage);
    $count = $node_storage->getQuery()
        ->accessCheck(FALSE)
        ->condition('type', 'article')
        ->count()
        ->execute();
    $this->assertGreaterThan(0, $count);
    // Uninstall the module.
    $module_installer->uninstall([
        'demo_umami_content',
    ]);
    // Reset storage cache.
    $block_storage->resetCache();
    $node_storage->resetCache();
    // Assert the removal of blocks on uninstall.
    foreach ($this->expectedBlocks() as $block_info) {
        $count = $block_storage->getQuery()
            ->accessCheck(FALSE)
            ->condition('type', $block_info['type'])
            ->count()
            ->execute();
        $this->assertEquals(0, $count);
        $block = $block_storage->loadByProperties([
            'uuid' => $block_info['uuid'],
        ]);
        $this->assertCount(0, $block);
    }
    // Assert the removal of nodes on uninstall.
    $count = $node_storage->getQuery()
        ->accessCheck(FALSE)
        ->condition('type', 'article')
        ->count()
        ->execute();
    $this->assertEquals(0, $count);
    $count = $node_storage->getQuery()
        ->accessCheck(FALSE)
        ->condition('type', 'recipe')
        ->count()
        ->execute();
    $this->assertEquals(0, $count);
    // Re-install and assert imported content.
    $module_installer->install([
        'demo_umami_content',
    ]);
    $this->assertRecipesImported($node_storage);
    $this->assertArticlesImported($node_storage);
    $this->assertImportedCustomBlock($block_storage);
}

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