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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
@isTest
private class LeadIntentionControllerTest {
    public static String rectIs = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Internal_staff').getRecordTypeId();
    
    @testSetup
    static void setUp(){
        TestDataUtility.CreatePIPolicyConfigurations( new string[]{'Inquiry_form__c'});
    }
    
    static testMethod void testMethod1() {
        LeadIntentionController.forTest();
        // PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__c');
        // insert config1;
        PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__cV2');
        insert config2;
        PI_Policy_Configuration__c config3 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Contact');
        insert config3;
        // PI_Field_Policy_Detail__c pfpd1 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config1.Id, Enable_Encrypt__c=true);
        // insert pfpd1;
        PI_Field_Policy_Detail__c pfpd2 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config2.Id, Enable_Encrypt__c=true);
        insert pfpd2;
        PI_Field_Policy_Detail__c pfpd3 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config3.Id, Enable_Encrypt__c=true);
        insert pfpd3;
        //医院
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        //科室
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
 
 
 
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
 
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
 
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
        Contact testRectIsContacts = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='testRectIsContacts',RecordTypeId = rectIs, accountId = dpt1.Id);
        insert testRectIsContacts;
 
        // Contact contact2 = new Contact();
        // contact2.AccountId = dpt1.Id;
        // contact2.FirstName = '責任者';
        // contact2.LastName = 'test1经销商';
        // insert contact2;
 
        Inquiry_form__c inquiryform = new Inquiry_form__c();
        // inquiryform.Name = '2019102101';
        inquiryform.Hospital_Name__c = dpt1.Id;
        List<Account> dpecList = [select Id,Department_Class__c from Account where Id =: dpt1.Id];
        inquiryform.Department_Class__c = dpecList[0].Department_Class__c;
        inquiryform.Status__c ='01.未跟进';
        inquiryform.Company__c ='北京某某某测试公司';
        inquiryform.Family_Name__c ='靳';
        inquiryform.Opportunity_Division__c = '询价';
        inquiryform.Contact_Name__c = testRectIsContacts.Id;
        inquiryform.Reasons_options__c  ='已经有询价';
        inquiryform.Phone__c = '13844756322';
        inquiryform.Product1__c = '超声';
        inquiryform.Request1__c = '需要报价';
        insert inquiryform;
 
        PageReference page = new PageReference('/apex/LeadIntention');
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
 
           
        // LeadIntentionController conTest = new LeadIntentionController(new ApexPages.StandardController(dpt));
        LeadIntentionController conTest = new LeadIntentionController();
        System.Test.startTest();
        conTest.inquiryformId = inquiryform.Id;
 
        conTest.init();
        conTest.text = '';
        conTest.condition = 'equals';
        conTest.value='未跟进';
  
        conTest.text2 = 'S:Phone__c';
        conTest.condition2 = 'contains';
        conTest.value2 = '123 ';
  
        conTest.text3 = 'S:Opportunity_Division__c';
        conTest.condition3 = 'equals';
        conTest.value3 = '询价';
 
        conTest.searchOpp();
        conTest.sortTable();
        conTest.save();
        conTest.cancel();
 
      // conTest.pclInfos.reasonFlg ='1';
        conTest.saveInquiryOpts();
        
    }
    //测试 选择一些筛选条件
    static testMethod void testMethod2() {
        PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__cV2');
        insert config2;
        PI_Policy_Configuration__c config3 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Contact');
        insert config3;
        // PI_Field_Policy_Detail__c pfpd1 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config1.Id, Enable_Encrypt__c=true);
        // insert pfpd1;
        PI_Field_Policy_Detail__c pfpd2 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config2.Id, Enable_Encrypt__c=true);
        insert pfpd2;
        PI_Field_Policy_Detail__c pfpd3 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config3.Id, Enable_Encrypt__c=true);
        insert pfpd3;
                 //医院
      List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        //科室
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        
    Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
    User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      insert hpOwner;
      User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      insert hpOwner2;
 
 
 
      Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
 
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
 
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
        // Contact contact2 = new Contact();
        // contact2.AccountId = dpt1.Id;
        // contact2.FirstName = '責任者';
        // contact2.LastName = 'test1经销商';
        // insert contact2;
        Contact testRectIsContacts1 = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='testRectIsContacts',RecordTypeId = rectIs, accountId = dpt1.Id);
        insert testRectIsContacts1;
 
        Inquiry_form__c inquiryform = new Inquiry_form__c();
        // inquiryform.Name = '2019102101';
        inquiryform.Hospital_Name__c = dpt1.Id;
        List<Account> dpecList = [select Id,Department_Class__c from Account where Id =: dpt1.Id];
        inquiryform.Department_Class__c = dpecList[0].Department_Class__c;
        inquiryform.Status__c ='01.未跟进';
        inquiryform.Company__c ='北京某某某测试公司';
        inquiryform.Family_Name__c ='靳';
        inquiryform.Opportunity_Division__c = '询价';
        inquiryform.Contact_Name__c = testRectIsContacts1.Id;
        inquiryform.Reasons_options__c  ='已经有询价';
        inquiryform.Phone__c = '13844756322';
        inquiryform.Product1__c = '超声';
        inquiryform.Request1__c = '需要报价';
        insert inquiryform;
 
        PageReference page = new PageReference('/apex/LeadIntention');
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
 
         
      // LeadIntentionController conTest = new LeadIntentionController(new ApexPages.StandardController(dpt));
      LeadIntentionController conTest = new LeadIntentionController();
      System.Test.startTest();
      conTest.inquiryformId = inquiryform.Id;
      conTest.savetype = '2';
      conTest.accSearch = '大连';
      conTest.ownerSearch = '刘';
 
      conTest.init();
      conTest.saveInquiryform();
      conTest.text = 'S:Status__c';
      conTest.condition = 'equals';
      conTest.value='未跟进';
 
      conTest.text2 = 'S:Phone__c';
      conTest.condition2 = 'contains';
      conTest.value2 = '123 ';
 
      conTest.text3 = 'S:Opportunity_Division__c';
      conTest.condition3 = 'equals';
      conTest.value3 = ',';
 
 
 
      conTest.searchOpp();
      conTest.sortTable();
      conTest.save();
      conTest.cancel();  
 
      // conTest.pclInfos.reasonFlg ='1';
      conTest.saveInquiryOpts();
 
        
    }
    static testMethod void testMethod3() {
        PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__cV2');
        insert config2;
        PI_Policy_Configuration__c config3 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Contact');
        insert config3;
        // PI_Field_Policy_Detail__c pfpd1 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config1.Id, Enable_Encrypt__c=true);
        // insert pfpd1;
        PI_Field_Policy_Detail__c pfpd2 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config2.Id, Enable_Encrypt__c=true);
        insert pfpd2;
        PI_Field_Policy_Detail__c pfpd3 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config3.Id, Enable_Encrypt__c=true);
        insert pfpd3;
                 //医院
      List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        //科室
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        
    Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
    User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      insert hpOwner;
      User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      insert hpOwner2;
 
 
 
      Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
 
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
 
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
        // Contact contact2 = new Contact();
        // contact2.AccountId = dpt1.Id;
        // contact2.FirstName = '責任者';
        // contact2.LastName = 'test1经销商';
        // insert contact2;
        Contact testRectIsContacts1 = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='testRectIsContacts',RecordTypeId = rectIs, accountId = dpt1.Id);
        insert testRectIsContacts1;
        List<Inquiry_form__c> queryListForMoney = new List<Inquiry_form__c>();
 
        Inquiry_form__c inquiryform = new Inquiry_form__c();
        // inquiryform.Name = '2019102101';
        inquiryform.Hospital_Name__c = dpt1.Id;
        List<Account> dpecList = [select Id,Department_Class__c from Account where Id =: dpt1.Id];
        inquiryform.Department_Class__c = dpecList[0].Department_Class__c;
        inquiryform.Status__c ='01.未跟进';
        inquiryform.Company__c ='北京某某某测试公司';
        inquiryform.Family_Name__c ='靳';
        inquiryform.Opportunity_Division__c = '询价';
        inquiryform.Contact_Name__c = testRectIsContacts1.Id;
        inquiryform.Reasons_options__c  ='已经有询价';
        inquiryform.Phone__c = '13844756322';
        inquiryform.Product1__c = '超声';
        inquiryform.Request1__c = '需要报价';
        insert inquiryform;
        queryListForMoney.add(inquiryform);
 
        PageReference page = new PageReference('/apex/LeadIntention');
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
 
         
      // LeadIntentionController conTest = new LeadIntentionController(new ApexPages.StandardController(dpt));
      LeadIntentionController conTest = new LeadIntentionController();
      System.Test.startTest();
      conTest.inquiryformId = inquiryform.Id;
      conTest.savetype = '2';
      conTest.accSearch = '大连';
      conTest.ownerSearch = '刘';
 
      conTest.init();
      conTest.saveInquiryform();
      conTest.text = 'S:Status__c';
      conTest.condition = 'equals';
      conTest.value='';
 
      conTest.text2 = 'S:Phone__c';
      conTest.condition2 = 'contains';
      conTest.value2 = '123 ';
 
      conTest.text3 = 'S:Opportunity_Division__c';
      conTest.condition3 = 'equals';
      conTest.value3 = '询价';
 
 
 
      conTest.searchOpp();
      conTest.sortTable();
      conTest.save();
      conTest.cancel(); 
      // 创建一个Inquiry_form__c记录用于测试
      Inquiry_form__c record = new Inquiry_form__c();
              
      // 实例化PCLInfo类,并传入测试记录
      LeadIntentionController.PCLInfo pclInfo = new LeadIntentionController.PCLInfo(record);
      
      // 验证初始化后的属性值
      System.assertEquals(record, pclInfo.rec);
      System.assertEquals(true, pclInfo.canEdit);
      System.assertEquals(false, pclInfo.hasError);
      System.assertEquals(false, pclInfo.hasFieldError);
      System.assertEquals(0, pclInfo.lineNo);
      System.assertEquals('0', pclInfo.changeFlg);
      System.assertEquals('0', pclInfo.reasonFlg);
      System.assertEquals('chk0', pclInfo.chk);
      
      // 修改属性值进行进一步测试
      pclInfo.changeFlg = '1';
      pclInfo.reasonFlg = '1';
      pclInfo.chk = 'chk1';
      
      // 验证修改后的属性值
      System.assertEquals('1', pclInfo.changeFlg);
      System.assertEquals('1', pclInfo.reasonFlg);
      System.assertEquals('chk1', pclInfo.chk);
 
      // conTest.pclInfos.reasonFlg ='1';
      conTest.saveInquiryOpts();
 
        
    }
}