function SiteConfigurationExcluderTest::testDefaultSiteDirectoryPermissions

Tests that `sites/default` is made writable in the stage directory.

File

core/modules/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php, line 86

Class

SiteConfigurationExcluderTest
@covers \Drupal\package_manager\PathExcluder\SiteConfigurationExcluder[[api-linebreak]] @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel\PathExcluder

Code

public function testDefaultSiteDirectoryPermissions() : void {
  $project_root = $this->container
    ->get(PathLocator::class)
    ->getProjectRoot();
  $live_dir = $project_root . '/sites/default';
  chmod($live_dir, 0555);
  $this->assertDirectoryIsNotWritable($live_dir);
  // Record the permissions of the directory now, so we can be sure those
  // permissions are restored after apply.
  $original_permissions = fileperms($live_dir);
  $this->assertIsInt($original_permissions);
  $stage = $this->createStage();
  $stage->create();
  // The staged `sites/default` will be made world-writable, because we want
  // to ensure the scaffold plugin can copy certain files into there.
  $staged_dir = str_replace($project_root, $stage->getSandboxDirectory(), $live_dir);
  $this->assertDirectoryIsWritable($staged_dir);
  $stage->require([
    'ext-json:*',
  ]);
  $stage->apply();
  // After applying, the live directory should NOT inherit the staged
  // directory's world-writable permissions.
  $this->assertSame($original_permissions, fileperms($live_dir));
}

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