|
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
|
|
|
|
|
11
|
|
|
class UploadersInternalsTest extends BaseCrudPanel |
|
12
|
|
|
{ |
|
13
|
|
|
protected $uploaderRepository; |
|
14
|
|
|
|
|
15
|
|
|
public function setUp(): void |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
$this->uploaderRepository = $this->app->make('UploadersRepository'); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function test_it_registers_default_uploaders() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'withFiles')); |
|
24
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('upload', 'withFiles')); |
|
25
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('upload_multiple', 'withFiles')); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertFalse($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function test_it_registers_default_uploaders_classes() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), UploaderInterface::class, true)); |
|
33
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload', 'withFiles'), UploaderInterface::class, true)); |
|
34
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('upload_multiple', 'withFiles'), UploaderInterface::class, true)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function test_it_throws_exception_if_uploader_or_group_is_not_registered() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->expectException(\Exception::class); |
|
40
|
|
|
|
|
41
|
|
|
$this->uploaderRepository->getUploadFor('dropzone', 'withFiles'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_it_can_add_more_uploaders() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
|
47
|
|
|
'dropzone' => SingleFile::class, |
|
48
|
|
|
], 'withFiles'); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
|
51
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), UploaderInterface::class, true)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function test_it_validates_uploaders_when_adding() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->expectException(\Exception::class); |
|
57
|
|
|
|
|
58
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
|
59
|
|
|
'dropzone' => 'InvalidClass', |
|
60
|
|
|
], 'withFiles'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function test_it_can_replace_defined_uploaders() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleBase64Image::class, true)); |
|
66
|
|
|
|
|
67
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
|
68
|
|
|
'image' => SingleFile::class, |
|
69
|
|
|
'dropzone' => SingleFile::class, |
|
70
|
|
|
], 'withFiles'); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('dropzone', 'withFiles')); |
|
73
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('dropzone', 'withFiles'), SingleFile::class, true)); |
|
74
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'withFiles'), SingleFile::class, true)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function test_it_can_register_uploaders_in_a_new_group() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->assertFalse($this->uploaderRepository->hasUploadFor('image', 'newGroup')); |
|
80
|
|
|
|
|
81
|
|
|
$this->uploaderRepository->addUploaderClasses([ |
|
82
|
|
|
'image' => SingleFile::class, |
|
83
|
|
|
], 'newGroup'); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertTrue($this->uploaderRepository->hasUploadFor('image', 'newGroup')); |
|
86
|
|
|
$this->assertTrue(is_a($this->uploaderRepository->getUploadFor('image', 'newGroup'), SingleFile::class, true)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function test_it_can_register_repeatable_uploaders() |
|
90
|
|
|
{ |
|
91
|
|
|
CRUD::field('gallery')->subfields([ |
|
92
|
|
|
[ |
|
93
|
|
|
'name' => 'image', |
|
94
|
|
|
'type' => 'image', |
|
95
|
|
|
'withFiles' => true, |
|
96
|
|
|
], |
|
97
|
|
|
]); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertTrue($this->uploaderRepository->hasRepeatableUploadersFor('gallery')); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function test_it_throws_exceptio_if_uploader_doesnt_exist() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->expectException(\Exception::class); |
|
105
|
|
|
CRUD::field('upload')->type('custom_type')->withFiles(); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function test_it_validates_a_custom_uploader() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->expectException(\Exception::class); |
|
111
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['uploader' => 'InvalidClass']); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function test_it_sets_the_prefix_on_field() |
|
115
|
|
|
{ |
|
116
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['path' => 'test']); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals('test/', CRUD::getFields()['upload']['prefix']); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function test_it_sets_the_disk_on_field() |
|
122
|
|
|
{ |
|
123
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['disk' => 'test']); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertEquals('test', CRUD::getFields()['upload']['disk']); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function test_it_can_set_temporary_options() |
|
129
|
|
|
{ |
|
130
|
|
|
CRUD::field('upload')->type('upload')->withFiles(['temporaryUrl' => true]); |
|
131
|
|
|
|
|
132
|
|
|
$this->assertTrue(CRUD::getFields()['upload']['temporary']); |
|
133
|
|
|
$this->assertEquals(1, CRUD::getFields()['upload']['expiration']); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
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.