Skip to content

Commit

Permalink
Merge pull request #6717 from getkirby/fix/page-rules-move
Browse files Browse the repository at this point in the history
Move page: allow parent without any pages sections
  • Loading branch information
distantnative authored Oct 3, 2024
2 parents 4938fa2 + 5fac8d5 commit 4bb9013
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Cms/PageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ public static function move(Page $page, Site|Page $parent): bool
}

// check if the template of this page is allowed as subpage type
if (in_array($page->intendedTemplate()->name(), $allowed) === false) {
if (
$allowed !== [] &&
in_array($page->intendedTemplate()->name(), $allowed) === false
) {
throw new PermissionException([
'key' => 'page.move.template',
'data' => [
Expand Down
60 changes: 60 additions & 0 deletions tests/Cms/Pages/PageRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ public function testValidateSlugMaxlength()
PageRules::create($page);
}

/**
* @covers ::move
*/
public function testMove()
{
$app = new App([
Expand Down Expand Up @@ -808,6 +811,9 @@ public function testMove()
$this->assertTrue(PageRules::move($child, $parentB));
}

/**
* @covers ::move
*/
public function testMoveWithoutPermissions()
{
$permissions = $this->createMock(PagePermissions::class);
Expand All @@ -823,6 +829,9 @@ public function testMoveWithoutPermissions()
PageRules::move($page, new Page(['slug' => 'test']));
}

/**
* @covers ::move
*/
public function testMoveWithDuplicate()
{
$app = new App([
Expand Down Expand Up @@ -862,6 +871,9 @@ public function testMoveWithDuplicate()
PageRules::move($child, $parentB);
}

/**
* @covers ::move
*/
public function testMoveWithInvalidTemplate()
{
$app = new App([
Expand Down Expand Up @@ -913,4 +925,52 @@ public function testMoveWithInvalidTemplate()

PageRules::move($child, $parentB);
}

/**
* @covers ::move
*/
public function testMoveWithNoTemplateRestrictions()
{
$app = new App([
'roots' => [
'index' => static::TMP,
],
'site' => [
'children' => [
[
'slug' => 'parent-a',
'template' => 'blog',
'children' => [
[
'slug' => 'child',
'template' => 'article'
]
]
],
[
'slug' => 'parent-b',
'template' => 'photography',
]
]
],
'blueprints' => [
'pages/photography' => [
'sections' => [
'albums' => [
'type' => 'info',
]
]
]
]
]);

$app->impersonate('kirby');

$parentB = $app->page('parent-b');
$child = $app->page('parent-a/child');

$this->expectNotToPerformAssertions();

PageRules::move($child, $parentB);
}
}

0 comments on commit 4bb9013

Please sign in to comment.