@isTest
|
private class MaintenanceContractPCLControllerTest {
|
|
static testMethod void myUnitTest() {
|
|
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', 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;
|
// 取引先作成
|
List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
if (rectHp.size() == 0) {
|
return;
|
}
|
List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科','診療科 普外科') order by Name desc];
|
if (rectDpt.size() == 0) {
|
return;
|
}
|
Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
|
insert hp1;
|
|
List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id and Department_Class_Label__c in ('消化科', '呼吸科') order by Department_Class_Label__c];
|
|
Account depart1 = new Account();
|
depart1.RecordTypeId = rectDpt[1].Id;
|
depart1.Name = '*';
|
depart1.Department_Name__c = '診療科1';
|
depart1.ParentId = dc1s[0].Id;
|
depart1.Department_Class__c = dc1s[0].Id;
|
depart1.Hospital__c = hp1.Id;
|
|
insert depart1;
|
|
Maintenance_Contract__c mc1 = new Maintenance_Contract__c();
|
mc1.Name = 'mc1';
|
mc1.Past_update_contract__c = true;
|
mc1.RecordTypeId = '01210000000QjeFAAS';
|
mc1.CurrencyIsoCode = 'CNY';
|
mc1.Status__c = '契約';
|
mc1.Hospital__c = hp1.Id;
|
mc1.Department_Class__c = dc1s[0].Id;
|
mc1.Department__c = depart1.Id;
|
mc1.Maintenance_Contract_No__c = 'mc1';
|
mc1.Contract_Conclusion_Date__c = Date.today();
|
mc1.Contract_End_Date__c = Date.today().addDays(1);
|
mc1.SalesOfficeCode_selection__c = '北京RC';
|
|
Maintenance_Contract__c mc2 = new Maintenance_Contract__c();
|
mc2.Name = 'mc2';
|
mc2.Past_update_contract__c = true;
|
mc2.RecordTypeId = '01210000000QjeFAAS';
|
mc2.CurrencyIsoCode = 'CNY';
|
mc2.Status__c = '契約';
|
mc2.Hospital__c = hp1.Id;
|
mc2.Department_Class__c = dc1s[0].Id;
|
mc2.Department__c = depart1.Id;
|
mc2.Maintenance_Contract_No__c = 'mc2';
|
mc2.Contract_Conclusion_Date__c = Date.today();
|
mc2.Contract_End_Date__c = Date.today().addDays(1);
|
mc2.SalesOfficeCode_selection__c = '北京RC';
|
|
insert new Maintenance_Contract__c[] {mc1,mc2};
|
|
PageReference page = new PageReference('/apex/MaintenanceContractPCL');
|
System.Test.setCurrentPage(page);
|
MaintenanceContractPCLController controller = new MaintenanceContractPCLController();
|
// 初始化测试
|
controller.init();
|
|
System.assertEquals(2, controller.oppRecords.size());
|
|
// 排序测试
|
controller.sortKey = '1';
|
controller.sortTable();
|
controller.sortTable();
|
|
// 检索测试
|
controller.text = 'S:HP__c';
|
controller.condition = 'equals';
|
controller.value = 'testHp1';
|
controller.searchOpp();
|
controller.condition = 'contains';
|
controller.value = 'test 1';
|
controller.searchOpp();
|
|
System.assertEquals(2, controller.oppRecords.size());
|
|
// 保存测试
|
controller.oppRecords[0].changeFlg = '1';
|
controller.save();
|
|
// 返回测试
|
controller.cancel();
|
}
|
|
static testMethod void myUnitTest2() {
|
|
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', 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;
|
// 取引先作成
|
List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
if (rectHp.size() == 0) {
|
return;
|
}
|
List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科','診療科 普外科') order by Name desc];
|
if (rectDpt.size() == 0) {
|
return;
|
}
|
Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
|
insert hp1;
|
|
List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id and Department_Class_Label__c in ('消化科', '呼吸科') order by Department_Class_Label__c];
|
|
Account depart1 = new Account();
|
depart1.RecordTypeId = rectDpt[1].Id;
|
depart1.Name = '*';
|
depart1.Department_Name__c = '診療科1';
|
depart1.ParentId = dc1s[0].Id;
|
depart1.Department_Class__c = dc1s[0].Id;
|
depart1.Hospital__c = hp1.Id;
|
|
insert depart1;
|
|
Maintenance_Contract__c mc1 = new Maintenance_Contract__c();
|
mc1.Name = 'mc1';
|
mc1.Past_update_contract__c = true;
|
mc1.RecordTypeId = '01210000000QjeFAAS';
|
mc1.CurrencyIsoCode = 'CNY';
|
mc1.Status__c = '契約';
|
mc1.Hospital__c = hp1.Id;
|
mc1.Department_Class__c = dc1s[0].Id;
|
mc1.Department__c = depart1.Id;
|
mc1.Maintenance_Contract_No__c = 'mc1';
|
mc1.Contract_Conclusion_Date__c = Date.today();
|
mc1.Contract_Start_Date__c = Date.today().addDays(-1);
|
mc1.Contract_End_Date__c = Date.today().addDays(1);
|
mc1.SalesOfficeCode_selection__c = '北京RC';
|
|
Maintenance_Contract__c mc2 = new Maintenance_Contract__c();
|
mc2.Name = 'mc2';
|
mc2.Past_update_contract__c = true;
|
mc2.RecordTypeId = '01210000000QjeFAAS';
|
mc2.CurrencyIsoCode = 'CNY';
|
mc2.Status__c = '契約';
|
mc2.Hospital__c = hp1.Id;
|
mc2.Department_Class__c = dc1s[0].Id;
|
mc2.Department__c = depart1.Id;
|
mc2.Maintenance_Contract_No__c = 'mc2';
|
mc2.Contract_Conclusion_Date__c = Date.today();
|
mc2.Contract_Start_Date__c = Date.today().addDays(-1);
|
mc2.Contract_End_Date__c = Date.today().addDays(1);
|
mc2.SalesOfficeCode_selection__c = '北京RC';
|
|
insert new Maintenance_Contract__c[] {mc1,mc2};
|
|
PageReference page = new PageReference('/apex/MaintenanceContractPCL?uid=' + UserInfo.getUserId() + '&hpid=' + hp1.Id);
|
System.Test.setCurrentPage(page);
|
MaintenanceContractPCLController controller = new MaintenanceContractPCLController();
|
// 初始化测试
|
controller.init();
|
|
System.assertEquals(2, controller.oppRecords.size());
|
|
// 保存测试
|
controller.oppRecords[0].changeFlg = '1';
|
controller.saveType = '1';
|
controller.save();
|
|
controller.oppRecords[0].changeFlg = '1';
|
controller.saveType = '2';
|
controller.save();
|
|
// 检索测试
|
controller.text = 'S:HP__c';
|
controller.condition = 'notequals';
|
controller.value = '';
|
controller.searchOpp();
|
|
controller.dateField = 'Contract_Start_Date__c';
|
controller.con1.Birthdate = Date.today().addDays(-2);
|
controller.con2.Birthdate = Date.today();
|
controller.text = 'S:HP__c';
|
controller.condition = 'starts with';
|
controller.value = 'test';
|
controller.searchOpp();
|
|
System.assertEquals(2, controller.oppRecords.size());
|
}
|
}
|