高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@isTest
private class Event_CommentControllerTest {
    
    private static Event__c e{get;set;}
    private static User u1{get;set;}
    private static User u2{get;set;}
    private static User u3{get;set;}
    private static User u4{get;set;}
    
    /**
     * 初期処理.
     */
    private static void init() {
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        
        u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'olympusTest01@sunbridge.com';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        u1.Post__c = '部长';
        insert u1;
        
        u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'あ';
        u2.Alias = 'あ';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'olympusTest02@sunbridge.com';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.id;
        u2.Job_Category__c = '销售服务';
        u2.Province__c = '東京';
        u2.Post__c = '经理';
        insert u2;
        
        u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'あ';
        u3.Alias = 'あ';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'olympusTest03@sunbridge.com';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = p.id;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '東京';
        u3.Post__c = '';
        insert u3;
        
        u4 = new User(Test_staff__c = true);
        u4.LastName = '_サンブリッジ';
        u4.FirstName = 'あ';
        u4.Alias = 'あ';
        u4.Email = 'olympusTest04@sunbridge.com';
        u4.Username = 'olympusTest04@sunbridge.com';
        u4.CommunityNickname = 'olympusTest04@sunbridge.com';
        u4.IsActive = true;
        u4.EmailEncodingKey = 'ISO-2022-JP';
        u4.TimeZoneSidKey = 'Asia/Tokyo';
        u4.LocaleSidKey = 'ja_JP';
        u4.LanguageLocaleKey = 'ja';
        u4.ProfileId = p.id;
        u4.Job_Category__c = '销售服务';
        u4.Province__c = '東京';
        u4.Post__c = '副总监';
        insert u4;
        
        Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = Date.today();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        
        Datetime dt = Datetime.now();
        e = new Event__c(
            Subject__c = 'test',
            StartDateTime__c = dt,
            DurationInMinutes__c = 60,
            EndDateTime__c = dt.addMinutes(60),
            ActivityDate__c = Date.today(),
            Daily_Report__c = dr.Id
        );
        insert e;
    }
    
    static testMethod void myUnitTest() {
        init();
        
        System.runAs(u1) {
            PageReference pageRef = Page.EventComment;
            pageRef.getParameters().put('Id', e.id);
            Test.setCurrentPage(pageRef);
            
            Event_CommentController ec = new Event_CommentController();
            ec.save();
        }
        
        System.runAs(u2) {
            PageReference pageRef = Page.EventComment;
            pageRef.getParameters().put('Id', e.id);
            Test.setCurrentPage(pageRef);
            
            Event_CommentController ec = new Event_CommentController();
            ec.save();
        }
        
        System.runAs(u3) {
            PageReference pageRef = Page.EventComment;
            pageRef.getParameters().put('Id', e.id);
            Test.setCurrentPage(pageRef);
            
            Event_CommentController ec = new Event_CommentController();
            ec.save();
        }
        
        System.runAs(u4) {
            PageReference pageRef = Page.EventComment;
            pageRef.getParameters().put('Id', e.id);
            Test.setCurrentPage(pageRef);
            
            Event_CommentController ec = new Event_CommentController();
            ec.save();
        }
    }
}