update('DMSDocument', 'default_download_behaviour', 'open'); $cmsFields = $document->getCMSFields(); $this->assertEquals('open', $cmsFields->dataFieldByName('DownloadBehavior')->Value()); Config::inst()->update('DMSDocument', 'default_download_behaviour', 'download'); $cmsFields = $document->getCMSFields(); $this->assertEquals('download', $cmsFields->dataFieldByName('DownloadBehavior')->Value()); } /** * Ensure that related documents can be retrieved for a given DMS document */ public function testRelatedDocuments() { $document = $this->objFromFixture('DMSDocument', 'document_with_relations'); $this->assertGreaterThan(0, $document->RelatedDocuments()->count()); $this->assertEquals( array('test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'), $document->getRelatedDocuments()->column('Filename') ); } /** * Test the extensibility of getRelatedDocuments */ public function testGetRelatedDocumentsIsExtensible() { DMSDocument::add_extension('StubRelatedDocumentExtension'); $emptyDocument = new DMSDocument; $relatedDocuments = $emptyDocument->getRelatedDocuments(); $this->assertCount(1, $relatedDocuments); $this->assertSame('Extended', $relatedDocuments->first()->Filename); } /** * Ensure that the DMS Document CMS actions contains a grid field for managing related documents */ public function testDocumentHasCmsFieldForManagingRelatedDocuments() { $document = $this->objFromFixture('DMSDocument', 'document_with_relations'); $gridField = $this->getGridFieldFromDocument($document); $gridFieldConfig = $gridField->getConfig(); $this->assertNotNull( 'GridFieldAddExistingAutocompleter', $addExisting = $gridFieldConfig->getComponentByType('GridFieldAddExistingAutocompleter'), 'Related documents GridField has an "add existing" autocompleter' ); $this->assertNull( $gridFieldConfig->getComponentByType('GridFieldAddNewButton'), 'Related documents GridField does not have an "add new" button' ); } /** * Ensure that the related documents list does not include the current document itself */ public function testGetRelatedDocumentsForAutocompleter() { $document = $this->objFromFixture('DMSDocument', 'd1'); $gridField = $this->getGridFieldFromDocument($document); $config = $gridField->getConfig(); $autocompleter = $config->getComponentByType('GridFieldAddExistingAutocompleter'); $autocompleter->setResultsFormat('$Filename'); $jsonResult = $autocompleter->doSearch( $gridField, new SS_HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'test')) ); $this->assertNotContains('test-file-file-doesnt-exist-1', $jsonResult); $this->assertContains('test-file-file-doesnt-exist-2', $jsonResult); $this->assertEquals(array('Title:PartialMatch', 'Filename:PartialMatch'), $autocompleter->getSearchFields()); } /** * @return GridField */ protected function getGridFieldFromDocument(DMSDocument $document) { $documentFields = $document->getCMSFields(); /** @var FieldGroup $actions */ $actions = $documentFields->fieldByName('ActionsPanel'); $gridField = null; foreach ($actions->getChildren() as $child) { /** @var FieldGroup $child */ if ($gridField = $child->fieldByName('RelatedDocuments')) { break; } } $this->assertInstanceOf('GridField', $gridField); return $gridField; } /** * Ensure that HTML is returned containing list items with action panel steps */ public function testGetActionTaskHtml() { $document = $this->objFromFixture('DMSDocument', 'd1'); $document->addActionPanelTask('example', 'Example'); $result = $document->getActionTaskHtml(); $this->assertContains('', $result); $this->assertContains('