liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@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<Attachment> attachmentList = new list<Attachment>();
        // 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<ContentVersion> versionList = new List<ContentVersion>();
 
        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<Id> idList = new List<Id>();
        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();
        
    }
}