You are here

public function UninstallDefaultContentTest::testReinstall in Drupal 8

Same name and namespace in other branches
  1. 9 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()
    ->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()
      ->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()
    ->condition('type', 'article')
    ->count()
    ->execute();
  $this
    ->assertEquals(0, $count);
  $count = $node_storage
    ->getQuery()
    ->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);
}