高章伟
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@isTest
private class PersonalEvaluationControllerTest {
    private static UserRole ur1{get;set;}
    private static UserRole ur2{get;set;}
    private static User u1{get;set;}
    private static User u2{get;set;}
    private static User u3{get;set;}
 
    private static void init() {
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        ur1 = [Select Id from UserRole where DeveloperName = 'Quality_Laws_Department'];
        ur2 = [Select Id from UserRole where DeveloperName = 'Quality_Laws_Section'];
        // まず user を作成
        u1 = new User();
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest11@sunbridge.com';
        u1.CommunityNickname = 'あ1';
        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 = '一般';
        u1.Province_select__c = '北京市;河南省';
        u1.UserRoleId = ur1.id;
        u2 = new User();
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'い';
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest12@sunbridge.com';
        u2.CommunityNickname = 'い2';
        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 = '高级';
        u2.Province_select__c = '北京市;河南省';
        u2.UserRoleId = ur2.id;
        u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest13@sunbridge.com';
        u3.CommunityNickname = 'う3';
        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 = '主管';
        u3.Province_select__c = '北京市;河南省';
        u3.UserRoleId = ur2.id;
        insert new List<User>{u1, u2, u3};
 
        // その後、UserRoleを変更
        // http://blog.livedoor.jp/volvic_beer/archives/52285724.html
//        System.runAs(u1) {
//            update new List<User>{u1, u2, u3};
//        }
    }
    
    // 各种条件画面初始化测试
    static testMethod void test1() {
        init();
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs(thisUser) {
            Personal_Evaluation__c pe1 = new Personal_Evaluation__c(Name = '3.业绩管理', Api_Name__c = '3.业绩管理', IsActive__c = true);
            pe1.Report1_1__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report1_2__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report1_3__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report2_1__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report2_2__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report2_3__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report3_1__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report3_2__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report3_3__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report4_1__c = 'select sum(Fiscal_Workdays__c) wt, sum(OPD_target_number_year__c) num from User where Id = :userId';
            pe1.Report4_3__c = 'Select sum(order_number__c) order, sum(Not_collect_money__c) NClct, sum(Not_received_endo_user_contract__c) NCtrc from Statu_Achievements__c where Owner_ID__c = :userId';
            pe1.Report5_1__c = 'Select Sales_forecast_day_BA__c, Sales_forecast_YM_BA__c, Id from Opportunity where OwnerId = :userId and Sales_forecast_day_BA__c < :maxForcastDay';
            pe1.Report1_1_Column__c = 'where GBIC__c=\'GI\' group by GBIC__c';
            pe1.Report1_2_Column__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report1_3_Column__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report5_1_Column__c = 'Order By Sales_forecast_day_BA__c';
            pe1.Tab_Index__c = 0;
            insert pe1;
            
            Personal_Evaluation__c pe2 = new Personal_Evaluation__c(Name = '99', Api_Name__c = '99', IsActive__c = true);
            pe2.Report1_1__c = 'Select Name, Report_Date__c From SMARM__c  limit 1000';
            pe2.Report1_2__c = 'Select Training_date__c, RecordType.Name from Training_test_Result__c  limit 1000';
            pe2.Report1_3__c = 'Select Received_call_day__c, LINK__c, prod__c from case where recordtypeId = \'01210000000QsYp\' limit 1000';
            pe2.Tab_Index__c = 99;
            insert pe2;
        }
        System.runAs(u1) {
            PageReference page = new PageReference('/apex/PersonalEvaluation');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller = new PersonalEvaluationController();
            //初始化
            controller.init();
            System.assertEquals(2, controller.userOpts.size());
            System.assertEquals(u1.Id, controller.selectUser);      // ログインユーザー
            page = new PageReference('/apex/PersonalEvaluation?tabIdx=0&user=' + UserInfo.getUserId());
            System.Test.setCurrentPage(page);
            controller = new PersonalEvaluationController();
            controller.init2();
 
            // 条件追加されたため、件数が減ります
            page = new PageReference('/apex/PersonalEvaluation?province=' + EncodingUtil.urlEncode('河南省', 'UTF-8') + '&tab=0');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller2 = new PersonalEvaluationController();
            //初始化
            controller2.init();
            System.assertEquals(1, controller2.userOpts.size());
            System.assertEquals(u3.Id, controller2.selectUser);
            
            page = new PageReference('/apex/PersonalEvaluation?salesDpt=' + EncodingUtil.urlEncode('3.西北', 'UTF-8') + '&ocm=0');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller3 = new PersonalEvaluationController();
            //初始化
            controller3.init();
            System.assertEquals(1, controller3.userOpts.size());
            System.assertEquals(u3.Id, controller3.selectUser);
            /*
            page = new PageReference('/apex/PersonalEvaluation?text=S:Job_Category__c&cond=notequals&val=销售服务,支援');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller4 = new PersonalEvaluationController();
            //初始化
            controller4.init();
            System.assertEquals(1, controller4.userOpts.size());
            System.assertEquals(u2.Id, controller4.selectUser);
            */
            page = new PageReference('/apex/PersonalEvaluation?user=' + u2.Id);
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller5 = new PersonalEvaluationController();
            //初始化
            controller5.init();
            System.assertEquals(2, controller5.userOpts.size());
            System.assertEquals(u2.Id, controller5.selectUser);
            
            controller5.getProvinceUrl();
            controller5.getSearchJsUrl();
            controller5.getUserUrl();
        }
    }
    
