|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Tests\GraphQL; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\GraphQL\DuplicateElementMutation; |
|
6
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
|
7
|
|
|
use DNADesign\Elemental\Models\ElementalArea; |
|
8
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
9
|
|
|
use InvalidArgumentException; |
|
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
11
|
|
|
use SilverStripe\Security\Security; |
|
12
|
|
|
|
|
13
|
|
|
class DuplicateElementMutationTest extends SapphireTest |
|
14
|
|
|
{ |
|
15
|
|
|
protected function setUp() |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
if (!class_exists(Schema::class)) { |
|
|
|
|
|
|
19
|
|
|
$this->markTestSkipped('Skipped GraphQL 4 test ' . __CLASS__); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testResolvePermissions() |
|
24
|
|
|
{ |
|
25
|
|
|
$cannotEditClass = new class extends BaseElement { |
|
26
|
|
|
public function canEdit($member = null) |
|
27
|
|
|
{ |
|
28
|
|
|
return false; |
|
29
|
|
|
} |
|
30
|
|
|
public function canCreate($member = null, $context = []) |
|
31
|
|
|
{ |
|
32
|
|
|
return true; |
|
33
|
|
|
} |
|
34
|
|
|
}; |
|
35
|
|
|
|
|
36
|
|
|
$cannotCreateClass = new class extends BaseElement { |
|
37
|
|
|
public function canEdit($member = null) |
|
38
|
|
|
{ |
|
39
|
|
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
public function canCreate($member = null, $context = []) |
|
42
|
|
|
{ |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
}; |
|
46
|
|
|
|
|
47
|
|
|
$area = new ElementalArea(); |
|
48
|
|
|
$area->write(); |
|
49
|
|
|
|
|
50
|
|
|
$testCases = [ |
|
51
|
|
|
[$cannotEditClass, 'edit'], |
|
52
|
|
|
[$cannotCreateClass, 'create'], |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
foreach ($testCases as $data) { |
|
56
|
|
|
[$class, $operation] = $data; |
|
57
|
|
|
|
|
58
|
|
|
$element = new $class(); |
|
59
|
|
|
$element->ParentID = $area->ID; |
|
60
|
|
|
$element->write(); |
|
61
|
|
|
$mutation = new DuplicateElementMutation(); |
|
|
|
|
|
|
62
|
|
|
$object = null; |
|
63
|
|
|
$args = ['id' => $element->ID]; |
|
64
|
|
|
$context = ['currentUser' => Security::getCurrentUser()]; |
|
65
|
|
|
$resolveInfo = new ResolveInfo([]); |
|
66
|
|
|
|
|
67
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
68
|
|
|
$this->expectExceptionMessageRegExp("#insufficient permission to {$operation}#"); |
|
69
|
|
|
$mutation->resolve($object, $args, $context, $resolveInfo); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths