|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class DMSDocumentControllerTest |
|
5
|
|
|
*/ |
|
6
|
|
|
class DMSDocumentControllerTest extends SapphireTest |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
protected static $fixture_file = "dmstest.yml"; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Test that the download behaviour is either "open" or "download" |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $behaviour |
|
14
|
|
|
* @param string $expectedDisposition |
|
15
|
|
|
* @dataProvider behaviourProvider |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testDownloadBehaviourOpen($behaviour, $expectedDisposition) |
|
18
|
|
|
{ |
|
19
|
|
|
DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives |
|
20
|
|
|
|
|
21
|
|
|
$this->logInWithPermission('ADMIN'); |
|
22
|
|
|
|
|
23
|
|
|
/** @var DMSDocument_Controller $controller */ |
|
24
|
|
|
$controller = $this->getMockBuilder('DMSDocument_Controller') |
|
|
|
|
|
|
25
|
|
|
->setMethods(array('sendFile'))->getMock(); |
|
26
|
|
|
|
|
27
|
|
|
$self = $this; |
|
28
|
|
|
$controller->expects($this->once()) |
|
|
|
|
|
|
29
|
|
|
->method('sendFile') |
|
30
|
|
|
->will( |
|
31
|
|
|
$this->returnCallback(function ($path, $mime, $name, $disposition) use ($self, $expectedDisposition) { |
|
|
|
|
|
|
32
|
|
|
$self->assertEquals($expectedDisposition, $disposition); |
|
|
|
|
|
|
33
|
|
|
}) |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$openDoc = new DMSDocument(); |
|
37
|
|
|
$openDoc->Filename = "DMS-test-lorum-file.pdf"; |
|
|
|
|
|
|
38
|
|
|
$openDoc->Folder = "tests"; |
|
|
|
|
|
|
39
|
|
|
$openDoc->DownloadBehavior = $behaviour; |
|
|
|
|
|
|
40
|
|
|
$openDoc->clearEmbargo(false); |
|
41
|
|
|
$openDoc->write(); |
|
42
|
|
|
$request = new SS_HTTPRequest('GET', 'index/' . $openDoc->ID); |
|
43
|
|
|
$request->match('index/$ID'); |
|
44
|
|
|
$controller->index($request); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function behaviourProvider() |
|
51
|
|
|
{ |
|
52
|
|
|
return array( |
|
53
|
|
|
array('open', 'inline'), |
|
54
|
|
|
array('download', 'attachment') |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.