Skip to content
Snippets Groups Projects
Commit abca8e74 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3303185 by phenaproxima, omkar.podey: Add unit test coverage of PathLocator::getWebRoot()

parent c23769f3
No related branches found
No related tags found
1 merge request!416Issue #3303185: Add unit test coverage of PathLocator::getWebRoot()
......@@ -110,7 +110,7 @@ class PathLocator {
* project root and Drupal root are the same.
*/
public function getWebRoot(): string {
$web_root = str_replace($this->getProjectRoot(), '', $this->appRoot);
$web_root = str_replace(trim($this->getProjectRoot(), DIRECTORY_SEPARATOR), '', trim($this->appRoot, DIRECTORY_SEPARATOR));
return trim($web_root, DIRECTORY_SEPARATOR);
}
......
......@@ -34,6 +34,91 @@ class PathLocatorTest extends UnitTestCase {
$this->assertSame('/path/to/temp/.package_managermy_site_id', $path_locator->getStagingRoot());
}
/**
* Data provider for ::testWebRoot().
*
* @return string[][]
* Sets of arguments to pass to the test method.
*/
public function providerWebRoot(): array {
// In certain sites (like those created by drupal/recommended-project), the
// web root is a subdirectory of the project, and exists next to the
// vendor directory.
return [
'recommended project' => [
'/path/to/project/www',
'/path/to/project',
'www',
],
'recommended project with trailing slash on app root' => [
'/path/to/project/www/',
'/path/to/project',
'www',
],
'recommended project with trailing slash on project root' => [
'/path/to/project/www',
'/path/to/project/',
'www',
],
'recommended project with trailing slashes' => [
'/path/to/project/www/',
'/path/to/project/',
'www',
],
// In legacy projects (i.e., created by drupal/legacy-project), the
// web root is the project root.
'legacy project' => [
'/path/to/drupal',
'/path/to/drupal',
'',
],
'legacy project with trailing slash on app root' => [
'/path/to/drupal/',
'/path/to/drupal',
'',
],
'legacy project with trailing slash on project root' => [
'/path/to/drupal',
'/path/to/drupal/',
'',
],
'legacy project with trailing slashes' => [
'/path/to/drupal/',
'/path/to/drupal/',
'',
],
];
}
/**
* Tests that the web root is computed correctly.
*
* @param string $app_root
* The absolute path of the Drupal root.
* @param string $project_root
* The absolute path of the project root.
* @param string $expected_web_root
* The value expected from getWebRoot().
*
* @covers ::getWebRoot
*
* @dataProvider providerWebRoot
*/
public function testWebRoot(string $app_root, string $project_root, string $expected_web_root): void {
$path_locator = $this->getMockBuilder(PathLocator::class)
// Mock all methods except getWebRoot().
->setMethodsExcept(['getWebRoot'])
->setConstructorArgs([
$app_root,
$this->getConfigFactoryStub(),
$this->prophesize(FileSystemInterface::class)->reveal(),
])
->getMock();
$path_locator->method('getProjectRoot')->willReturn($project_root);
$this->assertSame($expected_web_root, $path_locator->getWebRoot());
}
/**
* Tests that deprecations are raised for missing constructor arguments.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment