silverstripe-dms/tests/DMSDocumentControllerTest.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2016-12-20 12:57:19 +01:00
<?php
/**
* Class DMSDocumentControllerTest
*/
class DMSDocumentControllerTest extends SapphireTest
{
2016-12-20 12:57:19 +01:00
protected static $fixture_file = "dmstest.yml";
/**
* 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
DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives
$this->logInWithPermission('ADMIN');
/** @var DMSDocument_Controller $controller */
$controller = $this->getMockBuilder('DMSDocument_Controller')
->setMethods(array('sendFile'))->getMock();
2016-12-20 12:57:19 +01:00
$self = $this;
$controller->expects($this->once())
->method('sendFile')
->will(
$this->returnCallback(function ($path, $mime, $name, $disposition) use ($self, $expectedDisposition) {
$self->assertEquals($expectedDisposition, $disposition);
})
);
2016-12-20 12:57:19 +01:00
$openDoc = new DMSDocument();
$openDoc->Filename = "DMS-test-lorum-file.pdf";
$openDoc->Folder = "tests";
$openDoc->DownloadBehavior = $behaviour;
2016-12-20 12:57:19 +01:00
$openDoc->clearEmbargo(false);
$openDoc->write();
$request = new SS_HTTPRequest('GET', 'index/' . $openDoc->ID);
$request->match('index/$ID');
$controller->index($request);
}
/**
* @return array[]
*/
public function behaviourProvider()
{
return array(
array('open', 'inline'),
array('download', 'attachment')
);
}
2016-12-20 12:57:19 +01:00
}