/** * 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, e.g. "assets/documents/industry/supplied-v1-0.pdf" */ function storeDocument($file) { $filePath = self::transform_file_to_file_path($file); //create a new document and get its ID $doc = new DMSDocument(); $doc->write(); $doc->storeDocument($filePath); return $doc; }
function testRemovingTags() { $doc = new DMSDocument(); $doc->Filename = "test file"; $doc->Folder = "0"; $doc->write(); $doc->addTag("fruit", "banana"); $doc->addTag("fruit", "orange"); $doc->addTag("fruit", "apple"); $doc->addTag("company", "apple"); $doc->addTag("company", "SilverStripe"); $companies = $doc->getTagsList("company"); $this->assertNotNull($companies, "Companies returned before deletion"); $this->assertEquals(count($companies), 2, "Two companies returned before deletion"); //delete an entire category $doc->removeTag("company"); $companies = $doc->getTagsList("company"); $this->assertNull($companies, "All companies deleted"); $fruit = $doc->getTagsList("fruit"); $this->assertEquals(count($fruit), 3, "Three fruits returned before deletion"); //delete a single tag $doc->removeTag("fruit", "apple"); $fruit = $doc->getTagsList("fruit"); $this->assertEquals(count($fruit), 2, "Two fruits returned after deleting one"); //delete a single tag $doc->removeTag("fruit", "orange"); $fruit = $doc->getTagsList("fruit"); $this->assertEquals(count($fruit), 1, "One fruits returned after deleting two"); //nothing happens when deleting tag that doesn't exist $doc->removeTag("fruit", "jellybean"); $fruit = $doc->getTagsList("fruit"); $this->assertEquals(count($fruit), 1, "One fruits returned after attempting to delete non-existent fruit"); //delete the last fruit $doc->removeTag("fruit", "banana"); $fruit = $doc->getTagsList("fruit"); $this->assertNull($fruit, "All fruits deleted"); $tags = DataObject::get("DMSTag"); $this->assertEquals($tags->Count(), 0, "No DMS tag objects remain after deletion"); }
function testEmbargoUntilPublished() { $s1 = $this->objFromFixture('SiteTree', 's1'); $doc = new DMSDocument(); $doc->Filename = "test file"; $doc->Folder = "0"; $dID = $doc->write(); $doc->addPage($s1); $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); $this->assertTrue($doc->isHidden(), "Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is still there"); $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"); }
function testUnpublishPageWithAssociatedDocuments() { $s2 = $this->objFromFixture('SiteTree', 's2'); $s2->publish('Stage', 'Live'); $s2ID = $s2->ID; $doc = new DMSDocument(); $doc->Filename = "delete test file"; $doc->Folder = "0"; $doc->write(); $doc->addPage($s2); $s2->doDeleteFromLive(); $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'"); $this->assertEquals($documents->Count(), '1', "Deleting a page from live stage doesn't delete the associated docs," . "even if it's the last page they're associated with"); $s2 = Versioned::get_one_by_stage('SiteTree', 'Stage', sprintf('"SiteTree"."ID" = %d', $s2ID)); $s2->delete(); $documents = DataObject::get("DMSDocument", "\"Filename\" = 'delete test file'"); $this->assertEquals($documents->Count(), '0', "However, deleting the draft version of the last page that a document is " . "associated with causes that document to be deleted as well"); }