-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathSignalEventTest.php
More file actions
139 lines (111 loc) · 5.21 KB
/
Copy pathSignalEventTest.php
File metadata and controls
139 lines (111 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Tests\Feature\Api;
use Illuminate\Support\Facades\Bus;
use ProcessMaker\Facades\WorkflowManager;
use ProcessMaker\Jobs\CatchSignalEventProcess;
use ProcessMaker\Jobs\ImportProcess;
use ProcessMaker\Jobs\RefreshArtisanCaches;
use ProcessMaker\Jobs\StartEvent;
use ProcessMaker\Jobs\ThrowSignalEvent;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use Tests\TestCase;
class SignalEventTest extends TestCase
{
public function testSignalEventMustTriggeredWhenProcessActive()
{
Bus::fake([
RefreshArtisanCaches::class,
CatchSignalEventProcess::class,
]);
//Create a signal process that TRIGGER a signal with ACTIVE status by default
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_event_process_trigger.json')
);
//Get created TRIGGER process
$triggerProcess = Process::orderBy('id', 'desc')->first();
//Get excluded process
$excludedProcess = $triggerProcess->id;
//Get signalRef
$signalRef = $triggerProcess->signal_events[0];
//Create a signal process that CATCH a signal with ACTIVE status by default
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_event_process_catcher.json')
);
$throwSignalEventJob = new ThrowSignalEvent($signalRef, [], [$excludedProcess], []);
$throwSignalEventJob->handle();
//Evaluates that CatchSignalEventProcess is triggering because catcher process is ACTIVE
Bus::assertDispatched(CatchSignalEventProcess::class);
}
public function testSignalEventMustNotTriggeredWhenProcessInactive()
{
Bus::fake([
RefreshArtisanCaches::class,
CatchSignalEventProcess::class,
]);
//Create a signal process that TRIGGER a signal with ACTIVE status by default
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_event_process_trigger.json')
);
//Get created TRIGGER process
$triggerProcess = Process::orderBy('id', 'desc')->first();
//Get excluded process
$excludedProcess = $triggerProcess->id;
//Get signalRef
$signalRef = $triggerProcess->signal_events[0];
//Create a signal process that CATCH a signal with ACTIVE status by default
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_event_process_catcher.json')
);
//Get created CATCHER process
$catcherProcess = Process::orderBy('id', 'desc')->first();
//Change it's status to INACTIVE
$catcherProcess->status = 'INACTIVE';
$catcherProcess->save();
$throwSignalEventJob = new ThrowSignalEvent($signalRef, [], [$excludedProcess], []);
$throwSignalEventJob->handle();
//Evaluates that CatchSignalEventProcess is NOT triggering because catcher process is INACTIVE
Bus::assertNotDispatched(CatchSignalEventProcess::class);
}
/**
* This test verifies that in a signal start event with the "Request Variable" configured,
* every attribute of the signal payload goes to the request
* if payload={var1:1, var2:2} and request data {req1:'a', req2:'b'}
* request data should be {req1:'a', req2:'b'... request_var:{var1:1, var2:2}}
*/
public function testSignalStarEventWithPayloadToRequestVariable()
{
// The process used for the tests
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_catch_with_payload.json')
);
// Payload for all the signals in the test
$payload = ['payload1' => 1, 'payload2' => 2];
// Dispatch the job synchronously for the test (signal 3 triggers the "Payload in variable" start event)
ThrowSignalEvent::dispatchSync('Signal3', $payload, []);
// Verify that the created request has the payload stored in the request variable "incoming_data"
$createdRequestData = ProcessRequest::all()->first()->data;
$this->assertEquals($createdRequestData['incoming_data'], $payload);
}
/**
* This test verifies that in a signal start event with "Request Variable" empty,
* every attribute of the signal payload goes to the request
* if payload={var1:1, var2:2} and request data {req1:'a', req2:'b'}
* request data should be {req1:'a', req2:'b'... var1:1, var2:2}
*/
public function testSignalStarEventWithPayloadToRequestData()
{
// The process used for the tests
ImportProcess::dispatchSync(
file_get_contents(__DIR__ . '/../../Fixtures/signal_catch_with_payload.json')
);
// Payload for all the signals in the test
$payload = ['payload1' => 1, 'payload2' => 2];
// Dispatch the job synchronously for the test
ThrowSignalEvent::dispatchSync('Signal4', $payload, []);
// Verify that the created request has the payload stored in the request variable "incoming_data"
$createdRequestData = ProcessRequest::all()->first()->data;
$this->assertArraySubset($payload, $createdRequestData);
}
}