2016-12-20 12:57:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DMSDocumentControllerTest
|
|
|
|
*/
|
2017-05-01 05:54:48 +02:00
|
|
|
class DMSDocumentControllerTest extends SapphireTest
|
|
|
|
{
|
2017-05-17 06:24:25 +02:00
|
|
|
protected static $fixture_file = 'dmstest.yml';
|
2016-12-20 12:57:19 +01:00
|
|
|
|
2017-05-24 01:43:23 +02:00
|
|
|
/**
|
|
|
|
* @var DMSDocument_Controller
|
|
|
|
*/
|
|
|
|
protected $controller;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123');
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
|
|
|
|
$this->controller = $this->getMockBuilder('DMSDocument_Controller')
|
|
|
|
->setMethods(array('sendFile'))
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
DMSFilesystemTestHelper::delete('assets/_unit-test-123');
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
/**
|
|
|
|
* Test that the download behaviour is either "open" or "download"
|
|
|
|
*
|
|
|
|
* @param string $behaviour
|
|
|
|
* @param string $expectedDisposition
|
|
|
|
* @dataProvider behaviourProvider
|
|
|
|
*/
|
|
|
|
public function testDownloadBehaviourOpen($behaviour, $expectedDisposition)
|
|
|
|
{
|
2016-12-20 12:57:19 +01:00
|
|
|
$self = $this;
|
2017-05-24 01:43:23 +02:00
|
|
|
$this->controller->expects($this->once())
|
2017-05-01 05:54:48 +02:00
|
|
|
->method('sendFile')
|
|
|
|
->will(
|
|
|
|
$this->returnCallback(function ($path, $mime, $name, $disposition) use ($self, $expectedDisposition) {
|
|
|
|
$self->assertEquals($expectedDisposition, $disposition);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
$openDoc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
|
2017-05-01 05:54:48 +02:00
|
|
|
$openDoc->DownloadBehavior = $behaviour;
|
2016-12-20 12:57:19 +01:00
|
|
|
$openDoc->clearEmbargo(false);
|
|
|
|
$openDoc->write();
|
2017-05-17 06:24:25 +02:00
|
|
|
|
2017-05-24 01:43:23 +02:00
|
|
|
$request = new SS_HTTPRequest('GET', $openDoc->Link());
|
|
|
|
$request->match('dmsdocument/$ID');
|
|
|
|
$this->controller->index($request);
|
2016-12-20 12:57:19 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function behaviourProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('open', 'inline'),
|
|
|
|
array('download', 'attachment')
|
|
|
|
);
|
|
|
|
}
|
2016-12-20 12:57:19 +01:00
|
|
|
}
|