@isTest public with sharing class AccChangeApprovalResponseControllerTest { static User setNewUser(String firstName, String lastName, String aName, String email) { User user = new User(Test_staff__c = true); user.LastName = ' ' + lastName; user.FirstName = firstName; user.Alias = aName; user.Email = email; user.Username = 'Olympus' + email; user.CommunityNickname = aName; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_SystemAdmin; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Use_Start_Date__c = Date.today().addMonths(-6); insert user; return user; } static testMethod void test_method_one() { User user1 = setNewUser('ztest01', 'User001', 'Zhang001', 'test001@excemaple.com'); User user2 = setNewUser('ztest02', 'User002', 'Zhang002', 'test002@excemaple.com'); User user3 = setNewUser('ztest03', 'User003', 'Zhang003', 'test003@excemaple.com'); User user4 = setNewUser('ztest04', 'User004', 'Zhang004', 'test004@excemaple.com'); User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com'); User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com'); // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; hospital.Is_Active__c = '有効'; hospital.OwnerId = toUser.Id; //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start // insert hospital; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert hospital; } } //WLIG-BS2CJW ---20200807---update By rentongxiao ---End //新建 客户变更申请 Account_Delay_Apply__c ada = new Account_Delay_Apply__c(); ada.Hospital__c = hospital.Id; ada.ChangeReason__c = '地址错误'; ada.Is_Active__c = '申请中'; ada.Is_upload_file__c = true; ada.OpenWindow__c = user5.Id; ada.InstitutionalType__c = '非医疗机构'; ada.CreatedById = toUser.Id; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert ada; } } // 画面迁移--沟通应答画面 PageReference page = new PageReference('/apex/AccChangeApprovalResponseControllerPopUp?accid=' + ada.Id + '&type=response2system'); System.Test.setCurrentPage(page); AccChangeApprovalResponseController controller = new AccChangeApprovalResponseController(); controller.init(); controller.cc.ResponseNew__c = 'test goutong'; // 保存 controller.saveBtn(); } static testMethod void test_method_two() { User user1 = setNewUser('ztest01', 'User001', 'Zhang001', 'test001@excemaple.com'); User user2 = setNewUser('ztest02', 'User002', 'Zhang002', 'test002@excemaple.com'); User user3 = setNewUser('ztest03', 'User003', 'Zhang003', 'test003@excemaple.com'); User user4 = setNewUser('ztest04', 'User004', 'Zhang004', 'test004@excemaple.com'); User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com'); User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com'); // 病院を作る // Account hospital = new Account(); // hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; // hospital.Name = 'test hospital'; // hospital.Is_Active__c = '申请中'; // hospital.OwnerId = toUser.Id; // //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start // // insert hospital; // if (Test.isRunningTest()) { // System.runAs(new User(Id = UserInfo.getUserId())){ // insert hospital; // } // } //WLIG-BS2CJW ---20200807---update By rentongxiao ---End // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; hospital.Is_Active__c = '有効'; hospital.OwnerId = toUser.Id; //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start // insert hospital; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert hospital; } } //WLIG-BS2CJW ---20200807---update By rentongxiao ---End //新建 客户变更申请 Account_Delay_Apply__c ada = new Account_Delay_Apply__c(); ada.Hospital__c = hospital.Id; ada.ChangeReason__c = '地址错误'; ada.Is_Active__c = '申请中'; ada.Is_upload_file__c = true; ada.OpenWindow__c = user5.Id; ada.InstitutionalType__c = '非医疗机构'; ada.CreatedById = toUser.Id; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert ada; } } // 画面迁移--沟通应答画面 PageReference page = new PageReference('/apex/AccChangeApprovalResponseControllerPopUp?accid=' + ada.Id + '&type=response2user'); System.Test.setCurrentPage(page); AccChangeApprovalResponseController controller2 = new AccChangeApprovalResponseController(new ApexPages.StandardController(ada)); controller2.init(); controller2.saveBtn(); // 发送按钮 controller2.cc.Response__c = 'test goutong'; controller2.cc.ResponseNew__c = 'test .......'; controller2.cc.Response_Cc_User1__c = user1.Id; controller2.cc.Response_Cc_User2__c = user2.Id; controller2.cc.Response_Cc_User3__c = user3.Id; controller2.cc.Response_Cc_User4__c = user4.Id; controller2.cc.Response_Cc_User5__c = user5.Id; controller2.saveBtn(); } static testMethod void test_method_three() { User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com'); User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com'); // 病院を作る // Account hospital = new Account(); // hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; // hospital.Name = 'test hospital'; // hospital.Is_Active__c = '申请中'; // hospital.OwnerId = toUser.Id; // //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start // // insert hospital; // if (Test.isRunningTest()) { // System.runAs(new User(Id = UserInfo.getUserId())){ // insert hospital; // } // } //WLIG-BS2CJW ---20200807---update By rentongxiao ---Start // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; hospital.Is_Active__c = '有効'; hospital.OwnerId = toUser.Id; //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start // insert hospital; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert hospital; } } //WLIG-BS2CJW ---20200807---update By rentongxiao ---End //新建 客户变更申请 Account_Delay_Apply__c ada = new Account_Delay_Apply__c(); ada.Hospital__c = hospital.Id; ada.ChangeReason__c = '地址错误'; ada.Is_Active__c = '申请中'; ada.Is_upload_file__c = true; ada.OpenWindow__c = user5.Id; ada.InstitutionalType__c = '非医疗机构'; ada.CreatedById = toUser.Id; if (Test.isRunningTest()) { System.runAs(new User(Id = UserInfo.getUserId())){ insert ada; } } // 画面迁移--沟通应答画面 PageReference page = new PageReference('/apex/AccChangeApprovalResponseControllerPopUp?accid=' + ada.Id + '&type=response2user'); System.Test.setCurrentPage(page); AccChangeApprovalResponseController controller3 = new AccChangeApprovalResponseController(); controller3.init(); controller3.cc.Response__c = 'test goutong'; controller3.ra.CreatedBy.Email = '111111111111'; // 发送按钮 controller3.saveBtn(); } }