|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class DMSDocumentControllerTest |
|
5
|
|
|
*/ |
|
6
|
|
|
class DMSDocumentControllerTest extends SapphireTest |
|
7
|
|
|
{ |
|
8
|
|
|
protected static $fixture_file = 'dmstest.yml'; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var DMSDocument_Controller |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $controller; |
|
14
|
|
|
|
|
15
|
|
|
public function setUp() |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
|
|
19
|
|
|
Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); |
|
20
|
|
|
$this->logInWithPermission('ADMIN'); |
|
21
|
|
|
|
|
22
|
|
|
$this->controller = $this->getMockBuilder('DMSDocument_Controller') |
|
|
|
|
|
|
23
|
|
|
->setMethods(array('sendFile')) |
|
24
|
|
|
->getMock(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function tearDown() |
|
28
|
|
|
{ |
|
29
|
|
|
DMSFilesystemTestHelper::delete('assets/_unit-test-123'); |
|
30
|
|
|
parent::tearDown(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Test that the download behaviour is either "open" or "download" |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $behaviour |
|
37
|
|
|
* @param string $expectedDisposition |
|
38
|
|
|
* @dataProvider behaviourProvider |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testDownloadBehaviourOpen($behaviour, $expectedDisposition) |
|
41
|
|
|
{ |
|
42
|
|
|
$self = $this; |
|
43
|
|
|
$this->controller->expects($this->once()) |
|
|
|
|
|
|
44
|
|
|
->method('sendFile') |
|
45
|
|
|
->will( |
|
46
|
|
|
$this->returnCallback(function ($path, $mime, $name, $disposition) use ($self, $expectedDisposition) { |
|
|
|
|
|
|
47
|
|
|
$self->assertEquals($expectedDisposition, $disposition); |
|
|
|
|
|
|
48
|
|
|
}) |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$openDoc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf'); |
|
52
|
|
|
$openDoc->DownloadBehavior = $behaviour; |
|
53
|
|
|
$openDoc->clearEmbargo(false); |
|
54
|
|
|
$openDoc->write(); |
|
55
|
|
|
|
|
56
|
|
|
$request = new SS_HTTPRequest('GET', $openDoc->Link()); |
|
57
|
|
|
$request->match('dmsdocument/$ID'); |
|
58
|
|
|
$this->controller->index($request); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return array[] |
|
63
|
|
|
*/ |
|
64
|
|
|
public function behaviourProvider() |
|
65
|
|
|
{ |
|
66
|
|
|
return array( |
|
67
|
|
|
array('open', 'inline'), |
|
68
|
|
|
array('download', 'attachment') |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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.