Skip to content

Commit 75cd861

Browse files
committed
Add more page move tests for editor.
1 parent bb3ce83 commit 75cd861

File tree

5 files changed

+105
-21
lines changed

5 files changed

+105
-21
lines changed

test/Permissions/Editor/Update/NotAllowed/Move/ParentTemplateChildTemplates.php renamed to test/Permissions/Editor/Update/NotAllowed/Move/ParentTemplateChildTemplatesTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
class EditorMoveParentTemplateChildTemplatesTest extends GraphqlTestCase {
99

1010
/**
11-
* + For superuser.
11+
* + For editor.
1212
* + The target template is legal.
1313
* + The new parent template is legal.
14+
* + The user has all required permissions.
1415
* - The target template does not match parent template childTemplates rule.
1516
*/
1617
public static function getSettings()
@@ -21,11 +22,22 @@ public static function getSettings()
2122
'legalTemplates' => ['city', 'skyscraper'],
2223
'access' => [
2324
'templates' => [
25+
[
26+
'name' => 'skyscraper',
27+
'roles' => ['editor'],
28+
'editRoles' => ['editor'],
29+
'rolesPermissions' => [
30+
'editor' => ['page-move']
31+
]
32+
],
2433
[
2534
'name' => 'city',
26-
'childTemplates' => [$architect->id],
35+
'roles' => ['editor'],
36+
'editRoles' => ['editor'],
37+
'addRoles' => ['editor'],
38+
'childTemplates' => ['architect'], // <-- parent template has child templates without target template
2739
],
28-
],
40+
]
2941
],
3042
];
3143
}
@@ -51,7 +63,7 @@ public function testPermission() {
5163

5264
assertNotEquals($newParent->id, $skyscraper->parentID);
5365
$res = self::execute($query, $variables);
54-
assertEquals(1, count($res->errors), 'Does not allow to move if new parent template is not legal.');
66+
assertEquals(1, count($res->errors), 'Does not allow to move if new parent template has childTemplates without target template.');
5567
assertStringContainsString('parent', $res->errors[0]->message);
5668
}
5769
}

test/Permissions/Editor/Update/NotAllowed/Move/ParentTemplateNoChildren.php renamed to test/Permissions/Editor/Update/NotAllowed/Move/ParentTemplateNoChildrenTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class EditorMoveParentTemplateNoChildrenTest extends GraphqlTestCase {
1111
* + For superuser.
1212
* + The target template is legal.
1313
* + The new parent template is legal.
14+
* + The user has all required permissions.
1415
* - The parent template has noChildren checked.
1516
*/
1617
public static function getSettings()
@@ -20,11 +21,23 @@ public static function getSettings()
2021
'legalTemplates' => ['city', 'skyscraper'],
2122
'access' => [
2223
'templates' => [
24+
[
25+
'name' => 'skyscraper',
26+
'roles' => ['editor'],
27+
'editRoles' => ['editor'],
28+
'rolesPermissions' => [
29+
'editor' => ['page-move']
30+
]
31+
],
2332
[
2433
'name' => 'city',
25-
'noChildren' => 1,
34+
'roles' => ['editor'],
35+
'editRoles' => ['editor'],
36+
'addRoles' => ['editor'],
37+
'childTemplates' => ['skyscraper'],
38+
'noChildren' => 1 // <-- parent template has noChildren checked.
2639
],
27-
],
40+
]
2841
],
2942
];
3043
}
@@ -50,7 +63,7 @@ public function testPermission() {
5063

5164
assertNotEquals($newParent->id, $skyscraper->parentID);
5265
$res = self::execute($query, $variables);
53-
assertEquals(1, count($res->errors), 'Does not allow to move if new parent template is not legal.');
66+
assertEquals(1, count($res->errors), 'Does not allow to move if new parent template has noChildren checked.');
5467
assertStringContainsString('parent', $res->errors[0]->message);
5568
}
5669
}

