class StageNotInActiveValidatorTest
@coversDefaultClass \Drupal\package_manager\Validator\StageNotInActiveValidator @group package_manager @internal
Hierarchy
- class \Drupal\Tests\package_manager\Unit\StageNotInActiveValidatorTest extends \Drupal\Tests\UnitTestCase uses \Drupal\Tests\package_manager\Traits\ValidationTestTrait
Expanded class hierarchy of StageNotInActiveValidatorTest
File
-
core/
modules/ package_manager/ tests/ src/ Unit/ StageNotInActiveValidatorTest.php, line 22
Namespace
Drupal\Tests\package_manager\UnitView source
class StageNotInActiveValidatorTest 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(StageBase::class)
->reveal();
$stage_not_in_active_validator = new StageNotInActiveValidator($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('Stage 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::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
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. | |
StageNotInActiveValidatorTest::providerTestCheckNotInActive | public static | function | Data provider for testCheckNotInActive(). | |
StageNotInActiveValidatorTest::testCheckNotInActive | public | function | @covers ::validate | |
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::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
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::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function | ||
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.