function SymlinkValidatorTest::testSymlinkPointingOutsideProjectRoot

Tests that relative symlinks cannot point outside the project root.

File

core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php, line 84

Class

SymlinkValidatorTest
@covers \Drupal\package_manager\Validator\SymlinkValidator[[api-linebreak]] @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testSymlinkPointingOutsideProjectRoot() : void {
  $project_root = $this->container
    ->get(PathLocator::class)
    ->getProjectRoot();
  $parent_dir = dirname($project_root);
  touch($parent_dir . '/hello.txt');
  // Relative symlinks must be made from their actual directory to be
  // correctly evaluated.
  chdir($project_root);
  symlink('../hello.txt', 'fail.txt');
  $result = ValidationResult::createError([
    $this->t('The %which directory at %dir contains links that point outside the codebase, which is not supported. The first one is %file.', [
      '%which' => 'active',
      '%dir' => $project_root,
      '%file' => $project_root . '/fail.txt',
    ]),
  ]);
  $this->assertStatusCheckResults([
    $result,
  ]);
  $this->assertResults([
    $result,
  ], PreCreateEvent::class);
}

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