1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symbiote\AdvancedWorkflow\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests for permissions on all Workflow Objects. |
10
|
|
|
* These will obviousely need to be modified should additional workflow permissions come online. |
11
|
|
|
* |
12
|
|
|
* @author [email protected] |
13
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
14
|
|
|
* @package advancedworkflow |
15
|
|
|
* @subpackage tests |
16
|
|
|
*/ |
17
|
|
|
class WorkflowPermissionsTest extends SapphireTest |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected static $fixture_file = 'workflowpermissions.yml'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowDefinitions |
26
|
|
|
*/ |
27
|
|
|
public function testWorkflowDefinitionCanPerms() |
28
|
|
|
{ |
29
|
|
|
// Very limited perms. No create. |
30
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
31
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'no-actions'); |
32
|
|
|
$this->assertFalse($workflowdef->canCreate()); |
33
|
|
|
|
34
|
|
|
// Limited perms. No create. |
35
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
36
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'no-actions'); |
37
|
|
|
$this->assertFalse($workflowdef->canCreate()); |
38
|
|
|
|
39
|
|
|
// Has perms. Can create. |
40
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
41
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'no-actions'); |
42
|
|
|
$this->assertTrue($workflowdef->canCreate()); |
43
|
|
|
|
44
|
|
|
// Limited perms. No delete |
45
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
46
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'no-actions'); |
47
|
|
|
$this->assertFalse($workflowdef->canDelete()); |
48
|
|
|
|
49
|
|
|
// Has perms. No delete |
50
|
|
|
$this->logInWithPermission('DELETE_WORKFLOW'); |
51
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'no-actions'); |
52
|
|
|
$this->assertTrue($workflowdef->canDelete()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowActions |
57
|
|
|
*/ |
58
|
|
|
public function testWorkflowActionCanPerms() |
59
|
|
|
{ |
60
|
|
|
// Very limited perms. No create. |
61
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
62
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions'); |
63
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
64
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canEdit()); |
|
|
|
|
65
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
66
|
|
|
|
67
|
|
|
// Limited perms. No create or delete. |
68
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
69
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions'); |
70
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
71
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
72
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
73
|
|
|
|
74
|
|
|
// Has perms. Can create. |
75
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
76
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions'); |
77
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
78
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->canEdit()); |
|
|
|
|
79
|
|
|
|
80
|
|
|
// Limited perms. No Delete |
81
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowActions |
86
|
|
|
*/ |
87
|
|
|
public function testWorkflowTransitionPerms() |
88
|
|
|
{ |
89
|
|
|
// Very limited perms. No create. |
90
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
91
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions-and-transitions'); |
92
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
93
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
94
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
95
|
|
|
|
96
|
|
|
// Limited perms. No create. |
97
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
98
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions-and-transitions'); |
99
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
100
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
101
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
102
|
|
|
|
103
|
|
|
// Has perms. Can create. |
104
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
105
|
|
|
$workflowdef = $this->objFromFixture(WorkflowDefinition::class, 'with-actions-and-transitions'); |
106
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
107
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
108
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.