1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests for the workflow engine. |
4
|
|
|
* |
5
|
|
|
* @author [email protected] |
6
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
7
|
|
|
* @package advancedworkflow |
8
|
|
|
* @subpackage tests |
9
|
|
|
*/ |
10
|
|
|
class WorkflowInstanceTest extends SapphireTest { |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
public static $fixture_file = 'advancedworkflow/tests/useractioninstancehistory.yml'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* @var Member |
21
|
|
|
*/ |
22
|
|
|
protected $currentMember; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
public function setUp() { |
28
|
|
|
parent::setUp(); |
29
|
|
|
$this->currentMember = $this->objFromFixture('Member', 'ApproverMember01'); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Tests WorkflowInstance#getMostRecentActionForUser() |
34
|
|
|
*/ |
35
|
|
|
public function testGetMostRecentActionForUser() { |
36
|
|
|
|
37
|
|
|
// Single, AssignUsersToWorkflowAction in "History" |
38
|
|
|
$history01 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance01'); |
39
|
|
|
$mostRecentActionForUser01 = $history01->getMostRecentActionForUser($this->currentMember); |
40
|
|
|
$this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser01, 'Asserts the correct ClassName is retured #1'); |
|
|
|
|
41
|
|
|
$this->assertEquals('Assign', $mostRecentActionForUser01->BaseAction()->Title, 'Asserts the correct BaseAction is retured #1'); |
|
|
|
|
42
|
|
|
|
43
|
|
|
// No AssignUsersToWorkflowAction found with Member's related Group in "History" |
44
|
|
|
$history02 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance02'); |
45
|
|
|
$mostRecentActionForUser02 = $history02->getMostRecentActionForUser($this->currentMember); |
46
|
|
|
$this->assertFalse($mostRecentActionForUser02, 'Asserts false is returned because no WorkflowActionInstance was found'); |
|
|
|
|
47
|
|
|
|
48
|
|
|
// Multiple AssignUsersToWorkflowAction in "History", only one with Group relations |
49
|
|
|
$history03 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance03'); |
50
|
|
|
$mostRecentActionForUser03 = $history03->getMostRecentActionForUser($this->currentMember); |
51
|
|
|
$this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser03, 'Asserts the correct ClassName is retured #2'); |
|
|
|
|
52
|
|
|
$this->assertEquals('Assign', $mostRecentActionForUser03->BaseAction()->Title, 'Asserts the correct BaseAction is retured #2'); |
|
|
|
|
53
|
|
|
|
54
|
|
|
// Multiple AssignUsersToWorkflowAction in "History", both with Group relations |
55
|
|
|
$history04 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance04'); |
56
|
|
|
$mostRecentActionForUser04 = $history04->getMostRecentActionForUser($this->currentMember); |
57
|
|
|
$this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser04, 'Asserts the correct ClassName is retured #3'); |
|
|
|
|
58
|
|
|
$this->assertEquals('Assigned Again', $mostRecentActionForUser04->BaseAction()->Title, 'Asserts the correct BaseAction is retured #3'); |
|
|
|
|
59
|
|
|
|
60
|
|
|
// Multiple AssignUsersToWorkflowAction in "History", one with Group relations |
61
|
|
|
$history05 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance05'); |
62
|
|
|
$mostRecentActionForUser05 = $history05->getMostRecentActionForUser($this->currentMember); |
63
|
|
|
$this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser05, 'Asserts the correct ClassName is retured #4'); |
|
|
|
|
64
|
|
|
$this->assertEquals('Assigned Me', $mostRecentActionForUser05->BaseAction()->Title, 'Asserts the correct BaseAction is retured #4'); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests WorkflowInstance#canView() |
69
|
|
|
*/ |
70
|
|
|
public function testCanView() { |
71
|
|
|
// Single, AssignUsersToWorkflowAction in "History" |
72
|
|
|
$history01 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance01'); |
73
|
|
|
$this->assertTrue($history01->canView($this->currentMember)); |
|
|
|
|
74
|
|
|
|
75
|
|
|
// No AssignUsersToWorkflowAction found with Member's related Group in "History" |
76
|
|
|
$history02 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance02'); |
77
|
|
|
$this->assertFalse($history02->canView($this->currentMember)); |
|
|
|
|
78
|
|
|
|
79
|
|
|
// Multiple AssignUsersToWorkflowAction in "History", only one with Group relations |
80
|
|
|
$history03 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance03'); |
81
|
|
|
$this->assertTrue($history03->canView($this->currentMember)); |
|
|
|
|
82
|
|
|
|
83
|
|
|
// Multiple AssignUsersToWorkflowAction in "History", both with Group relations |
84
|
|
|
$history04 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance04'); |
85
|
|
|
$this->assertTrue($history04->canView($this->currentMember)); |
|
|
|
|
86
|
|
|
|
87
|
|
|
// Multiple AssignUsersToWorkflowAction in "History" |
88
|
|
|
$history05 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance05'); |
89
|
|
|
$this->assertTrue($history05->canView($this->currentMember)); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testValidTransitions() { |
93
|
|
|
$instance = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance06'); |
94
|
|
|
$transition1 = $this->objFromFixture('WorkflowTransition', 'Transition05'); |
95
|
|
|
$transition2 = $this->objFromFixture('WorkflowTransition', 'Transition06'); |
96
|
|
|
$member1 = $this->objFromFixture('Member', 'Transition05Member'); |
97
|
|
|
$member2 = $this->objFromFixture('Member', 'Transition06Member'); |
98
|
|
|
|
99
|
|
|
// Given logged in as admin, check that there are two actions |
100
|
|
|
$this->logInWithPermission('ADMIN'); |
101
|
|
|
$transitions = $instance->validTransitions()->column('ID'); |
102
|
|
|
$this->assertContains($transition1->ID, $transitions); |
103
|
|
|
$this->assertContains($transition2->ID, $transitions); |
104
|
|
|
|
105
|
|
|
// Logged in as a member with permission on one transition, check that only this one is present |
106
|
|
|
$member1->logIn(); |
107
|
|
|
$transitions = $instance->validTransitions()->column('ID'); |
108
|
|
|
$this->assertContains($transition1->ID, $transitions); |
109
|
|
|
$this->assertNotContains($transition2->ID, $transitions); |
110
|
|
|
|
111
|
|
|
// Logged in as a member with permissions via group |
112
|
|
|
$member2->logIn(); |
113
|
|
|
$transitions = $instance->validTransitions()->column('ID'); |
114
|
|
|
$this->assertNotContains($transition1->ID, $transitions); |
115
|
|
|
$this->assertContains($transition2->ID, $transitions); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
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.