You are here

protected function GTMBaseTestCase::deleteContainers in GoogleTagManager 7.2

Delete containers from the database and delete snippet files.

1 call to GTMBaseTestCase::deleteContainers()
GTMBaseTestCase::testModule in tests/google_tag.base.test
Test the module.

File

tests/google_tag.base.test, line 125

Class

GTMBaseTestCase
Tests the Google Tag Manager.

Code

protected function deleteContainers() {

  // Delete containers.
  foreach ($this->variables as $key => $variables) {
    $container = new GTMContainer(array(), $key);
    $container
      ->delete();
  }

  // Confirm no containers.
  $manager = \GTMContainerManager::getInstance();
  $containers = $manager
    ->loadContainers();
  $message = 'No containers found after delete';
  $this
    ->assert(empty($containers), $message, $this->group);

  // Delete snippet files.
  $directory = \GTMSettings::getInstance()
    ->get('uri');
  if (\GTMSettings::getInstance()
    ->get('flush_snippets')) {
    if (!empty($directory)) {

      // Remove any stale files (e.g. module update or machine name change).
      file_unmanaged_delete_recursive($directory . '/google_tag');
    }
  }

  // Confirm no snippet files.
  $message = 'No snippet files found after delete';
  $this
    ->assert(!is_dir($directory . '/google_tag'), $message, $this->group);
}