0

I have a controller that does simple queries of data for a visualforce email template. Not setting or computations, simple queries for list lines.

How do I test this?

public class QuoteLineEmailController {

public id QuoteID {get;set;}

public SBQQ__Quote__c getQuotee() {
return QuoteId == null? null:
    [Select Name, ID, Subtotal_Before_Trade_In__c, Trade_In__c, Total_After_Trade_In__c, Opportunity_ID_Number__c,
                Special_Incentive_Total__c, SBQQ__NetAmount__c, Net_Amount_Internal__c,
                Internal_External_Difference__c, Approved__c, CurrencyIsoCode
     FROM SBQQ__Quote__c 
     WHERE ID = :QuoteID]; 

}    

public list<SBQQ__QuoteLine__c> getQuoteLines() {

    list<SBQQ__QuoteLine__c> QLI = [SELECT  Name, SBQQ__ProductCode__c, SBQQ__Quantity__c, SBQQ__ListPrice__c, 
                                      Discounts__c, SBQQ__NetPrice__c, SBQQ__NetTotal__c, Internal_Discounts__c, Internal_Discount_Type__c, CurrencyIsoCode, 
                                      Net_Unit_Price_Internal__c, SBQQ__Optional__c, Net_Total_Internal__c, Internal_External_Difference__c, Tier__c,
                                      Trade_In_Discount_Grouping__c, Order_Admin_Description__c, Product_Name_and_Description__c
                                    FROM SBQQ__QuoteLine__c 
                                    WHERE SBQQ__Quote__c = :QuoteID ORDER by Name];

    return QLI;                    

    List<SBQQ__QuoteLine__c> result = [SELECT   Name, SBQQ__Optional__c, Trade_In_Discount_Grouping__c
                                    FROM SBQQ__QuoteLine__c 
                                    WHERE SBQQ__Quote__c = :QuoteID ORDER by Name];
    return result;    
}

public Boolean showTradeInSection {
get {
  List<SBQQ__QuoteLine__c> all_qli = getQuoteLines();
  Boolean result = false;
  for (SBQQ__QuoteLine__c qli : all_qli) {
    if (qli.Trade_In_Discount_Grouping__c == 'Additional Discounts') {
      result = true;
      break;
    }
  }
  return result;
}
private set;
}

public Boolean showOptionalSection {
    get {
  List<SBQQ__QuoteLine__c> all_qli = getQuoteLines();
  Boolean result = false;
  for (SBQQ__QuoteLine__c qli : all_qli) {
    if (qli.SBQQ__Optional__c == TRUE) {
      result = true;
      break;
    }
  }
  return result;
}
private set;
}   

public list<SBQQ__QuoteLine__c> getCSVQuoteLines() {

    list<SBQQ__QuoteLine__c> CSVQLI = [SELECT   Name, SBQQ__ProductCode__c, SBQQ__Quantity__c, SBQQ__ListPrice__c, Order_Number__c, 
                                    Price_List_Name__c, PRICE_MODF_NAME2__c, PRICE_MODF_NUMBER2__c, 
                                    User_Description__c, Internal_Discount__c
                                    FROM SBQQ__QuoteLine__c 
                                    WHERE (NOT SBQQ__ProductCode__c LIKE '%Bundle') 
                                       AND SBQQ__Quote__c = :QuoteID ORDER by Name];

    return CSVQLI;                     
}

}
  • 3
    It's the same as writing a unit test for any normal controller: insert your test data, instantiate the controller, call each method, and verify the output. There's no special magic here as opposed to writing any other sort of unit test. – sfdcfox May 5 '17 at 15:50