2012-11-21 06:24:46 +01:00
|
|
|
<?php
|
2015-12-17 19:48:37 +01:00
|
|
|
class DMSVersioningTest extends SapphireTest
|
|
|
|
{
|
2017-05-01 05:54:48 +02:00
|
|
|
protected $usesDatabase = true;
|
2015-12-17 19:48:37 +01:00
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
/**
|
|
|
|
* Stub PDF files for testing
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-12-17 19:48:37 +01:00
|
|
|
public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
|
|
|
|
public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
/**
|
|
|
|
* The test folder to write assets into
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $testDmsPath = 'assets/_dms-assets-test-versions';
|
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
/**
|
|
|
|
* Store values to reset back to after this test runs
|
|
|
|
*/
|
2015-12-17 19:48:37 +01:00
|
|
|
public static $dmsEnableVersionsOld;
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
/**
|
|
|
|
* Use a test DMS folder, so we don't overwrite the live one, and clear out the test folder (in case a broken
|
|
|
|
* test doesn't delete it)
|
|
|
|
*
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2015-12-17 19:48:37 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
self::$dmsEnableVersionsOld = DMSDocument_versions::$enable_versions;
|
|
|
|
DMSDocument_versions::$enable_versions = true;
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
Config::inst()->update('DMS', 'folder_name', $this->testDmsPath);
|
|
|
|
DMSFilesystemTestHelper::delete($this->testDmsPath);
|
2015-12-17 19:48:37 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
/**
|
|
|
|
* Delete the test folder after the tests run
|
|
|
|
*
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2015-12-17 19:48:37 +01:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
2017-05-17 06:24:25 +02:00
|
|
|
DMSFilesystemTestHelper::delete($this->testDmsPath);
|
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
// Set the old DMS folder back again
|
2015-12-17 19:48:37 +01:00
|
|
|
DMSDocument_versions::$enable_versions = self::$dmsEnableVersionsOld;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDMSVersionStorage()
|
|
|
|
{
|
2017-05-01 23:36:32 +02:00
|
|
|
$this->markTestSkipped('Needs re-implementation, this test is not consistent.');
|
|
|
|
|
2015-12-17 19:48:37 +01:00
|
|
|
$dms = DMS::inst();
|
|
|
|
|
|
|
|
$document = $dms->storeDocument(self::$testFile);
|
|
|
|
|
|
|
|
$this->assertNotNull($document, "Document object created");
|
2017-05-01 05:54:48 +02:00
|
|
|
$this->assertTrue(
|
|
|
|
file_exists(
|
2017-05-17 06:24:25 +02:00
|
|
|
DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
|
2017-05-01 05:54:48 +02:00
|
|
|
. DIRECTORY_SEPARATOR . $document->Filename
|
|
|
|
),
|
|
|
|
"Document file copied into DMS folder"
|
|
|
|
);
|
2015-12-17 19:48:37 +01:00
|
|
|
|
|
|
|
$document->replaceDocument(self::$testFile2);
|
|
|
|
$document->replaceDocument(self::$testFile);
|
|
|
|
$document->replaceDocument(self::$testFile2);
|
|
|
|
$document->replaceDocument(self::$testFile);
|
|
|
|
|
|
|
|
$versionsList = $document->getVersions();
|
|
|
|
|
|
|
|
$this->assertEquals(4, $versionsList->Count(), "4 Versions created");
|
|
|
|
$versionsArray = $versionsList->toArray();
|
|
|
|
|
|
|
|
$this->assertEquals($versionsArray[0]->VersionCounter, 1, "Correct version count");
|
|
|
|
$this->assertEquals($versionsArray[1]->VersionCounter, 2, "Correct version count");
|
|
|
|
$this->assertEquals($versionsArray[2]->VersionCounter, 3, "Correct version count");
|
|
|
|
$this->assertEquals($versionsArray[3]->VersionCounter, 4, "Correct version count");
|
|
|
|
}
|
|
|
|
}
|