2012-08-13 04:14:31 +02:00
|
|
|
<?php
|
2015-12-17 19:48:37 +01:00
|
|
|
class DMSEmbargoTest extends SapphireTest
|
|
|
|
{
|
2017-05-17 06:24:25 +02:00
|
|
|
protected static $fixture_file = 'dmsembargotest.yml';
|
2015-12-17 19:48:37 +01:00
|
|
|
|
|
|
|
public function createFakeHTTPRequest($id)
|
|
|
|
{
|
|
|
|
$r = new SS_HTTPRequest('GET', 'index/'.$id);
|
|
|
|
$r->match('index/$ID');
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicEmbargo()
|
|
|
|
{
|
2016-12-20 12:57:19 +01:00
|
|
|
$oldTestMode = DMSDocument_Controller::$testMode;
|
2017-05-17 06:24:25 +02:00
|
|
|
Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123');
|
2015-12-17 19:48:37 +01:00
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
$doc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
|
2017-05-08 05:30:24 +02:00
|
|
|
$doc->CanViewType = 'LoggedInUsers';
|
2015-12-17 19:48:37 +01:00
|
|
|
$docID = $doc->write();
|
|
|
|
|
|
|
|
//fake a request for a document
|
|
|
|
$controller = new DMSDocument_Controller();
|
|
|
|
DMSDocument_Controller::$testMode = true;
|
|
|
|
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
2017-05-17 06:24:25 +02:00
|
|
|
$this->assertEquals($doc->getFullPath(), $result, 'Correct underlying file returned (in test mode)');
|
2015-12-17 19:48:37 +01:00
|
|
|
|
|
|
|
$doc->embargoIndefinitely();
|
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
2017-05-17 06:24:25 +02:00
|
|
|
$this->assertEquals($doc->getFullPath(), $result, 'Admins can still download embargoed files');
|
2015-12-17 19:48:37 +01:00
|
|
|
|
|
|
|
$this->logInWithPermission('random-user-group');
|
|
|
|
$result = $controller->index($this->createFakeHTTPRequest($docID));
|
2017-05-01 05:54:48 +02:00
|
|
|
$this->assertNotEquals(
|
|
|
|
$doc->getFullPath(),
|
|
|
|
$result,
|
2017-05-17 06:24:25 +02:00
|
|
|
'File no longer returned (in test mode) when switching to other user group'
|
2017-05-01 05:54:48 +02:00
|
|
|
);
|
2015-12-17 19:48:37 +01:00
|
|
|
|
2016-12-20 12:57:19 +01:00
|
|
|
DMSDocument_Controller::$testMode = $oldTestMode;
|
2017-05-17 06:24:25 +02:00
|
|
|
DMSFilesystemTestHelper::delete('assets/_unit-test-123');
|
2015-12-17 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmbargoIndefinitely()
|
|
|
|
{
|
|
|
|
$doc = new DMSDocument();
|
|
|
|
$doc->Filename = "DMS-test-lorum-file.pdf";
|
|
|
|
$doc->Folder = "tests";
|
|
|
|
$doc->write();
|
|
|
|
|
|
|
|
$doc->embargoIndefinitely();
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->clearEmbargo();
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExpireAtDate()
|
|
|
|
{
|
|
|
|
$doc = new DMSDocument();
|
|
|
|
$doc->Filename = "DMS-test-lorum-file.pdf";
|
|
|
|
$doc->Folder = "tests";
|
|
|
|
$doc->write();
|
|
|
|
|
|
|
|
$doc->expireAtDate(strtotime('-1 second'));
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertTrue($doc->isExpired(), "Document is expired");
|
|
|
|
|
|
|
|
$expireTime = "2019-04-05 11:43:13";
|
|
|
|
$doc->expireAtDate($expireTime);
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
SS_Datetime::set_mock_now($expireTime);
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertTrue($doc->isExpired(), "Document is expired");
|
|
|
|
SS_Datetime::clear_mock_now();
|
|
|
|
|
|
|
|
$doc->expireAtDate(strtotime('-1 second'));
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertTrue($doc->isExpired(), "Document is expired");
|
|
|
|
|
|
|
|
$doc->clearExpiry();
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmbargoUntilDate()
|
|
|
|
{
|
|
|
|
$doc = new DMSDocument();
|
|
|
|
$doc->Filename = "DMS-test-lorum-file.pdf";
|
|
|
|
$doc->Folder = "tests";
|
|
|
|
$doc->write();
|
|
|
|
|
|
|
|
$doc->embargoUntilDate(strtotime('+1 minute'));
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->embargoUntilDate(strtotime('-1 second'));
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$embargoTime = "2019-04-05 11:43:13";
|
|
|
|
$doc->embargoUntilDate($embargoTime);
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
SS_Datetime::set_mock_now($embargoTime);
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
SS_Datetime::clear_mock_now();
|
|
|
|
|
|
|
|
$doc->clearEmbargo();
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmbargoUntilPublished()
|
|
|
|
{
|
|
|
|
$s1 = $this->objFromFixture('SiteTree', 's1');
|
|
|
|
|
|
|
|
$doc = new DMSDocument();
|
|
|
|
$doc->Filename = "test file";
|
|
|
|
$doc->Folder = "0";
|
|
|
|
$dID = $doc->write();
|
|
|
|
|
2017-05-02 04:49:41 +02:00
|
|
|
$s1->getDocumentSets()->first()->getDocuments()->add($doc);
|
2015-12-17 19:48:37 +01:00
|
|
|
|
|
|
|
$s1->publish('Stage', 'Live');
|
|
|
|
$s1->doPublish();
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->embargoUntilPublished();
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$s1->publish('Stage', 'Live');
|
|
|
|
$s1->doPublish();
|
|
|
|
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->embargoUntilPublished();
|
|
|
|
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->embargoIndefinitely();
|
|
|
|
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
|
|
|
$this->assertTrue($doc->isHidden(), "Document is hidden");
|
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$s1->publish('Stage', 'Live');
|
|
|
|
$s1->doPublish();
|
|
|
|
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
2017-05-01 05:54:48 +02:00
|
|
|
$this->assertTrue(
|
|
|
|
$doc->isHidden(),
|
|
|
|
"Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is there"
|
|
|
|
);
|
2015-12-17 19:48:37 +01:00
|
|
|
$this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
|
|
|
|
$doc->clearEmbargo();
|
|
|
|
$doc = DataObject::get_by_id("DMSDocument", $dID);
|
|
|
|
$this->assertFalse($doc->isHidden(), "Document is not hidden");
|
|
|
|
$this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
|
|
|
|
$this->assertFalse($doc->isExpired(), "Document is not expired");
|
|
|
|
}
|
|
|
|
}
|