You are here

protected function FileSystemOperationsTest::setUp in Automatic Updates 8.2

Overrides BrowserTestBase::setUp

File

tests/src/Functional/FileSystemOperationsTest.php, line 44

Class

FileSystemOperationsTest
Tests handling of files and directories during an update.

Namespace

Drupal\Tests\automatic_updates\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create a mocked path locator that uses the fake site fixture as its
  // active directory, and has a staging area within the site directory for
  // this test.
  $drupal_root = $this
    ->getDrupalRoot();

  /** @var \Drupal\automatic_updates\PathLocator|\Prophecy\Prophecy\ObjectProphecy $locator */
  $locator = $this
    ->prophesize(PathLocator::class);
  $locator
    ->getActiveDirectory()
    ->willReturn(__DIR__ . '/../../fixtures/fake-site');
  $this->stageDir = implode(DIRECTORY_SEPARATOR, [
    $drupal_root,
    $this->siteDirectory,
    'stage',
  ]);
  $locator
    ->getStageDirectory()
    ->willReturn($this->stageDir);
  $locator
    ->getProjectRoot()
    ->willReturn($drupal_root);
  $locator
    ->getWebRoot()
    ->willReturn('');

  // Create a cleaner that uses 'sites/default' as its site path, since it
  // will otherwise default to the site path being used for the test site,
  // which doesn't exist in the fake site fixture.
  $cleaner = new Cleaner($this->container
    ->get('package_manager.cleaner'), 'sites/default', $locator
    ->reveal());
  $this->updater = new Updater($this->container
    ->get('state'), $this->container
    ->get('string_translation'), $this->container
    ->get('package_manager.beginner'), $this->container
    ->get('package_manager.stager'), $cleaner, $this->container
    ->get('package_manager.committer'), $this->container
    ->get('event_dispatcher'), $locator
    ->reveal());

  // Use the public and private files directories in the fake site fixture.
  $settings = Settings::getAll();
  $settings['file_public_path'] = 'files/public';
  $settings['file_private_path'] = 'files/private';
  new Settings($settings);

  // Updater::begin() will trigger update validators, such as
  // \Drupal\automatic_updates\Validator\UpdateVersionValidator, that need to
  // fetch release metadata. We need to ensure that those HTTP request(s)
  // succeed, so set them up to point to our fake release metadata.
  $this
    ->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.1-security.xml');
  $this
    ->setCoreVersion('9.8.0');
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->checkForUpdates();
  $this
    ->drupalLogout();
}