    // RemoteAction方法测试
    static testMethod void test2() {
        init();
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs(thisUser) {
            Personal_Evaluation__c pe1 = new Personal_Evaluation__c(Name = '3.业绩管理', Api_Name__c = '3.业绩管理', IsActive__c = true);
            pe1.Report6_1_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report6_2_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report6_3_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report7_1_Sql__c = 'Select sum(order_number__c) order, sum(Not_collect_money__c) NClct, sum(Not_received_endo_user_contract__c) NCtrc from Statu_Achievements__c where Owner_ID__c = :userId';
            pe1.Report7_3_Sql__c = 'Select Sales_forecast_day_BA__c, Sales_forecast_YM_BA__c, Id from Opportunity where OwnerId = :userId and Sales_forecast_day_BA__c < :maxForcastDay';
            pe1.Report8_1_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report8_2_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report8_3_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report6_1_Sql2__c = 'where GBIC__c=\'GI\' group by GBIC__c';
            pe1.Report6_2_Sql2__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report6_3_Sql2__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report7_3_Sql2__c = 'Order By Sales_forecast_day_BA__c';
            pe1.Tab_Index__c = 0;
            insert pe1;
            
            Personal_Evaluation__c pe2 = new Personal_Evaluation__c(Name = '99', Api_Name__c = '99', IsActive__c = true);
            pe2.Report1_1__c = 'Select Name, Report_Date__c From SMARM__c  limit 1000';
            pe2.Report1_2__c = 'Select Training_date__c, RecordType.Name from Training_test_Result__c  limit 1000';
            pe2.Report1_3__c = 'Select Received_call_day__c, LINK__c, prod__c from case where recordtypeId = \'01210000000QsYp\' limit 1000';
            pe2.Tab_Index__c = 99;
            insert pe2;
        }
        
        System.runAs(u1) {
            PageReference page = new PageReference('/apex/PersonalEvaluation');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller = new PersonalEvaluationController();
            //初始化
            controller.init();
            
            PersonalEvaluationController.saveComment(u1.Id, '01210000000RDuV', 'subject', 'comment', null, '', 'rptName', 'rptNum');
            PersonalEvaluationController.saveComment(u1.Id, '01210000000RDua', 'subject', 'comment', null, 'tabName', '', '');
            PersonalEvaluationController.getPeSettings('3.业绩管理', u1.Id);
            PersonalEvaluationController.getJsonSAP('', u1.Id,'151P');
            PersonalEvaluationController.getJsonOppSum('', u1.Id);
            PersonalEvaluationController.getJsonMBSA('', u1.Id);
            PersonalEvaluationController.getJsonForcast('', u1.Id);
            PersonalEvaluationController.getPersonalEvaluationSettingJson();
            PersonalEvaluationController.getFirstTabIdx();
            controller.getR1InfoList();
            controller.getR2InfoList();
            controller.getR3InfoList();
            controller.getR1InfoColumnList();
            controller.getR2InfoColumnList();
            controller.getR3InfoColumnList();
        }
    }
 
    static testMethod void testPersonalEvaluationCommentListController() {
        PageReference page = new PageReference('/apex/PersonalEvaluationCommentList?user=A&rpt=rpt');
        System.Test.setCurrentPage(page);
        PersonalEvaluationCommentListController controller = new PersonalEvaluationCommentListController();
        controller.getCommentList();
        page = new PageReference('/apex/PersonalEvaluationCommentList?user=A&tab=tab');
        System.Test.setCurrentPage(page);
        controller = new PersonalEvaluationCommentListController();
        controller.getCommentList();
    }
 
