function SandboxManagerBaseTest::testConfigChangeDeletesSandbox

Same name and namespace in other branches
  1. main core/modules/package_manager/tests/src/Kernel/SandboxManagerBaseTest.php \Drupal\Tests\package_manager\Kernel\SandboxManagerBaseTest::testConfigChangeDeletesSandbox()

Tests that the sandbox directory is deleted on config change.

When 'include_unknown_files_in_project_root' is changed to FALSE, the sandbox directory should be deleted directly to ensure unknown files from a previous sync are not retained.

@legacy-covers \Drupal\package_manager\EventSubscriber\LongLivedSandboxSubscriber

File

core/modules/package_manager/tests/src/Kernel/SandboxManagerBaseTest.php, line 644

Class

SandboxManagerBaseTest
Tests Drupal\package_manager\SandboxManagerBase.

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testConfigChangeDeletesSandbox() : void {
  $stage = $this->createStage();
  $stage->create();
  $dir = $stage->getSandboxDirectory();
  $this->assertDirectoryExists($dir);
  $stage->destroy();
  $this->assertDirectoryExists($dir);
  // First enable the setting, then disable it to trigger the subscriber.
  $config = $this->config('package_manager.settings');
  $config->set('include_unknown_files_in_project_root', TRUE)
    ->save();
  // Directory should still exist after enabling.
  $this->assertDirectoryExists($dir);
  // Disabling should delete the sandbox directory immediately.
  $config->set('include_unknown_files_in_project_root', FALSE)
    ->save();
  $this->assertDirectoryDoesNotExist($dir);
  // The create event timestamp should also be cleared.
  $this->assertNull($this->container
    ->get('state')
    ->get(LongLivedSandboxSubscriber::STATE_KEY));
}

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