I cannot get this controller's test class to pass at all. Please help me understand why I cannot write a test for ApexPages.currentPage().getParameters().get(). I assume the SOQL string should pass the test as I insert a record before it runs.
Controller
public class tablestagingController {
public ApexPages.StandardController controller;
public tablestagingController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference saveanddirect() {
String thfirstname = ApexPages.currentPage().getParameters().get('thfirstname');
String thlastname = ApexPages.currentPage().getParameters().get('thlastname');
controller.save();
Id recordid = controller.getId();
String recordname = [SELECT id, Name FROM Reservation_Header__c WHERE id = :recordid].Name;
PageReference a = new PageReference('http://test.force.com/reservetable/Staging_table_1?Name='+ recordid + '&00N1a000008FU6Z=' + thfirstname + '&00N1a000008FU6U=' + thlastname + '&00NP0000000nbCH=' + recordname);
a.setRedirect(true);
return a;
}
}
Test Class
@isTest
public class testclasstablestaging{
public static testMethod void testtablestagingController(){
Reservation_Header__c a = new Reservation_Header__c (First_Name__c = 'test1', Last_Name__c = 'test2', Phone__c = '703');
insert a;
PageReference pageRef1 = new PageReference('/apex/Reservation_Header_KFAK_5');
apexpages.currentpage().getparameters().put('thfirstname' , a.First_Name__c);
apexpages.currentpage().getparameters().put('thlastname' , a.Last_Name__c);
Test.setCurrentPageReference(pageRef1);
ApexPages.StandardController c = new ApexPages.standardController(a);
tablestagingController b = new tablestagingController(c);
System.assert(b != null);
}
}
b.saveanddirect()
from your test to get that code executed.