    // RemoteAction方法测试  upsertSmarm
    static testMethod void test3() {
        init();
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs(thisUser) {
            Personal_Evaluation__c pe1 = new Personal_Evaluation__c(Name = '3.业绩管理', Api_Name__c = '3.业绩管理', IsActive__c = true);
            pe1.Report6_1_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report6_2_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report6_3_Sql__c = 'select GBIC__c GBIC, sum(Sales_amount_without_tax__c) wt, sum(Qty__c) num from ship__c';
            pe1.Report7_1_Sql__c = 'Select sum(order_number__c) order, sum(Not_collect_money__c) NClct, sum(Not_received_endo_user_contract__c) NCtrc from Statu_Achievements__c where Owner_ID__c = :userId';
            pe1.Report7_3_Sql__c = 'Select Sales_forecast_day_BA__c, Sales_forecast_YM_BA__c, Id from Opportunity__c where OwnerId = :userId and Sales_forecast_day_BA__c < :maxForcastDay';
            pe1.Report8_1_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report8_2_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report8_3_Sql__c = 'Select Sum(Amount_Without_Tax__c) wt, Sum(Number_of_PCL__c) num from Opportunity where OwnerId = :userId';
            pe1.Report6_1_Sql2__c = 'where GBIC__c=\'GI\' group by GBIC__c';
            pe1.Report6_2_Sql2__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report6_3_Sql2__c = 'where GBIC__c=\'BF\' group by GBIC__c';
            pe1.Report7_3_Sql2__c = 'Order By Sales_forecast_day_BA__c';
            pe1.Tab_Index__c = 0;
            insert pe1;
            
            Personal_Evaluation__c pe2 = new Personal_Evaluation__c(Name = '99', Api_Name__c = '99', IsActive__c = true);
            pe2.Report1_1__c = 'Select Name, Report_Date__c From SMARM__c  limit 1000';
            pe2.Report1_2__c = 'Select Training_date__c, RecordType.Name from Training_test_Result__c  limit 1000';
            pe2.Report1_3__c = 'Select Received_call_day__c, LINK__c, prod__c from case where recordtypeId = \'01210000000QsYp\' limit 1000';
            pe2.Tab_Index__c = 99;
            insert pe2;
            SMARM__c s = new SMARM__c(
                OwnerId = '00510000000fSYI',
                Status__c = 'Delete',
                Review_Practitioner__c = UserInfo.getUserId(),
                Review_Target__c = u1.id,
                
                Image1__c = 'img1',
                ReportName1__c = 'report1',
                Comment1__c = 'comment1',
                
                Image3__c = 'img3',
                ReportName3__c = 'report3',
                Comment3__c = 'comment3',
                
                Image4__c = 'img4',
                ReportName4__c = 'report4',
                Comment4__c = 'comment4'
            );
            insert s;
        }
        
        System.runAs(u1) {
            PageReference page = new PageReference('/apex/PersonalEvaluation');
            System.Test.setCurrentPage(page);
            PersonalEvaluationController controller = new PersonalEvaluationController();
            //初始化
            controller.init();
            PersonalEvaluationController.upsertSmarm(u1.Id,'ReportName1__c','11111',true);
            //PersonalEvaluationController.saveComment(u1.Id, '01210000000RDuV', 'subject', 'comment', null, '', 'rptName', 'rptNum');
            //PersonalEvaluationController.saveComment(u1.Id, '01210000000RDua', 'subject', 'comment', null, 'tabName', '', '');
            //PersonalEvaluationController.getPeSettings('3.业绩管理', u1.Id);
            //PersonalEvaluationController.getJsonSAP('', u1.Id);
            //PersonalEvaluationController.getJsonSAPNameJ('', u1.Id,'151P');
            //PersonalEvaluationController.getJsonOppSum('', u1.Id);
            //PersonalEvaluationController.getJsonMBSA('', u1.Id);
            //PersonalEvaluationController.getJsonForcast('', u1.Id);
            //PersonalEvaluationController.getPersonalEvaluationSettingJson();
            //PersonalEvaluationController.getFirstTabIdx();
            //controller.getR1InfoList();
            //controller.getR2InfoList();
            //controller.getR3InfoList();
            //controller.getR1InfoColumnList();
            //controller.getR2InfoColumnList();
            //controller.getR3InfoColumnList();
        }
    }
}