/** * Singleton * @return DMS */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; }
public function testShortcodeOperation() { $file = 'dms/tests/DMS-test-lorum-file.pdf'; $document = DMS::inst()->storeDocument($file); $result = ShortcodeParser::get('default')->parse(sprintf('<p><a href="[dms_document_link id=\'%d\']">Document</a></p>', $document->ID)); $value = Injector::inst()->create('HTMLValue', $result); $link = $value->query('//a')->item(0); $this->assertStringEndsWith("/dmsdocument/{$document->ID}", $link->getAttribute('href')); $this->assertEquals($document->getExtension(), $link->getAttribute('data-ext')); $this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size')); }
function testDMSVersionStorage() { $dms = DMS::inst(); $document = $dms->storeDocument(self::$testFile); $this->assertNotNull($document, "Document object created"); $this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename), "Document file copied into DMS folder"); $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"); }
/** * Override the default behaviour of the UploadField and take the uploaded file (uploaded to assets) and * add it into the DMS storage, deleting the old/uploaded file. * @param File */ protected function attachFile($file) { $dms = DMS::inst(); $record = $this->getRecord(); if ($record instanceof DMSDocument) { // If the edited record is a document, // assume we're replacing an existing file $doc = $record; $doc->ingestFile($file); } else { // Otherwise create it $doc = $dms->storeDocument($file); $file->delete(); // Relate to the underlying page being edited. // Not applicable when editing the document itself and replacing it. $doc->addPage($record); } return $doc; }
function testBasicEmbargo() { $oldDMSFolder = DMS::$dmsFolder; DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives $doc = new DMSDocument(); $doc->Filename = "DMS-test-lorum-file.pdf"; $doc->Folder = "tests"; $docID = $doc->write(); //fake a request for a document $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)"); $doc->embargoIndefinitely(); $result = $controller->index($this->createFakeHTTPRequest($docID)); $this->assertNotEquals($doc->getFullPath(), $result, "File no longer returned (in test mode)"); DMS::$dmsFolder = $oldDMSFolder; }
function testBasicEmbargo() { $oldDMSFolder = DMS::$dmsFolder; DMS::$dmsFolder = DMS_DIR; //sneakily setting the DMS folder to the folder where the test file lives $doc = new DMSDocument(); $doc->Filename = "DMS-test-lorum-file.pdf"; $doc->Folder = "tests"; $docID = $doc->write(); //fake a request for a document $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)"); $doc->embargoIndefinitely(); $this->logInWithPermission('ADMIN'); $result = $controller->index($this->createFakeHTTPRequest($docID)); $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"); DMS::$dmsFolder = $oldDMSFolder; }
function testReplaceDocument() { $dms = DMS::inst(); //store the first document $document = $dms->storeDocument(self::$testFile); $document->Title = "My custom title"; $document->Description = "My custom description"; $document->write(); //then overwrite with a second document $document = $document->replaceDocument(self::$testFile2); $this->assertNotNull($document, "Document object created"); $this->assertTrue(file_exists(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $document->Folder . DIRECTORY_SEPARATOR . $document->Filename), "Document file copied into DMS folder"); $this->assertContains("DMS-test-document-2", $document->Filename, "Original document filename is contain in the new filename"); $this->assertEquals("My custom title", $document->Title, "Custom title not modified"); $this->assertEquals("My custom description", $document->Description, "Custom description not modified"); }
/** * Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file * but keeping the rest of the document unchanged. * @param $file File object, or String that is path to a file to store * @return DMSDocumentInstance Document object that we replaced the file in */ function replaceDocument($file) { $filePath = DMS::transform_file_to_file_path($file); $doc = $this->storeDocument($filePath); //replace the document return $doc; }
/** * Returns the full filename of the document stored in this object. Can * optionally specify which filename to use at the end. * * @param string * * @return string */ public function getFullPath($filename = null) { if (!$filename) { $filename = $this->Filename; } return DMS::get_dms_path() . DIRECTORY_SEPARATOR . $this->Folder . DIRECTORY_SEPARATOR . $filename; }
<?php /** * altaztoradec.php * PHP test file to play with the Stellarduino PHP class. * Author: Casey Fulton, casey AT caseyfulton DOT com * License: MIT, http://opensource.org/licenses/MIT */ require_once 'Stellarduino.class.php'; header('Content-Type: text/plain;'); $m22 = new StellarObject(new HMS(18, 36, 24, 'e'), DMS::withDMS(23, 54, 0, 's'), 'M22'); $spica = new StellarObject(new HMS(13, 25, 11.6, 'e'), DMS::withDMS(11, 9, 41, 's'), 'M22'); list($alt, $az) = Stellarduino::getAltAz($m22, -27.43, 153.03); echo 'Viewed from Brisbane, Australia, M22 is at ' . $alt . ' alt, ' . $az . ' az.' . "\n"; list($alt, $az) = Stellarduino::getAltAz($spica, -27.43, 153.03); echo 'Viewed from Brisbane, Australia, Spica is at ' . $alt . ' alt, ' . $az . ' az.' . "\n"; $dec = Stellarduino::getRADec($alt, $az, -27.43, 153.03); echo 'Spica has a listed Dec of ' . $spica->getDec()->getDecimalDeg() . ', we calculated ' . $dec . "\n";
</select> <button class="dms-delete-row" title="Delete">×</button> </td> </tr> <?php } ?> <tr> <th></th> <td> <span class="pre-host">http://</span> <input type="text" class="dms regular-text dms-collect-key" placeholder="www.example.com" /> <span class="post-host">/</span> <?php $options = DMS::getDMSOptions(); ?> <select class="dms page_id" name="page_id" data-placeholder="The choice is yours."> <option></option> <?php foreach ($options as $key => $optgroup) { echo "<optgroup label=\"{$key}\">"; foreach ($optgroup as $option) { echo "<option class=\"level-0\" value=\"{$option['id']}\">{$option['title']}</option>"; } echo "</optgroup>"; } ?> </select> <button class="dms-delete-row" title="Delete">×</button> </td>