1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\Uploaders; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; |
6
|
|
|
use Backpack\CRUD\app\Library\Uploaders\SingleBase64Image; |
7
|
|
|
use Backpack\CRUD\app\Library\Uploaders\SingleFile; |
8
|
|
|
use Backpack\CRUD\app\Library\Uploaders\Support\Interfaces\UploaderInterface; |
9
|
|
|
use Backpack\CRUD\Tests\config\CrudPanel\BaseCrudPanel; |
10
|
|
|
use PHPUnit\Framework\Attributes\Group; |
11
|
|
|
|
12
|
|
|
class UploadersInternalsTest extends BaseCrudPanel |
13
|
|
|
{ |
14
|
|
|
protected $uploaderRepository; |
15
|
|
|
|
16
|
|
|
public function setUp(): void |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
$this->uploaderRepository = $this->app->make('UploadersRepository'); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function test_it_registers_default_uploaders() |
23
|
|
|
{ |
24
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'withFiles')); |
25
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('upload', 'withFiles')); |
26
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('upload_multiple', 'withFiles')); |
27
|
|
|
|
28
|
|
|
$this->assertFalse($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function test_it_registers_default_uploaders_classes() |
32
|
|
|
{ |
33
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), UploaderInterface::class, true)); |
34
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload', 'withFiles'), UploaderInterface::class, true)); |
35
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload_multiple', 'withFiles'), UploaderInterface::class, true)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function test_it_throws_exception_if_uploader_or_group_is_not_registered() |
39
|
|
|
{ |
40
|
|
|
$this->expectException(\Exception::class); |
41
|
|
|
|
42
|
|
|
$this->uploaderRepository->getUploadFor('dropzone', 'withFiles'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function test_it_can_add_more_uploaders() |
46
|
|
|
{ |
47
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
48
|
|
|
'dropzone' => SingleFile::class, |
49
|
|
|
], 'withFiles'); |
50
|
|
|
|
51
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
52
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), UploaderInterface::class, true)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function test_it_validates_uploaders_when_adding() |
56
|
|
|
{ |
57
|
|
|
$this->expectException(\Exception::class); |
58
|
|
|
|
59
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
60
|
|
|
'dropzone' => 'InvalidClass', |
61
|
|
|
], 'withFiles'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function test_it_can_replace_defined_uploaders() |
65
|
|
|
{ |
66
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleBase64Image::class, true)); |
67
|
|
|
|
68
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
69
|
|
|
'image' => SingleFile::class, |
70
|
|
|
'dropzone' => SingleFile::class, |
71
|
|
|
], 'withFiles'); |
72
|
|
|
|
73
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
74
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), SingleFile::class, true)); |
75
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleFile::class, true)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function test_it_can_register_uploaders_in_a_new_group() |
79
|
|
|
{ |
80
|
|
|
$this->assertFalse($this->uploaderRepository->hasUploadFor('image', 'newGroup')); |
81
|
|
|
|
82
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
83
|
|
|
'image' => SingleFile::class, |
84
|
|
|
], 'newGroup'); |
85
|
|
|
|
86
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'newGroup')); |
87
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'newGroup'), SingleFile::class, true)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function test_it_can_register_repeatable_uploaders() |
91
|
|
|
{ |
92
|
|
|
CRUD::field('gallery')->subfields([ |
93
|
|
|
[ |
94
|
|
|
'name' => 'image', |
95
|
|
|
'type' => 'image', |
96
|
|
|
'withFiles' => true, |
97
|
|
|
], |
98
|
|
|
]); |
99
|
|
|
|
100
|
|
|
$this->assertTrue($this->uploaderRepository->hasRepeatableUploadersFor('gallery')); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function test_it_throws_exceptio_if_uploader_doesnt_exist() |
104
|
|
|
{ |
105
|
|
|
$this->expectException(\Exception::class); |
106
|
|
|
CRUD::field('upload')->type('custom_type')->withFiles(); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function test_it_validates_a_custom_uploader() |
110
|
|
|
{ |
111
|
|
|
$this->expectException(\Exception::class); |
112
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['uploader' => 'InvalidClass']); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function test_it_sets_the_prefix_on_field() |
116
|
|
|
{ |
117
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['path' => 'test']); |
118
|
|
|
|
119
|
|
|
$this->assertEquals('test/', CRUD::getFields()['upload']['prefix']); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function test_it_sets_the_disk_on_field() |
123
|
|
|
{ |
124
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['disk' => 'test']); |
125
|
|
|
|
126
|
|
|
$this->assertEquals('test', CRUD::getFields()['upload']['disk']); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function test_it_can_set_temporary_options() |
130
|
|
|
{ |
131
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['temporaryUrl' => true]); |
132
|
|
|
|
133
|
|
|
$this->assertTrue(CRUD::getFields()['upload']['temporary']); |
134
|
|
|
$this->assertEquals(1, CRUD::getFields()['upload']['expiration']); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.