Skip to content

Commit 915d7f7

Browse files
authored
Migrate to Github actions (#31)
1 parent 2a40067 commit 915d7f7

File tree

7 files changed

+162
-122
lines changed

7 files changed

+162
-122
lines changed

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Test
2+
on: [push]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
include:
9+
- php-version: 7.2
10+
phpunit: 7.5
11+
mysql: 5.7.33
12+
- php-version: 8.0
13+
phpunit: 9.5
14+
mysql: 8.0.23
15+
services:
16+
mysql:
17+
image: mysql:${{ matrix.mysql }}
18+
env:
19+
MYSQL_ROOT_PASSWORD: root
20+
MYSQL_DATABASE: processgraphql
21+
MYSQL_USER: processgraphql
22+
MYSQL_PASSWORD: processgraphql
23+
ports:
24+
- 3306:3306
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v2
28+
29+
- name: Setup Node
30+
uses: actions/setup-node@v2
31+
with:
32+
node-version: '14'
33+
check-latest: true
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: '${{ matrix.php-version }}'
39+
tools: composer
40+
41+
- name: Dependencies
42+
run: |
43+
rm composer.lock
44+
composer require phpunit/phpunit ^${{ matrix.phpunit }} --dev
45+
composer update --with-all-dependencies
46+
npm install
47+
48+
- name: Test
49+
run: npm test

.travis.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ProcessGraphQL
22

3-
[![Travis-CI Status][travis-ci-badge]][travis-ci]
3+
[![Test Status](https://github.com/dadish/ProcessGraphQL/workflows/Test/badge.svg)](https://github.com/dadish/ProcessGraphQL/actions)
44

55
[GraphQL][graphql] for [ProcessWire][pw].
66

src/Permissions.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
class Permissions
99
{
10-
public const pageAddPermission = 'page-add';
11-
public const pageCreatePermission = 'page-create';
12-
public const pageDeletePermission = 'page-delete';
13-
public const pageEditPermission = 'page-edit';
14-
public const pageMovePermission = 'page-move';
15-
public const pageViewPermission = 'page-view';
16-
public const pageEditCreatedPermission = 'page-edit-created';
17-
public const pageEditTrashCreatedPermission = 'page-edit-trash-created';
10+
public const pageAddPermission = "page-add";
11+
public const pageCreatePermission = "page-create";
12+
public const pageDeletePermission = "page-delete";
13+
public const pageEditPermission = "page-edit";
14+
public const pageMovePermission = "page-move";
15+
public const pageViewPermission = "page-view";
16+
public const pageEditCreatedPermission = "page-edit-created";
17+
public const pageEditTrashCreatedPermission = "page-edit-trash-created";
1818

1919
/**
2020
* Checks if the page using this template can be viewed by the current user.
@@ -60,23 +60,27 @@ public static function canCreate(Template $template)
6060
}
6161

6262
// can't create if allowed parents are not legal
63-
if ($template->noParents == 0 && count($template->parentTemplates)) {
64-
63+
if (!$template->noParents && count($template->parentTemplates)) {
6564
// filter out the parents that has noChildren checked or
6665
// has configured childTemplates without the target template
67-
$parentTemplates = array_filter($template->parentTemplates, function ($templateId) use ($template) {
66+
$parentTemplates = array_filter($template->parentTemplates, function (
67+
$templateId
68+
) use ($template) {
6869
$parentTemplate = Utils::templates()->get($templateId);
6970
if ($parentTemplate->noChildren) {
7071
return false;
7172
}
72-
if (count($parentTemplate->childTemplates) && !in_array($template->id, $parentTemplate->childTemplates)) {
73+
if (
74+
count($parentTemplate->childTemplates) &&
75+
!in_array($template->id, $parentTemplate->childTemplates)
76+
) {
7377
return false;
7478
}
7579
return true;
7680
});
7781

7882
// get templates that user can add pages to
79-
$addTemplates = self::getAddTemplates()->explode('id');
83+
$addTemplates = self::getAddTemplates()->explode("id");
8084
if (!count(array_intersect($addTemplates, $parentTemplates))) {
8185
return false;
8286
}
@@ -219,7 +223,11 @@ public static function canAdd(Template $template)
219223

220224
// can't add a page if the allowed childTemplates are not legal
221225
if ($template->noChildren == 0 && count($template->childTemplates)) {
222-
if (!count(array_intersect(self::getTemplateIds(), $template->childTemplates))) {
226+
if (
227+
!count(
228+
array_intersect(self::getTemplateIds(), $template->childTemplates)
229+
)
230+
) {
223231
return false;
224232
}
225233
}
@@ -251,7 +259,7 @@ public static function canAdd(Template $template)
251259
*/
252260
public static function canEditField(Field $field, Template $template)
253261
{
254-
return self::hasFieldPermission('edit', $field, $template);
262+
return self::hasFieldPermission("edit", $field, $template);
255263
}
256264

257265
/**
@@ -263,7 +271,7 @@ public static function canEditField(Field $field, Template $template)
263271
*/
264272
public static function canViewField(Field $field, Template $template)
265273
{
266-
return self::hasFieldPermission('view', $field, $template);
274+
return self::hasFieldPermission("view", $field, $template);
267275
}
268276

269277
/**
@@ -274,8 +282,11 @@ public static function canViewField(Field $field, Template $template)
274282
* @param Template $template The context of the field.
275283
* @return boolean Returns true if user has rights and false otherwise
276284
*/
277-
public static function hasFieldPermission(string $permission, Field $field, Template $template)
278-
{
285+
public static function hasFieldPermission(
286+
string $permission,
287+
Field $field,
288+
Template $template
289+
) {
279290
$user = Utils::user();
280291

281292
// can view/edit a field if superuser
@@ -289,7 +300,7 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
289300
return false;
290301
}
291302

292-
$roles = $permission . 'Roles';
303+
$roles = $permission . "Roles";
293304

294305
foreach ($user->roles as $role) {
295306
if (in_array($role->id, $field->$roles)) {
@@ -300,7 +311,6 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
300311
return false;
301312
}
302313

303-
304314
/**
305315
* Tells if the template or field has access control defined.
306316
*
@@ -309,7 +319,7 @@ public static function hasFieldPermission(string $permission, Field $field, Temp
309319
*/
310320
public static function definesAccess($context)
311321
{
312-
return (boolean) $context->useRoles;
322+
return (bool) $context->useRoles;
313323
}
314324

315325
/**
@@ -320,7 +330,7 @@ public static function definesAccess($context)
320330
public static function getTemplates()
321331
{
322332
$templates = Utils::templates();
323-
$legalTemplateNames = implode('|', Utils::module()->legalTemplates);
333+
$legalTemplateNames = implode("|", Utils::module()->legalTemplates);
324334
return $templates->find("name=$legalTemplateNames");
325335
}
326336

@@ -331,7 +341,7 @@ public static function getTemplates()
331341
*/
332342
public static function getTemplateIds()
333343
{
334-
return array_merge([], self::getTemplates()->explode('id'));
344+
return array_merge([], self::getTemplates()->explode("id"));
335345
}
336346

337347
public static function filterTemplatesByPermission($predicator)

test/Field/Mutation/CreatePage/CaseTwoTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,25 @@ public function testValue()
3737
$res = self::execute($query, $variables);
3838
$newBuildingSky = Utils::pages()->get("name=$name");
3939
self::assertEquals(
40-
1,
40+
2,
4141
count($res->errors),
42-
"createSkyscraper does not exist if allowed parent page is not legal."
42+
// "createSkyscraper does not exist if allowed parent page is not legal."
43+
"Should have two errors."
44+
);
45+
self::assertStringContainsString(
46+
"SkyscraperCreateInput",
47+
$res->errors[0]->message,
48+
"'SkyscraperCreateInput' type should not exist."
49+
);
50+
self::assertStringContainsString(
51+
"createSkyscraper",
52+
$res->errors[1]->message,
53+
"'createSkyscraper' field should not exist."
4354
);
4455
self::assertInstanceOf(
4556
NullPage::class,
4657
$newBuildingSky,
47-
"createSkyscraper does not create a page."
58+
"'createSkyscraper' does not create a page."
4859
);
4960
}
5061
}

test/Interface/PageTest.php renamed to test/Interfaces/PageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProcessWire\GraphQL\Test\Interface;
3+
namespace ProcessWire\GraphQL\Test\Interfaces;
44

55
/**
66
* It supports page interfaces.

0 commit comments

Comments
 (0)