|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\AssetAdmin\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use FunctionalTest; |
|
6
|
|
|
use Versioned; |
|
7
|
|
|
use File; |
|
8
|
|
|
use Folder; |
|
9
|
|
|
use AssetStoreTest_SpyStore; |
|
10
|
|
|
use SecurityToken; |
|
11
|
|
|
use Director; |
|
12
|
|
|
use Injector; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Tests {@see AssetAdmin} |
|
17
|
|
|
*/ |
|
18
|
|
|
class AssetAdminTest extends FunctionalTest |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
protected static $fixture_file = 'AssetAdminTest.yml'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Session |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $session = null; |
|
27
|
|
|
|
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
|
|
32
|
|
|
AssetStoreTest_SpyStore::activate('AssetAdminTest'); |
|
33
|
|
|
$memberID = $this->logInWithPermission('ADMIN'); |
|
34
|
|
|
$this->session = Injector::inst()->create('Session', array('loggedInAs' => $memberID)); |
|
35
|
|
|
|
|
36
|
|
|
// Create a test folders for each of the fixture references |
|
37
|
|
|
foreach (File::get()->filter('ClassName', 'Folder') as $folder) { |
|
38
|
|
|
/** @var Folder $folder */ |
|
39
|
|
|
$folder->publish(Versioned::DRAFT, Versioned::LIVE); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// Create a test files for each of the fixture references |
|
43
|
|
|
$content = str_repeat('x', 1000000); |
|
44
|
|
|
foreach (File::get()->exclude('ClassName', 'Folder') as $file) { |
|
45
|
|
|
/** @var File $file */ |
|
46
|
|
|
$file->setFromString($content, $file->generateFilename()); |
|
47
|
|
|
$file->publish(Versioned::DRAFT, Versioned::LIVE); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Override FunctionalTest defaults |
|
51
|
|
|
SecurityToken::enable(); |
|
52
|
|
|
$this->session->inst_set('SecurityID', SecurityToken::inst()->getValue()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function tearDown() |
|
56
|
|
|
{ |
|
57
|
|
|
AssetStoreTest_SpyStore::reset(); |
|
58
|
|
|
parent::tearDown(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testItCreatesFolder() |
|
62
|
|
|
{ |
|
63
|
|
|
$folder1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', 'folder1'); |
|
64
|
|
|
|
|
65
|
|
|
$response = Director::test( |
|
66
|
|
|
'admin/assets/api/createFolder', |
|
67
|
|
|
[ |
|
68
|
|
|
'ParentID' => $folder1->ID, |
|
69
|
|
|
'Name' => 'testItCreatesFolder', |
|
70
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
71
|
|
|
], |
|
72
|
|
|
$this->session, |
|
73
|
|
|
'POST' |
|
74
|
|
|
); |
|
75
|
|
|
$this->assertFalse($response->isError()); |
|
76
|
|
|
$responseData = json_decode($response->getBody(), true); |
|
77
|
|
|
$newFolder = \Folder::get()->byID($responseData['ID']); |
|
78
|
|
|
$this->assertNotNull($newFolder); |
|
79
|
|
|
$this->assertEquals($folder1->ID, $newFolder->ParentID); |
|
80
|
|
|
$this->assertEquals('testItCreatesFolder', $newFolder->Name); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
public function testItRestrictsCreateFolderByCanCreate() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$folder = $this->objFromFixture( |
|
86
|
|
|
'SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', |
|
87
|
|
|
'disallowCanCreate' |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$response = Director::test( |
|
91
|
|
|
'admin/assets/api/createFolder', |
|
92
|
|
|
[ |
|
93
|
|
|
'ParentID' => $folder->ID, |
|
94
|
|
|
'Name' => 'testItRestrictsCreateFolderByCanCreate', |
|
95
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
96
|
|
|
], |
|
97
|
|
|
$this->session, |
|
98
|
|
|
'POST' |
|
99
|
|
|
); |
|
100
|
|
|
$this->assertTrue($response->isError()); |
|
101
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
public function testItRestrictsCreateFolderByCanAddChildren() |
|
|
|
|
|
|
105
|
|
|
{ |
|
106
|
|
|
$folder = $this->objFromFixture( |
|
107
|
|
|
'SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', |
|
108
|
|
|
'disallowCanAddChildren' |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$response = Director::test( |
|
112
|
|
|
'admin/assets/api/createFolder', |
|
113
|
|
|
[ |
|
114
|
|
|
'ParentID' => $folder->ID, |
|
115
|
|
|
'Name' => 'testItRestrictsCreateFolderByCanAddChildren', |
|
116
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
117
|
|
|
], |
|
118
|
|
|
$this->session, |
|
119
|
|
|
'POST' |
|
120
|
|
|
); |
|
121
|
|
|
$this->assertTrue($response->isError()); |
|
122
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testItCreatesFile() |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$folder1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', 'folder1'); |
|
128
|
|
|
|
|
129
|
|
|
$fileData = array('Upload' => $this->getUploadFile('Upload', 'testItCreatesFile.txt')); |
|
130
|
|
|
$_FILES = $fileData; |
|
131
|
|
|
$response = Director::test( |
|
132
|
|
|
'admin/assets/api/createFile', |
|
133
|
|
|
array_merge( |
|
134
|
|
|
$fileData, |
|
135
|
|
|
[ |
|
136
|
|
|
'ParentID' => $folder1->ID, |
|
137
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
138
|
|
|
] |
|
139
|
|
|
), |
|
140
|
|
|
$this->session, |
|
141
|
|
|
'POST' |
|
142
|
|
|
); |
|
143
|
|
|
$this->assertFalse($response->isError()); |
|
144
|
|
|
$responseData = json_decode($response->getBody(), true); |
|
145
|
|
|
$newFile = \File::get()->byID($responseData[0]['id']); |
|
146
|
|
|
$this->assertNotNull($newFile); |
|
147
|
|
|
$this->assertEquals($folder1->ID, $newFile->ParentID); |
|
148
|
|
|
$this->assertEquals('testItCreatesFile.txt', $newFile->Name); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
View Code Duplication |
public function testItRestrictsCreateFileOnCanCreate() |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
$folder = $this->objFromFixture( |
|
154
|
|
|
'SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', |
|
155
|
|
|
'disallowCanCreate' |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
$fileData = array('Upload' => $this->getUploadFile('Upload', 'test.txt')); |
|
159
|
|
|
$_FILES = $fileData; |
|
160
|
|
|
$response = Director::test( |
|
161
|
|
|
'admin/assets/api/createFile', |
|
162
|
|
|
array_merge( |
|
163
|
|
|
$fileData, |
|
164
|
|
|
[ |
|
165
|
|
|
'ParentID' => $folder->ID, |
|
166
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
167
|
|
|
] |
|
168
|
|
|
), |
|
169
|
|
|
$this->session, |
|
170
|
|
|
'POST' |
|
171
|
|
|
); |
|
172
|
|
|
$this->assertTrue($response->isError()); |
|
173
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
View Code Duplication |
public function testItRestrictsCreateFileOnCanAddChildren() |
|
|
|
|
|
|
177
|
|
|
{ |
|
178
|
|
|
$folder = $this->objFromFixture( |
|
179
|
|
|
'SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', |
|
180
|
|
|
'disallowCanAddChildren' |
|
181
|
|
|
); |
|
182
|
|
|
|
|
183
|
|
|
$fileData = array('Upload' => $this->getUploadFile('Upload', 'test.txt')); |
|
184
|
|
|
$_FILES = $fileData; |
|
185
|
|
|
$response = Director::test( |
|
186
|
|
|
'admin/assets/api/createFile', |
|
187
|
|
|
array_merge( |
|
188
|
|
|
$fileData, |
|
189
|
|
|
[ |
|
190
|
|
|
'ParentID' => $folder->ID, |
|
191
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
192
|
|
|
] |
|
193
|
|
|
), |
|
194
|
|
|
$this->session, |
|
195
|
|
|
'POST' |
|
196
|
|
|
); |
|
197
|
|
|
$this->assertTrue($response->isError()); |
|
198
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function testItRestrictsCreateFileOnExtension() |
|
|
|
|
|
|
202
|
|
|
{ |
|
203
|
|
|
$folder1 = $this->objFromFixture( |
|
204
|
|
|
'SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', |
|
205
|
|
|
'folder1' |
|
206
|
|
|
); |
|
207
|
|
|
|
|
208
|
|
|
$fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowed.php')); |
|
209
|
|
|
$_FILES = $fileData; |
|
210
|
|
|
$response = Director::test( |
|
211
|
|
|
'admin/assets/api/createFile', |
|
212
|
|
|
array_merge( |
|
213
|
|
|
$fileData, |
|
214
|
|
|
[ |
|
215
|
|
|
'ParentID' => $folder1->ID, |
|
216
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
217
|
|
|
] |
|
218
|
|
|
), |
|
219
|
|
|
$this->session, |
|
220
|
|
|
'POST' |
|
221
|
|
|
); |
|
222
|
|
|
$this->assertTrue($response->isError()); |
|
223
|
|
|
$this->assertEquals(400, $response->getStatusCode()); |
|
224
|
|
|
$responseData = json_decode($response->getBody(), true); |
|
225
|
|
|
$this->assertContains( |
|
226
|
|
|
'Extension is not allowed', |
|
227
|
|
|
$responseData['error'][0] |
|
228
|
|
|
); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
public function testItFiltersByDateInSearch() |
|
232
|
|
|
{ |
|
233
|
|
|
$file1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
234
|
|
|
$file2 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file2'); |
|
235
|
|
|
|
|
236
|
|
|
// Force creation times |
|
237
|
|
|
$file1->Created = '2014-01-05 23:11:39'; |
|
238
|
|
|
$file1->write(); |
|
239
|
|
|
$file2->Created = '2014-01-06 12:00:00'; |
|
240
|
|
|
$file2->write(); |
|
241
|
|
|
|
|
242
|
|
|
// Mock searches for 4th Jan |
|
243
|
|
|
$results = $this->getResultsForSearch([ |
|
244
|
|
|
'CreatedFrom' => '2014-01-04', |
|
245
|
|
|
'CreatedTo' => '2014-01-04' |
|
246
|
|
|
]); |
|
247
|
|
|
$this->assertEquals(count($results['files']), 0); |
|
248
|
|
|
|
|
249
|
|
|
// Mock searches for 5th Jan |
|
250
|
|
|
$results = $this->getResultsForSearch([ |
|
251
|
|
|
'CreatedFrom' => '2014-01-05', |
|
252
|
|
|
'CreatedTo' => '2014-01-05' |
|
253
|
|
|
]); |
|
254
|
|
|
$this->assertEquals(count($results['files']), 1); |
|
255
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id')); |
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
// Mock searches for 5th-6th Jan |
|
259
|
|
|
$results = $this->getResultsForSearch([ |
|
260
|
|
|
'CreatedFrom' => '2014-01-05', |
|
261
|
|
|
'CreatedTo' => '2014-01-06' |
|
262
|
|
|
]); |
|
263
|
|
|
$this->assertEquals(count($results['files']), 2); |
|
264
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id')); |
|
265
|
|
|
$this->assertContains($file2->ID, array_column($results['files'], 'id')); |
|
266
|
|
|
|
|
267
|
|
|
// Mock searches for 6th Jan |
|
268
|
|
|
$results = $this->getResultsForSearch([ |
|
269
|
|
|
'CreatedFrom' => '2014-01-06', |
|
270
|
|
|
'CreatedTo' => '2014-01-06' |
|
271
|
|
|
]); |
|
272
|
|
|
$this->assertEquals(count($results['files']), 1); |
|
273
|
|
|
$this->assertContains($file2->ID, array_column($results['files'], 'id')); |
|
274
|
|
|
|
|
275
|
|
|
// Mock searches for 7th Jan |
|
276
|
|
|
$results = $this->getResultsForSearch([ |
|
277
|
|
|
'CreatedFrom' => '2014-01-07', |
|
278
|
|
|
'CreatedTo' => '2014-01-07' |
|
279
|
|
|
]); |
|
280
|
|
|
$this->assertEquals(count($results['files']), 0); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
public function testItDoesNotFilterByDefaultInSearch() |
|
285
|
|
|
{ |
|
286
|
|
|
$rootfile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'rootfile'); |
|
287
|
|
|
$file1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
288
|
|
|
$folder1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', 'folder1'); |
|
289
|
|
|
|
|
290
|
|
|
$results = $this->getResultsForSearch(); |
|
291
|
|
|
$this->assertContains($rootfile->ID, array_column($results['files'], 'id'), |
|
292
|
|
|
'Contains top level file' |
|
293
|
|
|
); |
|
294
|
|
|
$this->assertContains($folder1->ID, array_column($results['files'], 'id'), |
|
295
|
|
|
'Contains top level folder' |
|
296
|
|
|
); |
|
297
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id'), |
|
298
|
|
|
'Contains files in subfolder' |
|
299
|
|
|
); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
public function testItFiltersByParentInSearch() |
|
303
|
|
|
{ |
|
304
|
|
|
$file1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
305
|
|
|
$file2 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file2'); |
|
306
|
|
|
$file1Folder = $file1->Parent(); |
|
|
|
|
|
|
307
|
|
|
$file2Folder = $file2->Parent(); |
|
|
|
|
|
|
308
|
|
|
|
|
309
|
|
|
$results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file1Folder->ID]); |
|
310
|
|
|
$this->assertEquals(count($results['files']), 1); |
|
311
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id'), |
|
312
|
|
|
'Returns file when contained in correct folder' |
|
313
|
|
|
); |
|
314
|
|
|
|
|
315
|
|
|
$results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file2Folder->ID]); |
|
316
|
|
|
$this->assertEquals(count($results['files']), 0, |
|
317
|
|
|
'Does not return file when contained in different folder' |
|
318
|
|
|
); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
public function testItFiltersByNameInSearch() |
|
322
|
|
|
{ |
|
323
|
|
|
$file1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
324
|
|
|
|
|
325
|
|
|
$results = $this->getResultsForSearch(['Name' => $file1->Name]); |
|
326
|
|
|
$this->assertEquals(count($results['files']), 1, |
|
327
|
|
|
'Finds by Name property' |
|
328
|
|
|
); |
|
329
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id')); |
|
330
|
|
|
|
|
331
|
|
|
$results = $this->getResultsForSearch(['Name' => 'First']); |
|
332
|
|
|
$this->assertEquals(count($results['files']), 1, |
|
333
|
|
|
'Finds by Title property' |
|
334
|
|
|
); |
|
335
|
|
|
$this->assertContains($file1->ID, array_column($results['files'], 'id')); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
public function testItRestrictsViewInSearch() |
|
339
|
|
|
{ |
|
340
|
|
|
$allowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
341
|
|
|
$disallowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'disallowCanView'); |
|
342
|
|
|
|
|
343
|
|
|
$results = $this->getResultsForSearch(['Name' => $allowedFile->Name]); |
|
344
|
|
|
$this->assertEquals(count($results['files']), 1); |
|
345
|
|
|
$this->assertContains($allowedFile->ID, array_column($results['files'], 'id')); |
|
346
|
|
|
|
|
347
|
|
|
$results = $this->getResultsForSearch(['Name' => $disallowedFile->Name]); |
|
348
|
|
|
$this->assertEquals(count($results['files']), 0); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
public function testItRestrictsViewInReadFolder() |
|
352
|
|
|
{ |
|
353
|
|
|
$folder1 = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_Folder', 'folder1'); |
|
354
|
|
|
$allowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
355
|
|
|
$disallowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'disallowCanView'); |
|
356
|
|
|
|
|
357
|
|
|
$response = $this->get('admin/assets/api/readFolder?' . http_build_query(['id' => $folder1->ID])); |
|
358
|
|
|
$files = json_decode($response->getBody(), true); |
|
359
|
|
|
$this->assertArrayHasKey('files', $files); |
|
360
|
|
|
$ids = array_map(function ($file) { |
|
361
|
|
|
return $file['id']; |
|
362
|
|
|
}, $files['files']); |
|
363
|
|
|
$this->assertContains($allowedFile->ID, $ids); |
|
364
|
|
|
$this->assertEquals($allowedFile->ParentID, $folder1->ID); |
|
365
|
|
|
$this->assertNotContains($disallowedFile->ID, $ids); |
|
366
|
|
|
$this->assertEquals($disallowedFile->ParentID, $folder1->ID); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
public function testItRestrictsUpdateFile() |
|
370
|
|
|
{ |
|
371
|
|
|
$allowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
372
|
|
|
$disallowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'disallowCanEdit'); |
|
373
|
|
|
|
|
374
|
|
|
$response = Director::test( |
|
375
|
|
|
'admin/assets/api/updateFile', |
|
376
|
|
|
null, |
|
377
|
|
|
$this->session, |
|
378
|
|
|
'PUT', |
|
379
|
|
|
http_build_query([ |
|
380
|
|
|
'id' => $allowedFile->ID, |
|
381
|
|
|
'title' => 'new', |
|
382
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
383
|
|
|
]) |
|
384
|
|
|
); |
|
385
|
|
|
$this->assertFalse($response->isError()); |
|
386
|
|
|
|
|
387
|
|
|
$response = Director::test( |
|
388
|
|
|
'admin/assets/api/updateFile', |
|
389
|
|
|
null, |
|
390
|
|
|
$this->session, |
|
391
|
|
|
'PUT', |
|
392
|
|
|
http_build_query([ |
|
393
|
|
|
'id' => $disallowedFile->ID, |
|
394
|
|
|
'title' => 'new', |
|
395
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
396
|
|
|
]) |
|
397
|
|
|
); |
|
398
|
|
|
$this->assertTrue($response->isError()); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
public function testItRestrictsDelete() |
|
402
|
|
|
{ |
|
403
|
|
|
$allowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', 'file1'); |
|
404
|
|
|
$disallowedFile = $this->objFromFixture('SilverStripe\AssetAdmin\Tests\AssetAdminTest_File', |
|
405
|
|
|
'disallowCanDelete'); |
|
406
|
|
|
|
|
407
|
|
|
$response = Director::test( |
|
408
|
|
|
'admin/assets/api/delete', |
|
409
|
|
|
null, |
|
410
|
|
|
$this->session, |
|
411
|
|
|
'DELETE', |
|
412
|
|
|
http_build_query([ |
|
413
|
|
|
'ids' => [$allowedFile->ID, $disallowedFile->ID], |
|
414
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
415
|
|
|
]) |
|
416
|
|
|
); |
|
417
|
|
|
$this->assertTrue($response->isError()); |
|
418
|
|
|
|
|
419
|
|
|
$response = Director::test( |
|
420
|
|
|
'admin/assets/api/delete', |
|
421
|
|
|
null, |
|
422
|
|
|
$this->session, |
|
423
|
|
|
'DELETE', |
|
424
|
|
|
http_build_query([ |
|
425
|
|
|
'ids' => [$allowedFile->ID], |
|
426
|
|
|
'SecurityID' => SecurityToken::inst()->getValue(), |
|
427
|
|
|
]) |
|
428
|
|
|
); |
|
429
|
|
|
$this->assertFalse($response->isError()); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* @param array $params |
|
434
|
|
|
* @return array |
|
435
|
|
|
*/ |
|
436
|
|
|
protected function getResultsForSearch($params = array()) |
|
437
|
|
|
{ |
|
438
|
|
|
$response = $this->get('admin/assets/api/search?' . http_build_query($params)); |
|
439
|
|
|
$this->assertFalse($response->isError()); |
|
440
|
|
|
|
|
441
|
|
|
return json_decode($response->getBody(), true); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
/** |
|
445
|
|
|
* @return Array Emulating an entry in the $_FILES superglobal |
|
446
|
|
|
*/ |
|
447
|
|
|
protected function getUploadFile($paramName, $tmpFileName = 'AssetAdminTest.txt') |
|
|
|
|
|
|
448
|
|
|
{ |
|
449
|
|
|
$tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
|
450
|
|
|
$tmpFileContent = ''; |
|
451
|
|
|
for ($i = 0; $i < 10000; $i++) { |
|
452
|
|
|
$tmpFileContent .= '0'; |
|
453
|
|
|
} |
|
454
|
|
|
file_put_contents($tmpFilePath, $tmpFileContent); |
|
455
|
|
|
|
|
456
|
|
|
// emulates the $_FILES array |
|
457
|
|
|
return array( |
|
458
|
|
|
'name' => $tmpFileName, |
|
459
|
|
|
'type' => 'text/plaintext', |
|
460
|
|
|
'size' => filesize($tmpFilePath), |
|
461
|
|
|
'tmp_name' => $tmpFilePath, |
|
462
|
|
|
'error' => UPLOAD_ERR_OK, |
|
463
|
|
|
); |
|
464
|
|
|
} |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
class AssetAdminTest_File extends File implements \TestOnly |
|
|
|
|
|
|
468
|
|
|
{ |
|
469
|
|
|
public function canView($member = null) |
|
470
|
|
|
{ |
|
471
|
|
|
return ($this->Name != 'disallowCanView.txt'); |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
public function canEdit($member = null) |
|
475
|
|
|
{ |
|
476
|
|
|
return ($this->Name != 'disallowCanEdit.txt'); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
public function canDelete($member = null) |
|
480
|
|
|
{ |
|
481
|
|
|
return ($this->Name != 'disallowCanDelete.txt'); |
|
482
|
|
|
} |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
class AssetAdminTest_Folder extends Folder implements \TestOnly |
|
|
|
|
|
|
486
|
|
|
{ |
|
487
|
|
|
public function canView($member = null, $context = array()) |
|
|
|
|
|
|
488
|
|
|
{ |
|
489
|
|
|
return ($this->Name != 'disallowCanView'); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
public function canEdit($member = null, $context = array()) |
|
|
|
|
|
|
493
|
|
|
{ |
|
494
|
|
|
return ($this->Name != 'disallowCanEdit'); |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
public function canDelete($member = null, $context = array()) |
|
|
|
|
|
|
498
|
|
|
{ |
|
499
|
|
|
return ($this->Name != 'disallowCanDelete'); |
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
public function canCreate($member = null, $context = array()) |
|
503
|
|
|
{ |
|
504
|
|
|
return ($this->Name != 'disallowCanCreate'); |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
public function canAddChildren($member = null, $context = array()) |
|
|
|
|
|
|
508
|
|
|
{ |
|
509
|
|
|
return ($this->Name != 'disallowCanAddChildren'); |
|
510
|
|
|
} |
|
511
|
|
|
} |
|
512
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.