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
a15542ca
Commit
a15542ca
authored
3 years ago
by
Ted Bowman
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3243422
by phenaproxima, tedbow: Add a kernel test of WritableFileSystemValidator
parent
56499f0c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!78
Issue #3243422: Add a kernel test of WritableFileSystemValidator
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/Kernel/AutomaticUpdatesKernelTestBase.php
+10
-3
10 additions, 3 deletions
tests/src/Kernel/AutomaticUpdatesKernelTestBase.php
tests/src/Kernel/ReadinessValidation/WritableFileSystemValidatorTest.php
+112
-0
112 additions, 0 deletions
...l/ReadinessValidation/WritableFileSystemValidatorTest.php
with
122 additions
and
3 deletions
tests/src/Kernel/AutomaticUpdatesKernelTestBase.php
+
10
−
3
View file @
a15542ca
...
...
@@ -86,10 +86,17 @@ abstract class AutomaticUpdatesKernelTestBase extends KernelTestBase {
$container
->
set
(
'http_client'
,
$this
->
client
);
}
$this
->
disableValidators
(
$container
);
}
/**
* Disables any validators that will interfere with this test.
*/
protected
function
disableValidators
(
ContainerBuilder
$container
):
void
{
// Disable the filesystem permissions validator, since we cannot guarantee
// that the current code base will be writable in all testing situations.
We
// test this validator in our build tests, since those do
give us control
// over the filesystem permissions.
// that the current code base will be writable in all testing situations.
//
We
test this validator
functionally
in our build tests, since those do
//
give us control
over the filesystem permissions.
// @see \Drupal\Tests\automatic_updates\Build\CoreUpdateTest::assertReadOnlyFileSystemError()
$container
->
removeDefinition
(
'automatic_updates.validator.file_system_permissions'
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/ReadinessValidation/WritableFileSystemValidatorTest.php
0 → 100644
+
112
−
0
View file @
a15542ca
<?php
namespace
Drupal\Tests\automatic_updates\Kernel\ReadinessValidation
;
use
Drupal\automatic_updates
\PathLocator
;
use
Drupal\automatic_updates
\Validation\ValidationResult
;
use
Drupal\automatic_updates
\Validator\WritableFileSystemValidator
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Tests\automatic_updates
\Kernel\AutomaticUpdatesKernelTestBase
;
use
org\bovigo\vfs\vfsStream
;
/**
* Unit tests the file system permissions validator.
*
* This validator is tested functionally in our build tests, since those give
* us control over the file system permissions.
*
* @see \Drupal\Tests\automatic_updates\Build\CoreUpdateTest::assertReadOnlyFileSystemError()
*
* @covers \Drupal\automatic_updates\Validator\WritableFileSystemValidator
*
* @group automatic_updates
*/
class
WritableFileSystemValidatorTest
extends
AutomaticUpdatesKernelTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'automatic_updates'
,
'package_manager'
,
];
/**
* {@inheritdoc}
*/
protected
function
disableValidators
(
ContainerBuilder
$container
):
void
{
// No need to disable any validators in this test.
}
/**
* Data provider for ::testWritable().
*
* @return array[]
* Sets of arguments to pass to the test method.
*/
public
function
providerWritable
():
array
{
$root_error
=
t
(
'The Drupal directory "vfs://root" is not writable.'
);
$vendor_error
=
t
(
'The vendor directory "vfs://root/vendor" is not writable.'
);
$summary
=
t
(
'The file system is not writable.'
);
$writable_permission
=
0777
;
$non_writable_permission
=
0444
;
return
[
'root and vendor are writable'
=>
[
$writable_permission
,
$writable_permission
,
[],
],
'root writable, vendor not writable'
=>
[
$writable_permission
,
$non_writable_permission
,
[
ValidationResult
::
createError
([
$vendor_error
],
$summary
),
],
],
'root not writable, vendor writable'
=>
[
$non_writable_permission
,
$writable_permission
,
[
ValidationResult
::
createError
([
$root_error
],
$summary
),
],
],
'nothing writable'
=>
[
$non_writable_permission
,
$non_writable_permission
,
[
ValidationResult
::
createError
([
$root_error
,
$vendor_error
],
$summary
),
],
],
];
}
/**
* Tests the file system permissions validator.
*
* @param int $root_permissions
* The file permissions for the root folder.
* @param int $vendor_permissions
* The file permissions for the vendor folder.
* @param array $expected_results
* The expected validation results.
*
* @dataProvider providerWritable
*/
public
function
testWritable
(
int
$root_permissions
,
int
$vendor_permissions
,
array
$expected_results
):
void
{
$files
=
vfsStream
::
setup
(
'root'
,
$root_permissions
);
$files
->
addChild
(
vfsStream
::
newDirectory
(
'vendor'
,
$vendor_permissions
));
$path_locator
=
$this
->
prophesize
(
PathLocator
::
class
);
$path_locator
->
getVendorDirectory
()
->
willReturn
(
vfsStream
::
url
(
'root/vendor'
));
$validator
=
new
WritableFileSystemValidator
(
$path_locator
->
reveal
(),
vfsStream
::
url
(
'root'
),
$this
->
container
->
get
(
'string_translation'
)
);
$this
->
container
->
set
(
'automatic_updates.validator.file_system_permissions'
,
$validator
);
$this
->
assertCheckerResultsFromManager
(
$expected_results
,
TRUE
);
}
}
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