Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prevent_homepage_deletion
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
prevent_homepage_deletion
Commits
60c1e0fc
Commit
60c1e0fc
authored
1 year ago
by
Josha Hubbers
Committed by
Josha Hubbers
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3354277
by JoshaHubbers: PHPcs issues
parent
d84199d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+0
-1
0 additions, 1 deletion
README.md
prevent_homepage_deletion.module
+3
-0
3 additions, 0 deletions
prevent_homepage_deletion.module
tests/src/Functional/DeleteHomepageTest.php
+16
-10
16 additions, 10 deletions
tests/src/Functional/DeleteHomepageTest.php
with
19 additions
and
11 deletions
README.md
+
0
−
1
View file @
60c1e0fc
...
...
@@ -39,4 +39,3 @@ delete it ;-).
Current maintainers:
-
Josha Hubbers (JoshaHubbers) - https://www.drupal.org/u/joshahubbers-0
This diff is collapsed.
Click to expand it.
prevent_homepage_deletion.module
+
3
−
0
View file @
60c1e0fc
...
...
@@ -51,9 +51,12 @@ function prevent_homepage_deletion_node_access(EntityInterface $entity, $operati
* Helper function that checks if the current user can delete this node.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* Current entity.
* @param \Drupal\Core\Session\AccountInterface $account
* User account.
*
* @return bool
* True if the page can be deleted by this user.
*/
function
_prevent_homepage_deletion_check
(
EntityInterface
$entity
,
AccountInterface
$account
)
{
$candelete
=
TRUE
;
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/DeleteHomepageTest.php
+
16
−
10
View file @
60c1e0fc
...
...
@@ -8,7 +8,6 @@ use Drupal\Tests\BrowserTestBase;
* Tests the functionality of this module.
*
* @group prevent_homepage_deletion
*
*/
class
DeleteHomepageTest
extends
BrowserTestBase
{
...
...
@@ -30,11 +29,18 @@ class DeleteHomepageTest extends BrowserTestBase {
protected
$contentType
;
/**
* Our two nodes.
* Homepage node.
*
* @var \Drupal\node\NodeInterface
*/
protected
$pageHome
;
/**
* Node that is not the homepage.
*
* @var \Drupal\node\NodeInterface
*/
protected
$page_home
;
protected
$page_not_home
;
protected
$pageNotHome
;
/**
* {@inheritdoc}
...
...
@@ -44,14 +50,14 @@ class DeleteHomepageTest extends BrowserTestBase {
// Add a content type.
$this
->
contentType
=
$this
->
createContentType
([
'type'
=>
'page'
]);
// Create a first page (homepage).
$this
->
page
_h
ome
=
$this
->
drupalCreateNode
([
'type'
=>
'page'
]);
$this
->
page
H
ome
=
$this
->
drupalCreateNode
([
'type'
=>
'page'
]);
// Set page to be homepage.
\Drupal
::
configFactory
()
->
getEditable
(
'system.site'
)
->
set
(
'page.front'
,
'/node/'
.
$this
->
page
_h
ome
->
id
())
->
set
(
'page.front'
,
'/node/'
.
$this
->
page
H
ome
->
id
())
->
save
(
TRUE
);
// Create a second page (not homepage).
$this
->
page
_not_h
ome
=
$this
->
drupalCreateNode
([
'type'
=>
'page'
]);
$this
->
page
NotH
ome
=
$this
->
drupalCreateNode
([
'type'
=>
'page'
]);
}
/**
...
...
@@ -67,7 +73,7 @@ class DeleteHomepageTest extends BrowserTestBase {
);
// Step 2: Try to delete the homepage.
$this
->
drupalGet
(
'node/'
.
$this
->
page
_h
ome
->
id
()
.
'/delete'
);
$this
->
drupalGet
(
'node/'
.
$this
->
page
H
ome
->
id
()
.
'/delete'
);
$this
->
assertSession
()
->
statusCodeEquals
(
200
);
// Step 3: Logout, and login as user without the permission.
...
...
@@ -79,11 +85,11 @@ class DeleteHomepageTest extends BrowserTestBase {
);
// Step 4: Try to delete the homepage.
$this
->
drupalGet
(
'node/'
.
$this
->
page
_h
ome
->
id
()
.
'/delete'
);
$this
->
drupalGet
(
'node/'
.
$this
->
page
H
ome
->
id
()
.
'/delete'
);
$this
->
assertSession
()
->
statusCodeEquals
(
403
);
// Step 5: Try to delete the non-homepage.
$this
->
drupalGet
(
'node/'
.
$this
->
page
_not_h
ome
->
id
()
.
'/delete'
);
$this
->
drupalGet
(
'node/'
.
$this
->
page
NotH
ome
->
id
()
.
'/delete'
);
$this
->
assertSession
()
->
statusCodeEquals
(
200
);
}
...
...
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