-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProcessRequestFileTest.php
More file actions
108 lines (94 loc) · 3.36 KB
/
Copy pathProcessRequestFileTest.php
File metadata and controls
108 lines (94 loc) · 3.36 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
<?php
namespace Tests\Feature\Api;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Testing\File;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Models\Media;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class ProcessRequestFileTest extends TestCase
{
use RequestHelper;
/**
* test process request files index
*/
public function testIndex()
{
//create a request
$process_request = ProcessRequest::factory()->create();
//upload a fake document with id of the request
$fileUpload = File::image('photo.jpg');
//save the file with media lib
$process_request
->addMedia($fileUpload)
->withCustomProperties(['data_name' => 'test'])
->toMediaCollection();
$response = $this->apiCall('GET', '/requests/' . $process_request->id . '/files');
$response->assertStatus(200);
$this->assertEquals($response->json()['data'][0]['file_name'], 'photo.jpg');
}
/**
* Test file upload associated with a process request id
*/
public function testFileUploadWithProcessRequestID()
{
//create a request
$process_request = ProcessRequest::factory()->create();
//post photo id with the request
$response = $this->apiCall('POST', '/requests/' . $process_request->id . '/files', [
'file' => File::image('photo.jpg'),
'data_name' => 'photo',
]);
$response->assertStatus(200);
$this->assertEquals($process_request->getMedia()[0]->file_name, 'photo.jpg');
}
/**
* test delete of Media attached to a request
*/
public function testDeleteFile()
{
//create a request
$process_request = ProcessRequest::factory()->create();
// upload file
$fileUpload = File::image('HEEEEy.jpg');
$process_request
->addMedia($fileUpload)
->withCustomProperties(['data_name' => 'test'])
->toMediaCollection();
//delete the file
$process_request->refresh();
$process_request->getMedia()[0]->delete();
$process_request->refresh();
//confirm the file was deleted
$this->assertEquals($process_request->getMedia()->count(), 0);
}
/**
* test get a single file for a process by id
*/
public function testShow()
{
//create a request
$process_request = ProcessRequest::factory()->create();
//upload a fake document with id of the request
$fileUpload1 = File::image('photo1.jpg');
$fileUpload2 = File::image('photo2.jpg');
//save the file with media lib
$file1 = $process_request
->addMedia($fileUpload1)
->withCustomProperties(['data_name' => 'test'])
->toMediaCollection();
$file2 = $process_request
->addMedia($fileUpload2)
->withCustomProperties(['data_name' => 'test'])
->toMediaCollection();
$response = $this->apiCall('GET', '/requests/' . $process_request->id . '/files/' . $file2->id);
$response->assertStatus(200);
$this->assertEquals(
'attachment; filename=photo2.jpg',
$response->headers->get('content-disposition')
);
}
}