@isTest
public class summonsPDFControllerTest {
	static testMethod void summonsPDFControllerTest(){
		Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
		List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
		user MyUser_Test;
		Account myAccount1;
		Account myAccount2;
		Product2__c pro1;
		User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
		System.runAs(thisUser){
			Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			Product2 prod03 = new Product2(Name='Test03',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			Product2 prod04 = new Product2(Name='Test04',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			Product2 prod05 = new Product2(Name='Test05',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			Product2 prod06 = new Product2(Name='Test06',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
			insert new Product2[] {prod01,prod02,prod03,prod04,prod05,prod06};

			pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
			Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
			Product2__c pro5 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
			Product2__c pro3 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
			Product2__c pro4 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
			Product2__c pro6 = new Product2__c(Name='Pro006',OT_CODE_Text__c='Test006',Product2__c = prod06.Id);
			insert new Product2__c[] {pro4, pro5,pro6,pro1, pro2, pro3};

			myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id);
			myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id);
			insert myAccount1;
			insert myAccount2;
			Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
			insert core;
			MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com');
			insert MyUser_Test;
			Product2__Share dcTS1 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro1.id );
        	insert dcTS1;
		}
		system.runAs(MyUser_Test){

			Consumable_order__c zsdTest = new Consumable_order__c();
			zsdTest.Name = 'testMing';
			zsdTest.Summons_Sale_Status__c= '批准';
			zsdTest.SummonsStatus_c__c = '草案中';
			zsdTest.SummonsForDirction__c ='二级经销商备货';
			zsdTest.Order_type__c = '订单';
			zsdTest.Dealer_Info__c = myAccount2.id;
			zsdTest.RecordTypeid = System.Label.RT_ConOrder_Order;
			zsdTest.Order_type__c = '传票';
			insert zsdTest;
			Consumable_orderdetails__c Good = new Consumable_orderdetails__c();
			Good.recordtypeid= System.Label.RT_ConOrderDetail1_Order;
			Good.Name = 'ZSD0001';
			Good.Consumable_Product__c = pro1.Id;
			Good.Shipment_Count__c = 1;
			Good.Consumable_order__c = zsdTest.id;
			Oly_TriggerHandler.bypass('ConsumableAssetHander');
			insert Good;
			Consumable_order_details2__c Orderdet =new Consumable_order_details2__c();
			 Orderdet.Name = 'OCM_01_001001';
            Orderdet.Consumable_order_minor__c = zsdTest.Id;
            Orderdet.Bar_Code__c = '11111';
            Orderdet.Arrive_date__c = Date.today();
            Orderdet.Lose_Flag__c = false;
            Orderdet.Send_Date__c = null;
            Orderdet.Used_date__c =null;
			Oly_TriggerHandler.bypass('ConsumableAssetHander');
			insert Orderdet;
			PageReference page = new PageReference('/apex/summonsPDF?ESetid='+zsdTest.id);
			page.setRedirect(true);
			System.Test.setCurrentPage(page);
			summonsPDFController SDF = new summonsPDFController();
			SDF.init();
			system.assertEquals(1, SDF.consumableorderdetailsRecords.size());
		}
	}
}