class SandboxDirectoryValidatorTest

@coversDefaultClass \Drupal\package_manager\Validator\SandboxDirectoryValidator
@group package_manager @internal

Hierarchy

Expanded class hierarchy of SandboxDirectoryValidatorTest

File

core/modules/package_manager/tests/src/Unit/SandboxDirectoryValidatorTest.php, line 22

Namespace

Drupal\Tests\package_manager\Unit
View source
class SandboxDirectoryValidatorTest extends UnitTestCase {
  use ValidationTestTrait;
  
  /**
   * @covers ::validate
   *
   * @param \Drupal\package_manager\ValidationResult[] $expected
   *   The expected result.
   * @param string $project_root
   *   The project root.
   * @param string $staging_root
   *   The staging root.
   *
   * @dataProvider providerTestCheckNotInActive
   */
  public function testCheckNotInActive(array $expected, string $project_root, string $staging_root) : void {
    $path_locator_prophecy = $this->prophesize(PathLocator::class);
    $path_locator_prophecy->getProjectRoot()
      ->willReturn(Path::canonicalize($project_root));
    $path_locator_prophecy->getStagingRoot()
      ->willReturn(Path::canonicalize($staging_root));
    $path_locator_prophecy->getVendorDirectory()
      ->willReturn('not used');
    $path_locator = $path_locator_prophecy->reveal();
    $stage = $this->prophesize(SandboxManagerBase::class)
      ->reveal();
    $stage_not_in_active_validator = new SandboxDirectoryValidator($path_locator);
    $stage_not_in_active_validator->setStringTranslation($this->getStringTranslationStub());
    $event = new PreCreateEvent($stage, $this->createMock(PathListInterface::class));
    $stage_not_in_active_validator->validate($event);
    $this->assertValidationResultsEqual($expected, $event->getResults(), $path_locator);
  }
  
  /**
   * Data provider for testCheckNotInActive().
   *
   * @return mixed[]
   *   The test cases.
   */
  public static function providerTestCheckNotInActive() : array {
    $expected_symlink_validation_error = ValidationResult::createError([
      t('The sandbox directory is a subdirectory of the active directory.'),
    ]);
    return [
      "Absolute paths which don't satisfy" => [
        [
          $expected_symlink_validation_error,
        ],
        "/var/root",
        "/var/root/xyz",
      ],
      "Absolute paths which satisfy" => [
        [],
        "/var/root",
        "/home/var/root",
      ],
      'Stage with .. segments, outside active' => [
        [],
        "/var/root/active",
        "/var/root/active/../stage",
      ],
      'Stage without .. segments, outside active' => [
        [],
        "/var/root/active",
        "/var/root/stage",
      ],
      'Stage with .. segments, inside active' => [
        [
          $expected_symlink_validation_error,
        ],
        "/var/root/active",
        "/var/root/active/../active/stage",
      ],
      'Stage without .. segments, inside active' => [
        [
          $expected_symlink_validation_error,
        ],
        "/var/root/active",
        "/var/root/active/stage",
      ],
      'Stage with .. segments, outside active, active with .. segments' => [
        [],
        "/var/root/active",
        "/var/root/active/../stage",
      ],
      'Stage without .. segments, outside active, active with .. segments' => [
        [],
        "/var/root/random/../active",
        "/var/root/stage",
      ],
      'Stage with .. segments, inside active, active with .. segments' => [
        [
          $expected_symlink_validation_error,
        ],
        "/var/root/random/../active",
        "/var/root/active/../active/stage",
      ],
      'Stage without .. segments, inside active, active with .. segments' => [
        [
          $expected_symlink_validation_error,
        ],
        "/var/root/random/../active",
        "/var/root/active/stage",
      ],
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
SandboxDirectoryValidatorTest::providerTestCheckNotInActive public static function Data provider for testCheckNotInActive().
SandboxDirectoryValidatorTest::testCheckNotInActive public function @covers ::validate[[api-linebreak]]
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
UnitTestCase::setUp protected function 375
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.
ValidationTestTrait::assertValidationResultsEqual protected function Asserts two validation result sets are equal.
ValidationTestTrait::getValidationResultsAsArray protected function Gets an array representation of validation results for easy comparison.
ValidationTestTrait::resolvePlaceholdersInArrayValuesWithRealPaths protected function Resolves <PROJECT_ROOT>, <VENDOR_DIR>, <STAGE_ROOT>, <STAGE_ROOT_PARENT>.

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