1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests for permissions on all Workflow Objects. |
4
|
|
|
* These will obviousely need to be modified should additional workflow permissions come online. |
5
|
|
|
* |
6
|
|
|
* @author [email protected] |
7
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
8
|
|
|
* @package advancedworkflow |
9
|
|
|
* @subpackage tests |
10
|
|
|
*/ |
11
|
|
|
class WorkflowPermissionsTest extends SapphireTest { |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
public static $fixture_file = 'advancedworkflow/tests/workflowpermissions.yml'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowDefinitions |
20
|
|
|
*/ |
21
|
|
|
public function testWorkflowDefinitionCanPerms() { |
22
|
|
|
// Very limited perms. No create. |
23
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
24
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'no-actions'); |
25
|
|
|
$this->assertFalse($workflowdef->canCreate()); |
|
|
|
|
26
|
|
|
|
27
|
|
|
// Limited perms. No create. |
28
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
29
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'no-actions'); |
30
|
|
|
$this->assertFalse($workflowdef->canCreate()); |
|
|
|
|
31
|
|
|
|
32
|
|
|
// Has perms. Can create. |
33
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
34
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'no-actions'); |
35
|
|
|
$this->assertTrue($workflowdef->canCreate()); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Limited perms. No delete |
38
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
39
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'no-actions'); |
40
|
|
|
$this->assertFalse($workflowdef->canDelete()); |
|
|
|
|
41
|
|
|
|
42
|
|
|
// Has perms. No delete |
43
|
|
|
$this->logInWithPermission('DELETE_WORKFLOW'); |
44
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'no-actions'); |
45
|
|
|
$this->assertTrue($workflowdef->canDelete()); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowActions |
50
|
|
|
*/ |
51
|
|
|
public function testWorkflowActionCanPerms() { |
52
|
|
|
// Very limited perms. No create. |
53
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
54
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions'); |
55
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
56
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canEdit()); |
|
|
|
|
57
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// Limited perms. No create or delete. |
60
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
61
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions'); |
62
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
63
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
64
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
65
|
|
|
|
66
|
|
|
// Has perms. Can create. |
67
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
68
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions'); |
69
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->canCreate()); |
|
|
|
|
70
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->canEdit()); |
|
|
|
|
71
|
|
|
|
72
|
|
|
// Limited perms. No Delete |
73
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->canDelete()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Tests whether members with differing permissions, should be able to create & edit WorkflowActions |
78
|
|
|
*/ |
79
|
|
|
public function testWorkflowTransitionPerms() { |
80
|
|
|
// Very limited perms. No create. |
81
|
|
|
$this->logInWithPermission('CMS_ACCESS_AdvancedWorkflowAdmin'); |
82
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions-and-transitions'); |
83
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
84
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
85
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
86
|
|
|
|
87
|
|
|
// Limited perms. No create. |
88
|
|
|
$this->logInWithPermission('VIEW_ACTIVE_WORKFLOWS'); |
89
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions-and-transitions'); |
90
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
91
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
92
|
|
|
$this->assertFalse($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
93
|
|
|
|
94
|
|
|
// Has perms. Can create. |
95
|
|
|
$this->logInWithPermission('CREATE_WORKFLOW'); |
96
|
|
|
$workflowdef = $this->objFromFixture('WorkflowDefinition', 'with-actions-and-transitions'); |
97
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canCreate()); |
|
|
|
|
98
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canEdit()); |
|
|
|
|
99
|
|
|
$this->assertTrue($workflowdef->Actions()->first()->Transitions()->first()->canDelete()); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.