@isTest private class QLMAttachmentPreviewControllerTest { static testMethod void testMethod1() { Tender_information__c Ten = new Tender_information__c(); Ten.Name = '123456'; Ten.ProjectId__c = '38_99df2844cf784982acdc61d00d7a7dbb'; Ten.Overstep_12M_infofile__c = 'http://'; insert Ten; // list attachmentList = new list(); // Attachment attach = new Attachment(); // attach.Name = 'A-65224941-20200923--1.docx'; // Blob bodyBlob = Blob.valueOf('Unit Test Attachment Body'); // attach.body = bodyBlob; // attach.parentId = Ten.id; // attach.ContentType = 'application/pdf'; // attachmentList.add(attach); // // insert attach; // Attachment attach1 = new Attachment(); // attach1.Name = 'H-65224945-20200928--15.jpg'; // Blob bodyBlob1 = Blob.valueOf('Unit Test Attachment Body'); // attach1.body = bodyBlob1; // attach1.parentId = Ten.id; // attach1.ContentType = 'application/pdf'; // attachmentList.add(attach1); // insert attachmentList; List versionList = new List(); ContentVersion version = new ContentVersion(); Blob bodyBlob1 = Blob.valueOf('Unit Test Attachment Body'); version.VersionData = bodyBlob1; version.Title = 'test'; version.PathOnClient = 'test'; version.ContentLocation = 's'; version.Description = 's;0;0;2024-02-23'; versionList.add(version); insert versionList; List idList = new List(); for (ContentVersion newVersion : versionList) { idList.add(newVersion.Id); } versionList = [select ContentDocumentId,Title from ContentVersion where Id in: idList]; ContentDocumentLink cDocLink = new ContentDocumentLink(); cDocLink.ContentDocumentId = versionList[0].ContentDocumentId; cDocLink.LinkedEntityId = Ten.id; cDocLink.ShareType = 'V'; cDocLink.Visibility = 'AllUsers'; insert cDocLink; PageReference page = new PageReference('/apex/QLMAttachmentPreview?parentId=' + Ten.id); System.Test.setCurrentPage(page); QLMAttachmentPreviewController apc = new QLMAttachmentPreviewController(); //初始化测试 apc.gethtmlvalue(); apc.init(); } }