@isTest private class buttonRepairQuotationCtlTest { final static string acc1 = [select id , SobjectType, developername from recordtype where SobjectType='Account' and developername='HP'][0].id; private static Repair__c rpr { get; set; } private static Repair_Quotation__c rq { get; set; } private static void init() { List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科']; if (rectSct.size() == 0) { return; } List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; if (rectDpt.size() == 0) { return; } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM104TestCompany'; upsert company; Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id]; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM104TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id]; depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id]; Product2 prd1 = new Product2(); prd1.ProductCode_Ext__c = 'NFM104Prd1'; prd1.ProductCode = 'NFM104Prd1'; prd1.Repair_Product_Code__c = 'NFM104Prd1_RP'; prd1.Name = 'NFM104Prd1'; prd1.Manual_Entry__c = false; insert prd1; Asset ast = new Asset(); ast.Name = 'NFM104Ast1'; ast.AccountId = depart.Id; ast.Department_Class__c = section.Id; ast.Hospital__c = company.Id; ast.Product2Id = prd1.Id; ast.SerialNumber = 'NFM104SerialNumber'; ast.Guarantee_period_for_products__c = Date.today(); ast.InstallDate = Date.today(); insert ast; Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User us = 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); us.Job_Category__c = '销售服务'; insert us; rpr = new Repair__c(); rpr.SAPRepairNo__c = 'NFM104Rpr1'; rpr.Account__c = depart.Id; rpr.Department_Class__c = section.Id; rpr.Hospital__c = company.Id; rpr.Delivered_Product__c = ast.Id; rpr.SalesOfficeCode_selection__c = '北京'; rpr.Status__c = '1.受理完毕'; rpr.Incharge_Staff__c = us.Id; rpr.Repair_Detail__c = 'test'; //rpr.Exc_work_location__c = true; //rpr.On_site_repair__c = '直送SORC修理'; rpr.On_site_repair__c = 'RC修理'; rpr.work_location_select__c = '杭州办事处'; insert rpr; rq = new Repair_Quotation__c(); rq.Name = 'testNFM104'; rq.Repair__c = rpr.Id; rq.Repair_quotation_status__c = '减价申请填写完毕'; rq.Request_amount_after_discount__c = 5000; rq.Background_Description__c = '测试'; rq.Discount_reason__c = '减价申请'; insert rq; buttonRepairQuotationCtl.init(rq.id); } static testMethod void testMethod1() { init(); buttonRepairQuotationCtl.updateRepairQuotation04(rq.id); } static testMethod void testMethod2() { init(); buttonRepairQuotationCtl.updateRepairQuotation(rq.id); buttonRepairQuotationCtl.updateRepairQuotation02(rq.id); buttonRepairQuotationCtl.updateRepairQuotation03(rq.id); } static testMethod void testMethod3() { init(); buttonRepairQuotationCtl.selectRepairC(rpr.id); } static testMethod void testMethod4() { init(); buttonRepairQuotationCtl.initSelectProfile(UserInfo.getProfileId()); buttonRepairQuotationCtl.updateRepairQuotation(null); buttonRepairQuotationCtl.updateRepairQuotation02(null); buttonRepairQuotationCtl.updateRepairQuotation03(null); } }