Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
automatic_updates
Commits
abca8e74
Commit
abca8e74
authored
2 years ago
by
Adam G-H
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3303185
by phenaproxima, omkar.podey: Add unit test coverage of PathLocator::getWebRoot()
parent
c23769f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!416
Issue #3303185: Add unit test coverage of PathLocator::getWebRoot()
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
package_manager/src/PathLocator.php
+1
-1
1 addition, 1 deletion
package_manager/src/PathLocator.php
package_manager/tests/src/Unit/PathLocatorTest.php
+85
-0
85 additions, 0 deletions
package_manager/tests/src/Unit/PathLocatorTest.php
with
86 additions
and
1 deletion
package_manager/src/PathLocator.php
+
1
−
1
View file @
abca8e74
...
...
@@ -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
);
}
...
...
This diff is collapsed.
Click to expand it.
package_manager/tests/src/Unit/PathLocatorTest.php
+
85
−
0
View file @
abca8e74
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment