@isTest
private class QuotePDFControllerTest {

	@isTest static void test_init() {
		Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        insert product1;

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true
        );
        insert standardPrice1;

        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        insert entry1;

        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456'
        );
        insert user;

        Contact contact = new Contact(
            LastName = 'contact',
            AccountId = user.Id
        );
        insert contact;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;

        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 10,
            UnitPrice = 10
        );
        OpportunityLineItem oli2 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 20,
            UnitPrice = 20
        );
        insert new OpportunityLineItem[] {oli1, oli2};

        OpportunityContactRole ocr = new OpportunityContactRole(
            OpportunityId = opp.Id,
            ContactId = contact.Id,
            IsPrimary = true
        );
        insert ocr;

        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname1',
            SetQty1__c = 1
        );
        insert quo;

        QuoteLineItem qli1 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 10,
            UnitPrice = 10,
            Custom_Price__c = 15,
            Set__c = 'set01',
            SingleProduct__c = false
        );
        QuoteLineItem qli2 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 20,
            UnitPrice = 20,
            Custom_Price__c = 25,
            Set__c = 'set01'
        );
        insert new QuoteLineItem[] {qli1, qli2};

        opp.SyncedQuoteId = quo.Id;
        update opp;

        PageReference page = new PageReference('/apex/QuotePDF?Id=' + quo.Id + '&printprice=true');
        System.Test.setCurrentPage(page);
        QuotePDFController controller = new QuotePDFController();

        controller.init();
	}

}