@isTest private class BeforeOPDPDFExtensionControllerTest { private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; // 询价入口测试 static testMethod void myUnitTest() { Product2 product = new Product2( Name='テスト商品'); product.SFDA_Status__c = '有効'; product.Intra_Trade_List_RMB_1__c = 100; product.Intra_Trade_List_RMB_Date1__c = date.today(); product.Intra_Trade_Cost_RMB_1__c = 200; product.Intra_Trade_Cost_RMB_Date1__c = date.today(); product.Manual_Entry__c = false; product.Asset_Model_No__c = '11111'; product.ProductCode = 'OTV-SP1H-NA-12E'; insert product; PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; insert entry; Opportunity opp = new Opportunity(); opp.Name='aiueo'; opp.StageName='contact'; opp.Trade__c = '内貿'; opp.CloseDate=Date.today(); opp.CurrencyIsoCode = 'CNY'; opp.Estimation_List_Price__c = 100; opp.Wholesale_Price__c = 101; opp.Dealer_Final_Price__c = 102; opp.OCM_Agent1_Price__c = 103; opp.Stocking_Price__c = 104; opp.Estimation_No__c = '105'; opp.Estimation_Name__c = '106'; opp.Estimation_Id__c = '107'; insert opp; OpportunityLineItem oppli = new OpportunityLineItem(); oppli.OpportunityId = opp.Id; oppli.Id__c = '110'; oppli.SFDA_Status__c = '有効'; oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十'; oppli.ListPrice__c = 112; oppli.Quantity = 113; oppli.UnitPrice = 114; oppli.UnitPrice__c = 115; oppli.Qty_Unit__c = '116'; oppli.Cost__c = 117; oppli.BSS_Category__c = 'G&R'; oppli.Item_Order__c = 1; oppli.PricebookEntryId = entry.Id; insert oppli; OpportunityLineItem oppli2 = new OpportunityLineItem(); oppli2.OpportunityId = opp.Id; oppli2.Id__c = '110'; oppli2.SFDA_Status__c = '有効'; oppli2.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五'; oppli2.ListPrice__c = 112; oppli2.Quantity = 113; oppli2.UnitPrice = 114; oppli2.UnitPrice__c = 115; oppli2.Qty_Unit__c = '116'; oppli2.Cost__c = 117; oppli2.BSS_Category__c = 'G&R'; oppli2.Item_Order__c = 1; oppli2.PricebookEntryId = entry.Id; insert oppli2; Common_Sequence__c cs = new Common_Sequence__c(); cs.Name = 'test'; cs.EvaluationPDF_NextValue__c = 1; insert cs; PageReference page = new PageReference('/apex/BeforeOPDPDF?oid=' + opp.Id); System.Test.setCurrentPage(page); BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController(); // 初始化测试 controller.startContract(); System.assertEquals(1, controller.printRecords.size()); System.assertEquals(3, controller.printRecords[0].size()); } // 报价依赖入口测试 static testMethod void myUnitTest2() { Product2 product = new Product2( Name='テスト商品'); product.SFDA_Status__c = '有効'; product.Intra_Trade_List_RMB_1__c = 100; product.Intra_Trade_List_RMB_Date1__c = date.today(); product.Intra_Trade_Cost_RMB_1__c = 200; product.Intra_Trade_Cost_RMB_Date1__c = date.today(); product.Manual_Entry__c = false; product.Asset_Model_No__c = '11111'; product.ProductCode = 'OTV-SP1H-NA-12E'; insert product; PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; insert entry; QuoteIrai__c irai = new QuoteIrai__c(); irai.IraiSubject__c = '委托01'; irai.IraiUser__c = null; irai.CurrencyIsoCode = 'USD'; insert irai; QuoteIraiLineItem__c item1 = new QuoteIraiLineItem__c(); item1.SFDA_Status__c = '有効'; item1.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十'; item1.Quantity__c = 1; item1.ListPrice__c = 2150; item1.Product2__c = product.Id; item1.QuoteIrai__c = irai.Id; QuoteIraiLineItem__c item2 = new QuoteIraiLineItem__c(); item2.SFDA_Status__c = '有効'; item2.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五'; item2.Quantity__c = 1; item2.ListPrice__c = 2150; item2.Product2__c = product.Id; item2.QuoteIrai__c = irai.Id; insert new QuoteIraiLineItem__c[] {item1,item2}; Common_Sequence__c cs = new Common_Sequence__c(); cs.Name = 'test'; cs.EvaluationPDF_NextValue__c = 1; insert cs; PageReference page = new PageReference('/apex/BeforeOPDPDF?qid=' + irai.Id); System.Test.setCurrentPage(page); BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController(); // 初始化测试 controller.startContract(); System.assertEquals(1, controller.printRecords.size()); System.assertEquals(3, controller.printRecords[0].size()); } // 消耗品入口测试 static testMethod void myUnitTest3() { Product2 product = new Product2( Name='テスト商品'); product.SFDA_Status__c = '有効'; product.Intra_Trade_List_RMB_1__c = 100; product.Intra_Trade_List_RMB_Date1__c = date.today(); product.Intra_Trade_Cost_RMB_1__c = 200; product.Intra_Trade_Cost_RMB_Date1__c = date.today(); product.Manual_Entry__c = false; product.Asset_Model_No__c = '11111'; product.ProductCode = 'OTV-SP1H-NA-12E'; insert product; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc]; Account company1 = new Account( RecordTypeId = rectCo[0].Id, Name = '病院テスト1' ); insert company1; List dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c]; Account depart1 = new Account(); depart1.RecordTypeId = rectDpt[0].Id; depart1.Name = '*'; depart1.Department_Name__c = '診療科1'; depart1.ParentId = dc1s[0].Id; depart1.Department_Class__c = dc1s[0].Id; depart1.Hospital__c = company1.Id; insert depart1; RecordType rtDoc = [select id from RecordType where DeveloperName =:'Doctor']; Contact con1 = new Contact(); con1.FirstName='ZZ'; con1.LastName = '取引先責任者1'; con1.RecordTypeId = rtDoc.id; con1.AccountId = depart1.Id; con1.Strategic_dept_Class__c = dc1s[0].Id; insert con1; ConsumableSample__c csample = new ConsumableSample__c(Contact__c = con1.Id); insert csample; ConsumableSampleLineItem__c csli = new ConsumableSampleLineItem__c( ConsumableSample__c = csample.Id, Product2__c = product.Id, Name__c = 'テスト商品' ); insert csli; Common_Sequence__c cs = new Common_Sequence__c(); cs.Name = 'test'; cs.EvaluationPDF_NextValue__c = 1; insert cs; PageReference page = new PageReference('/apex/BeforeOPDPDF?csid=' + csample.Id); System.Test.setCurrentPage(page); BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController(); // 初始化测试 controller.startContract(); System.assertEquals(1, controller.printRecords.size()); } }