diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..05cef68 --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,12 @@ +--- +Name: dmsconfig +--- +SiteTree: + extensions: + - DMSSiteTreeExtension + # Whether to show the document sets tab in the CMS for the page type this extension is applied to + documents_enabled: true + +HtmlEditorField_Toolbar: + extensions: + - DocumentHtmlEditorFieldToolbar diff --git a/_config/dmsdocument.yml b/_config/dmsdocument.yml index 9d796ee..d6493e6 100644 --- a/_config/dmsdocument.yml +++ b/_config/dmsdocument.yml @@ -6,15 +6,5 @@ Director: rules: 'dmsdocument/$ID' : 'DMSDocument_Controller' -SiteTree: - extensions: - - DMSSiteTreeExtension - # Whether to show the document sets tab in the CMS for the page type this extension is applied to - documents_enabled: true - -HtmlEditorField_Toolbar: - extensions: - - DocumentHtmlEditorFieldToolbar - DMSDocument_versions: enable_versions: true diff --git a/code/DMS.php b/code/DMS.php index 3b0e81e..541b01d 100644 --- a/code/DMS.php +++ b/code/DMS.php @@ -1,21 +1,30 @@ getStoragePath(); + + if (!is_dir($dmsPath)) { + self::$instance->createStorageFolder($dmsPath); + } + + if (!file_exists($dmsPath . DIRECTORY_SEPARATOR . '.htaccess')) { + // Restrict access to the storage folder + copy( + BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR . DIRECTORY_SEPARATOR + . 'resources' . DIRECTORY_SEPARATOR . '.htaccess', + $dmsPath . DIRECTORY_SEPARATOR . '.htaccess' + ); + + copy( + BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR . DIRECTORY_SEPARATOR + . 'resources' . DIRECTORY_SEPARATOR . 'web.config', + $dmsPath . DIRECTORY_SEPARATOR . 'web.config' + ); + } } - - if (!file_exists($dmsPath . DIRECTORY_SEPARATOR . '.htaccess')) { - // Restrict access to the storage folder - copy( - BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR . DIRECTORY_SEPARATOR - . 'resources' . DIRECTORY_SEPARATOR . '.htaccess', - $dmsPath . DIRECTORY_SEPARATOR . '.htaccess' - ); - - copy( - BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR . DIRECTORY_SEPARATOR - . 'resources' . DIRECTORY_SEPARATOR . 'web.config', - $dmsPath . DIRECTORY_SEPARATOR . 'web.config' - ); - } - return $dms; + return self::$instance; } /** + * Get the storage path for DMS documents + * * @return string */ - public static function get_dms_path() + public function getStoragePath() { - return BASE_PATH . DIRECTORY_SEPARATOR . self::$dmsFolder; + return BASE_PATH . DIRECTORY_SEPARATOR . $this->config()->get('folder_name'); } - public static function transform_file_to_file_path($file) + /** + * Gets a file path from either a File or a string + * + * @param string|File $file + * @return string + * @throws FileNotFoundException If an unexpected value was provided, or the filename was null + */ + public function transformFileToFilePath($file) { //confirm we have a file $filePath = null; @@ -84,16 +105,16 @@ class DMS implements DMSInterface /** * Takes a File object or a String (path to a file) and copies it into the DMS. The original file remains unchanged. * When storing a document, sets the fields on the File has "tag" metadata. - * @param $file File object, or String that is path to a file to store, + * @param File|string $file File object, or String that is path to a file to store, * e.g. "assets/documents/industry/supplied-v1-0.pdf" * @return DMSDocument */ public function storeDocument($file) { - $filePath = self::transform_file_to_file_path($file); + $filePath = $this->transformFileToFilePath($file); - //create a new document and get its ID - $doc = new DMSDocument(); + // Create a new document and get its ID + $doc = DMSDocument::create(); $doc->write(); $doc->storeDocument($filePath); @@ -156,22 +177,26 @@ class DMS implements DMSInterface /** * Creates a storage folder for the given path - * @param $path Path to create a folder for + * + * @param string $path Path to create a folder for + * @return $this */ - public static function create_storage_folder($path) + public function createStorageFolder($path) { if (!is_dir($path)) { - mkdir($path, 0777); + mkdir($path, 0777, true); } + return $this; } /** * Calculates the storage path from a database DMSDocument ID + * + * @return int */ - public static function get_storage_folder($id) + public function getStorageFolder($id) { - $folderName = intval($id / self::$dmsFolderSize); - return $folderName; + return intval($id / self::config()->get('folder_size')); } /** diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index 958c8d4..bd76322 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -667,7 +667,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface public function getFullPath() { if ($this->Filename) { - return DMS::get_dms_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $this->Filename; + return DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR + . $this->Folder . DIRECTORY_SEPARATOR . $this->Filename; } return null; @@ -712,7 +713,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface */ public function getStorageFolder() { - return DMS::get_dms_path() . DIRECTORY_SEPARATOR . DMS::get_storage_folder($this->ID); + return DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . DMS::inst()->getStorageFolder($this->ID); } /** @@ -770,7 +771,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface /** * Relate an existing file on the filesystem to the document. * - * Copies the file to the new destination, as defined in {@link get_DMS_path()}. + * Copies the file to the new destination, as defined in {@link DMS::getStoragePath()}. * * @param string $filePath Path to file, relative to webroot. * @@ -785,10 +786,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface // calculate all the path to copy the file to $fromFilename = basename($filePath); $toFilename = $this->ID. '~' . $fromFilename; //add the docID to the start of the Filename - $toFolder = DMS::get_storage_folder($this->ID); - $toPath = DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename; + $toFolder = DMS::inst()->getStorageFolder($this->ID); + $toPath = DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename; - DMS::create_storage_folder(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder); + DMS::inst()->createStorageFolder(DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $toFolder); //copy the file into place $fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath; @@ -832,7 +833,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface */ public function replaceDocument($file) { - $filePath = DMS::transform_file_to_file_path($file); + $filePath = DMS::inst()->transformFileToFilePath($file); $doc = $this->storeDocument($filePath); // replace the document return $doc; diff --git a/code/model/DMSDocument_versions.php b/code/model/DMSDocument_versions.php index 7957e8f..87b070c 100644 --- a/code/model/DMSDocument_versions.php +++ b/code/model/DMSDocument_versions.php @@ -179,7 +179,7 @@ class DMSDocument_versions extends DataObject if (!$filename) { $filename = $this->Filename; } - return DMS::get_dms_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $filename; + return DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $filename; } /** diff --git a/docs/en/changelogs/2.0.0.md b/docs/en/changelogs/2.0.0.md index 9077fd2..d0380de 100644 --- a/docs/en/changelogs/2.0.0.md +++ b/docs/en/changelogs/2.0.0.md @@ -23,6 +23,12 @@ having a Document Set intermediary (@todo Add a build task for this). * `DMSDocumentAddController::add_allowed_extensions` removed, use YAML configuration `DMSDocumentAddController::allowed_extensions` instead * `DMSInterface` (and `DMS`) are stricter in the `getByPage` method, enforcing a `SiteTree` type hint * New method `DMSInterface::getDocumentSetsByPage` (and in `DMS`) +* `DMS::$dmsFolder` removed, use YAML configuration `DMS.folder_name` instead +* `DMS::$dmsFolderSize` removed, use YAML configuration `DMS.folder_size` instead +* `DMS::get_dms_path` made non-static, use `DMS::inst()->getStoragePath()` instead +* `DMS::transform_file_to_file_path` made non-static, use `DMS::inst()->transformFileToFilePath()` instead +* `DMS::create_storage_folder` made non-static, use `DMS::inst()->createStorageFolder()` instead +* `DMS::get_storage_folder` made non-static, use `DMS::inst()->getStorageFolder()` instead ## Template changes diff --git a/docs/en/configuration.md b/docs/en/configuration.md index dc4db25..1857703 100644 --- a/docs/en/configuration.md +++ b/docs/en/configuration.md @@ -1,6 +1,20 @@ # Configuration -The file location is set via the `DMS::$dmsFolder` static, and points to a location in the webroot. +The file location is set via the `DMS.folder_name` configuation property, and points to a location in the webroot. By +default, this resides in an underscores folder within the assets folder. This means that automated snapshots/backups +(e.g. using [sspak](https://github.com/silverstripe/sspak)) can still handle DMS documents, but they will not show up +when navigating asset folders in the CMS. + +## Changing the default storage folder + +You can change the default storage folder location using YAML configuration. This folder would be relative to your +project root directory: + +```yaml +DMS: + folder_name: my-custom-folder +``` + ## Enable/disable documents/sets for a specific page type diff --git a/tests/DMSDocumentControllerTest.php b/tests/DMSDocumentControllerTest.php index e034593..82440ea 100644 --- a/tests/DMSDocumentControllerTest.php +++ b/tests/DMSDocumentControllerTest.php @@ -5,7 +5,7 @@ */ class DMSDocumentControllerTest extends SapphireTest { - protected static $fixture_file = "dmstest.yml"; + protected static $fixture_file = 'dmstest.yml'; /** * Test that the download behaviour is either "open" or "download" @@ -16,7 +16,7 @@ class DMSDocumentControllerTest extends SapphireTest */ public function testDownloadBehaviourOpen($behaviour, $expectedDisposition) { - DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives + Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); $this->logInWithPermission('ADMIN'); @@ -33,15 +33,16 @@ class DMSDocumentControllerTest extends SapphireTest }) ); - $openDoc = new DMSDocument(); - $openDoc->Filename = "DMS-test-lorum-file.pdf"; - $openDoc->Folder = "tests"; + $openDoc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf'); $openDoc->DownloadBehavior = $behaviour; $openDoc->clearEmbargo(false); $openDoc->write(); + $request = new SS_HTTPRequest('GET', 'index/' . $openDoc->ID); $request->match('index/$ID'); $controller->index($request); + + DMSFilesystemTestHelper::delete('assets/_unit-test-123'); } /** diff --git a/tests/DMSDocumentTest.php b/tests/DMSDocumentTest.php index d010e3f..b0278a5 100644 --- a/tests/DMSDocumentTest.php +++ b/tests/DMSDocumentTest.php @@ -3,22 +3,6 @@ class DMSDocumentTest extends SapphireTest { protected static $fixture_file = 'dmstest.yml'; - public function tearDownOnce() - { - self::$is_running_test = true; - - $d = DataObject::get('DMSDocument'); - foreach ($d as $d1) { - $d1->delete(); - } - $t = DataObject::get('DMSTag'); - foreach ($t as $t1) { - $t1->delete(); - } - - self::$is_running_test = $this->originalIsRunningTest; - } - public function testDefaultDownloadBehabiourCMSFields() { $document = singleton('DMSDocument'); @@ -259,4 +243,35 @@ class DMSDocumentTest extends SapphireTest $d2 = $this->objFromFixture('DMSDocument', 'd2'); $this->assertSame('File That Doesn\'t Exist (Title)', $d2->getTitle()); } + + /** + * Ensure that the folder a document's file is stored in can be retrieved, and that delete() will also delete + * the file and the record + */ + public function testGetStorageFolderThenDelete() + { + Config::inst()->update('DMS', 'folder_name', 'assets/_unit-tests'); + + $document = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf'); + $filename = $document->getStorageFolder() . '/' . $document->getFileName(); + + $this->assertTrue(file_exists($filename)); + $document->delete(); + $this->assertFalse($document->exists()); + $this->assertFalse(file_exists($filename)); + + DMSFilesystemTestHelper::delete('assets/_unit-tests'); + } + + /** + * Ensure that the description can be returned in HTML format + */ + public function testGetDescriptionWithLineBreak() + { + $document = DMSDocument::create(); + $document->Description = "Line 1\nLine 2\nLine 3"; + $document->write(); + + $this->assertSame("Line 1
\nLine 2
\nLine 3", $document->getDescriptionWithLineBreak()); + } } diff --git a/tests/DMSEmbargoTest.php b/tests/DMSEmbargoTest.php index 780e449..bd5faed 100644 --- a/tests/DMSEmbargoTest.php +++ b/tests/DMSEmbargoTest.php @@ -1,23 +1,7 @@ delete(); - } - $t = DataObject::get("DMSTag"); - foreach ($t as $t1) { - $t1->delete(); - } - - self::$is_running_test = $this->originalIsRunningTest; - } + protected static $fixture_file = 'dmsembargotest.yml'; public function createFakeHTTPRequest($id) { @@ -28,13 +12,10 @@ class DMSEmbargoTest extends SapphireTest public function testBasicEmbargo() { - $oldDMSFolder = DMS::$dmsFolder; $oldTestMode = DMSDocument_Controller::$testMode; - DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives + Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); - $doc = new DMSDocument(); - $doc->Filename = "DMS-test-lorum-file.pdf"; - $doc->Folder = "tests"; + $doc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf'); $doc->CanViewType = 'LoggedInUsers'; $docID = $doc->write(); @@ -42,24 +23,24 @@ class DMSEmbargoTest extends SapphireTest $controller = new DMSDocument_Controller(); DMSDocument_Controller::$testMode = true; $result = $controller->index($this->createFakeHTTPRequest($docID)); - $this->assertEquals($doc->getFullPath(), $result, "Correct underlying file returned (in test mode)"); + $this->assertEquals($doc->getFullPath(), $result, 'Correct underlying file returned (in test mode)'); $doc->embargoIndefinitely(); $this->logInWithPermission('ADMIN'); $result = $controller->index($this->createFakeHTTPRequest($docID)); - $this->assertEquals($doc->getFullPath(), $result, "Admins can still download embargoed files"); + $this->assertEquals($doc->getFullPath(), $result, 'Admins can still download embargoed files'); $this->logInWithPermission('random-user-group'); $result = $controller->index($this->createFakeHTTPRequest($docID)); $this->assertNotEquals( $doc->getFullPath(), $result, - "File no longer returned (in test mode) when switching to other user group" + 'File no longer returned (in test mode) when switching to other user group' ); - DMS::$dmsFolder = $oldDMSFolder; DMSDocument_Controller::$testMode = $oldTestMode; + DMSFilesystemTestHelper::delete('assets/_unit-test-123'); } public function testEmbargoIndefinitely() diff --git a/tests/DMSFilesystemTestHelper.php b/tests/DMSFilesystemTestHelper.php new file mode 100644 index 0000000..6255da7 --- /dev/null +++ b/tests/DMSFilesystemTestHelper.php @@ -0,0 +1,42 @@ +isDir() ? 'rmdir' : 'unlink'; + $action($fileinfo->getRealPath()); + } + + rmdir($path); + } else { + unlink($path); + } + } +} diff --git a/tests/DMSShortcodeTest.php b/tests/DMSShortcodeTest.php index c913920..1564401 100644 --- a/tests/DMSShortcodeTest.php +++ b/tests/DMSShortcodeTest.php @@ -9,6 +9,8 @@ class DMSShortcodeTest extends SapphireTest { public function testShortcodeOperation() { + Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123'); + $file = 'dms/tests/DMS-test-lorum-file.pdf'; $document = DMS::inst()->storeDocument($file); @@ -23,5 +25,7 @@ class DMSShortcodeTest extends SapphireTest $this->assertStringEndsWith("/dmsdocument/$document->ID", $link->getAttribute('href')); $this->assertEquals($document->getExtension(), $link->getAttribute('data-ext')); $this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size')); + + DMSFilesystemTestHelper::delete('assets/_unit-test-123'); } } diff --git a/tests/DMSTest.php b/tests/DMSTest.php index 6a5f4ce..d95b008 100644 --- a/tests/DMSTest.php +++ b/tests/DMSTest.php @@ -5,86 +5,46 @@ class DMSTest extends FunctionalTest /** * Stub PDF files for testing + * * @var string */ public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf'; public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf'; /** - * Store values to reset back to after this test runs + * The test folder to write assets into + * + * @var string */ - public static $dmsFolderOld; - public static $dmsFolderSizeOld; + protected $testDmsPath = 'assets/_dms-assets-test-1234'; /** - * @var DMS + * @var DMSInterace */ protected $dms; + /** + * Use a test DMS folder, so we don't overwrite the live one, and clear it out in case of previous broken tests + * + * {@inheritDoc} + */ public function setUp() { parent::setUp(); - - self::$dmsFolderOld = DMS::$dmsFolder; - self::$dmsFolderSizeOld = DMS::$dmsFolderSize; - - //use a test DMS folder, so we don't overwrite the live one - DMS::$dmsFolder = 'dms-assets-test-1234'; - - //clear out the test folder (in case a broken test doesn't delete it) - $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-1234'); - + Config::inst()->update('DMS', 'folder_name', $this->testDmsPath); + DMSFilesystemTestHelper::delete($this->testDmsPath); $this->dms = DMS::inst(); } + /** + * Delete the test folder after the test runs + * + * {@inheritDoc} + */ public function tearDown() { parent::tearDown(); - - self::$is_running_test = true; - - $d = DataObject::get("DMSDocument"); - foreach ($d as $d1) { - $d1->delete(); - } - $t = DataObject::get("DMSTag"); - foreach ($t as $t1) { - $t1->delete(); - } - - //delete the test folder after the test runs - $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-1234'); - - //set the old DMS folder back again - DMS::$dmsFolder = self::$dmsFolderOld; - DMS::$dmsFolderSize = self::$dmsFolderSizeOld; - - self::$is_running_test = $this->originalIsRunningTest; - } - - /** - * Delete a file that was created during a unit test - * - * @param string $path - */ - public function delete($path) - { - if (file_exists($path) || is_dir($path)) { - $it = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path), - RecursiveIteratorIterator::CHILD_FIRST - ); - foreach ($it as $file) { - if (in_array($file->getBasename(), array('.', '..'))) { - continue; - } elseif ($file->isDir()) { - rmdir($file->getPathname()); - } elseif ($file->isFile() || $file->isLink()) { - unlink($file->getPathname()); - } - } - rmdir($path); - } + DMSFilesystemTestHelper::delete($this->testDmsPath); } public function testDMSStorage() @@ -95,7 +55,7 @@ class DMSTest extends FunctionalTest $this->assertNotNull($document, "Document object created"); $this->assertTrue( file_exists( - DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder + DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename ), "Document file copied into DMS folder" @@ -104,7 +64,7 @@ class DMSTest extends FunctionalTest public function testDMSFolderSpanning() { - DMS::$dmsFolderSize = 5; + Config::inst()->update('DMS', 'folder_size', 5); $file = self::$testFile; $documents = array(); @@ -128,7 +88,10 @@ class DMSTest extends FunctionalTest // Test we created 4 folder to contain the 17 files foreach ($folders as $f) { - $this->assertTrue(is_dir(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $f), "Document folder '$f' exists"); + $this->assertTrue( + is_dir(DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $f), + "Document folder '$f' exists" + ); } } @@ -146,7 +109,7 @@ class DMSTest extends FunctionalTest $this->assertNotNull($document, "Document object created"); $this->assertTrue( file_exists( - DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder + DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename ), "Document file copied into DMS folder" diff --git a/tests/DMSVersioningTest.php b/tests/DMSVersioningTest.php index feaeb48..318766e 100755 --- a/tests/DMSVersioningTest.php +++ b/tests/DMSVersioningTest.php @@ -10,74 +10,48 @@ class DMSVersioningTest extends SapphireTest public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf'; public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf'; + /** + * The test folder to write assets into + * + * @var string + */ + protected $testDmsPath = 'assets/_dms-assets-test-versions'; + /** * Store values to reset back to after this test runs */ - public static $dmsFolderOld; - public static $dmsFolderSizeOld; public static $dmsEnableVersionsOld; + /** + * 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} + */ public function setUp() { parent::setUp(); - self::$dmsFolderOld = DMS::$dmsFolder; - self::$dmsFolderSizeOld = DMS::$dmsFolderSize; self::$dmsEnableVersionsOld = DMSDocument_versions::$enable_versions; DMSDocument_versions::$enable_versions = true; - //use a test DMS folder, so we don't overwrite the live one - DMS::$dmsFolder = 'dms-assets-test-versions'; - - //clear out the test folder (in case a broken test doesn't delete it) - $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-versions'); - } - - public function tearDown() - { - $d = DataObject::get("DMSDocument"); - foreach ($d as $d1) { - $d1->delete(); - } - $t = DataObject::get("DMSTag"); - foreach ($t as $t1) { - $t1->delete(); - } - - // Delete the test folder after the test runs - $this->delete(BASE_PATH . DIRECTORY_SEPARATOR . 'dms-assets-test-versions'); - - parent::tearDown(); - - // Set the old DMS folder back again - DMS::$dmsFolder = self::$dmsFolderOld; - DMS::$dmsFolderSize = self::$dmsFolderSizeOld; - DMSDocument_versions::$enable_versions = self::$dmsEnableVersionsOld; + Config::inst()->update('DMS', 'folder_name', $this->testDmsPath); + DMSFilesystemTestHelper::delete($this->testDmsPath); } /** - * Delete a file that was created during a unit test + * Delete the test folder after the tests run * - * @param string $path + * {@inheritDoc} */ - public function delete($path) + public function tearDown() { - if (file_exists($path) || is_dir($path)) { - $it = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path), - RecursiveIteratorIterator::CHILD_FIRST - ); - foreach ($it as $file) { - if (in_array($file->getBasename(), array('.', '..'))) { - continue; - } elseif ($file->isDir()) { - rmdir($file->getPathname()); - } elseif ($file->isFile() || $file->isLink()) { - unlink($file->getPathname()); - } - } - rmdir($path); - } + parent::tearDown(); + + DMSFilesystemTestHelper::delete($this->testDmsPath); + + // Set the old DMS folder back again + DMSDocument_versions::$enable_versions = self::$dmsEnableVersionsOld; } public function testDMSVersionStorage() @@ -91,7 +65,7 @@ class DMSVersioningTest extends SapphireTest $this->assertNotNull($document, "Document object created"); $this->assertTrue( file_exists( - DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder + DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename ), "Document file copied into DMS folder"