test/Permissions/Editor/Update/NotAllowed/Move/TemplateMovePermissionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EditorUpdateNotAllowedMovePermissionTest extends GraphqlTestCase {
1111
* + For editor.
1212
* + The target template is legal.
1313
* + The parent template is legal.
14-
* - The page-move permission is installed and user does not have that permission.
14+
* - The user does not have page-move permission.
1515
*/
1616
public static function getSettings()
1717
{
@@ -60,7 +60,7 @@ public function testPermission() {
6060

6161
assertNotEquals($newParent->id, $skyscraper->parentID);
6262
$res = self::execute($query, $variables);
63-
assertEquals(1, count($res->errors), 'Does not allow to move the page if page-move permission is installed and user does not have it.');
63+
assertEquals(1, count($res->errors), 'Does not allow to move the page if user does not have page-move permission.');
6464
assertStringContainsString('move', $res->errors[0]->message);
6565
}
6666
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php namespace ProcessWire\GraphQL\Test\Permissions;
2+
3+
use ProcessWire\GraphQL\Test\GraphqlTestCase;
4+
use ProcessWire\GraphQL\Utils;
5+
6+
use function ProcessWire\GraphQL\Test\Assert\assertStringContainsString;
7+
8+
class EditorUpdateNotAllowedParentAddPermissionTest extends GraphqlTestCase {
9+
10+
/**
11+
* + For editor.
12+
* + The target template is legal.
13+
* + The parent template is legal.
14+
* - The user does not have page-add permission for parent template.
15+
*/
16+
public static function getSettings()
17+
{
18+
return [
19+
'login' => 'editor',
20+
'legalTemplates' => ['skyscraper', 'city'],
21+
'legalPageFields' => ['parentID'],
22+
'access' => [
23+
'templates' => [
24+
[
25+
'name' => 'skyscraper',
26+
'roles' => ['editor'],
27+
'editRoles' => ['editor'],
28+
'rolesPermissions' => [
29+
'editor' => ['page-move']
30+
]
31+
],
32+
[
33+
'name' => 'city',
34+
'roles' => ['editor'],
35+
'editRoles' => ['editor'],
36+
// 'addRoles' => ['editor'], // <-- no page-add permission for parent template
37+
],
38+
],
39+
]
40+
];
41+
}
42+
43+
public function testPermission() {
44+
$skyscraper = Utils::pages()->get("template=skyscraper, sort=random");
45+
$newParent = Utils::pages()->get("template=city, id!={$skyscraper->parentID}, sort=random");
46+
$query = 'mutation movePage($id: ID!, $page: SkyscraperUpdateInput!){
47+
updateSkyscraper(id: $id, page: $page) {
48+
id
49+
parentID
50+
}
51+
}';
52+
53+
54+
$variables = [
55+
'id' => $skyscraper->id,
56+
'page' => [
57+
'parent' => $newParent->id,
58+
]
59+
];
60+
61+
assertNotEquals($newParent->id, $skyscraper->parentID);
62+
$res = self::execute($query, $variables);
63+
assertEquals(1, count($res->errors), 'Does not allow to move the page if user has no page-add permission for target parent template.');
64+
assertStringContainsString('parent', $res->errors[0]->message);
65+
}
66+
}

test/Permissions/Permissions.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ Editor
101101
✅ Name conflict
102102
✅ Parent Template legal
103103
✅ ParentTemplates Match
104-
- Template page-move Permission
105-
- Parent Template Add Permission
106-
- Parent Template NoChildren On
107-
- Parent Template ChildTemplates Match
104+
Template page-move Permission
105+
Parent Template page-add Permission
106+
Parent Template NoChildren On
107+
Parent Template ChildTemplates Match
108108

109109
- Trash
110110
- Available
@@ -116,11 +116,4 @@ Editor
116116
- Allowed
117117
- NotAllowed
118118
- Template legal
119-
- Template Delete Permission | Template page-edit-trash-created Permission
120-
121-
- Delete
122-
- Available
123-
- Allowed
124-
- NotAllowed
125-
- Template legal
126-
- Template Delete Permission
119+
- Template Delete Permission | Template page-edit-trash-created Permission

0 commit comments

Comments
 (0)