You are here

protected function GTMTestBase::deleteContainers in GoogleTagManager 8

Delete containers from the database and delete snippet files.

1 call to GTMTestBase::deleteContainers()
GTMTestBase::testModule in tests/src/Functional/GTMTestBase.php
Test the module.

File

tests/src/Functional/GTMTestBase.php, line 166

Class

GTMTestBase
Tests the Google Tag Manager.

Namespace

Drupal\Tests\google_tag\Functional

Code

protected function deleteContainers() {

  // Delete containers.
  foreach ($this->variables as $key => $variables) {

    // Also exposed as \Drupal::entityTypeManager().
    $container = $this->container
      ->get('entity_type.manager')
      ->getStorage('google_tag_container')
      ->load($key);
    $container
      ->delete();
  }

  // Confirm no containers.
  $manager = $this->container
    ->get('google_tag.container_manager');
  $ids = $manager
    ->loadContainerIDs();
  $message = 'No containers found after delete';
  parent::assertTrue(empty($ids), $message);

  // @todo Next statement will not delete files as containers are gone.
  // $manager->createAllAssets();
  // Delete snippet files.
  $directory = $this
    ->config('google_tag.settings')
    ->get('uri');
  if ($this
    ->config('google_tag.settings')
    ->get('flush_snippets')) {
    if (!empty($directory)) {

      // Remove any stale files (e.g. module update or machine name change).
      $this->container
        ->get('file_system')
        ->deleteRecursive($directory . '/google_tag');
    }
  }

  // Confirm no snippet files.
  $message = 'No snippet files found after delete';
  parent::assertDirectoryNotExists($directory . '/google_tag', $message);
}