You need to sign in to do that
Don't have an account?
Bug in test.setCurrentPage method (does not exist?)
Since the Winter '10 release, any test class where we use
test.setCurrentPage(PageReference ref);
fails with error
Method does not exist or incorrect signature: test.setCurrentPage(System.PageReference)
These are documented as static methods (both setCurrentPage, and setCurrentPageReference). Nothing has changed since writing this code a few months ago, other than me deploying the classes from NA5 to NA7 in order to take advantage of new orgs getting customer portal licenses (deploy was before the Winter '10 rollout).
Adding on, what exactly is the difference between these two methods, because the usage and documentation are identical.
I'll note that I'm not instantiating the PageReference as "system.pagereference" either. I wasn't doing it before, but to test, I tried overriding this with
ApexPages.PageReference ref = new ApexPages.PageReference('/apex/rescuehandleUrlPost');
It seems to ignore me trying to force the ApexPages namespace and throws the same error as above. This is preventing me from packaging a new app that we plan to offer on the AppExchange because all the test methods fail, which prevents the upload. This is on NA7 if that matters. Please help.
It doesn't have to be a class. It can be a variable with small-capital "test". SFDC looks at variable names first, like "Account account = new Account();". I've been there...
ThomasTT
the word "test" only appears as part of method names and test.setcurrentpage in my test class. it doesn't appear at all in the actaul class i'm testing.
this is the code that's on the server right now. if i use eclipse and refresh from server, change one character, and try to resave, same error.
@isTest private class RescueAPIConTests { static testMethod void emailVarTests() { RescueAPICon con = new RescueAPICon(); con.setEmail('test@test.com'); string e = con.getEmail(); system.assertEquals('test@test.com', e); } static testMethod void pwdVarTests(){ RescueAPICon con = new RescueAPICon(); con.setPwd('secret'); string p = con.getPwd(); system.assertEquals('secret',p); } static testMethod void pinVarTests(){ RescueAPICon con = new RescueAPICon(); con.setPin('123456'); string p = con.getPin(); system.assertEquals('123456',p); } static testMethod void constructauthcodeurlTests(){ RescueAPICon con = new RescueAPICon(); string url = con.constructauthcodeurl(); system.assertEquals('https://secure.logmeinrescue.com/api/requestAuthCode.aspx',url); } static testMethod void authCodeReqTests(){ RescueAPICon con = new RescueAPICon(); con.setEmail('test@test.com'); con.setPwd('123456'); HttpRequest req = con.authCodeReq(); system.debug('request: ' + req); } static testMethod void pinCodeReqTests(){ RescueAPICon con = new RescueAPICon(); con.setEmail('test@test.com'); con.setPwd('123456'); HttpRequest req = con.pinCodeReq(); system.debug('request: ' + req); } static testMethod void getStoredAuthCodeTests(){ RescueAPICon con = new RescueAPICon(); string authcode = con.getStoredAuthCode(); } static testMethod void constructpincodeurlTests(){ RescueAPICon con = new RescueAPICon(); string url = con.constructpincodeurl(); system.assertEquals('https://secure.logmeinrescue.com/api/requestPINCode.aspx',url); } static testMethod void generateAuthCodeTests(){ RescueAPICon con = new RescueAPICon(); con.generateAuthCode(); } static testMethod void setAuthCodeForUserTests(){ RescueAPICon con = new RescueAPICon(); con.setAuthCodeForUser('blah'); system.assertEquals('blah',con.getStoredAuthCode()); } static testMethod void clearAuthCodeTests(){ ApexPages.PageReference ref = Page.RescueGenerateAuthCode; RescueAPICon con = new RescueAPICon(); system.assertEquals(null,con.clearAuthCode()); } static testMethod void requestPinTests(){ /* this test should redirect them to the generateauthcode page */ RescueAPICon con = new RescueAPICon(); con.clearAuthCode(); ApexPages.PageReference ref = con.requestPin(); system.assertEquals(ref.getUrl().toLowerCase(),Page.RescueGenerateAuthCode.getUrl().toLowerCase()); /* this test should return null because the autcode is present */ RescueAPICon con1 = new RescueAPICon(); con.setAuthCodeForUser('blah'); ApexPages.PageReference ref1 = con1.requestPin(); system.assertEquals(ref1,null); } static testMethod void linkAccountsTests(){ RescueAPICon con = new RescueAPICon(); con.linkAccounts(); } static testMethod void handleUrlPostTests(){ Case cse = new Case(); insert cse; system.debug('Case info: ' + cse); ApexPages.PageReference ref = new ApexPages.PageReference('/apex/rescuehandleUrlPost'); ref.getParameters().put('Tracking0',cse.id); ref.getParameters().put('SessionID','1234567'); ref.getParameters().put('PickupTime', '2009-07-28 15:10:27'); ref.getParameters().put('ClosingTime','2009-07-28 15:10:27'); ref.getParameters().put('WaitingTime','38'); system.debug('tracking0: ' + ref.getParameters().get('Tracking0')); RescueAPICon con = new RescueAPICon(); test.setCurrentPageReference(ref); con.handleURLPost(); } static testMethod void getShowPinTests(){ RescueAPICon con = new RescueAPICon(); boolean p = con.getShowPin(); } static testMethod void sendEmailTests(){ /* this will test a good email */ ApexPages.PageReference ref = new PageReference('/apex/RescueEmailPIN?pin=123456'); test.setCurrentPageReference(ref); RescueAPICon con = new RescueAPICon(); con.setEmail('test@test.com'); con.setEmailBody('this is a test'); con.sendEmail(); /* this will test email exception handling */ con.setEmail(''); con.sendEmail(); } static testMethod void emailPinTests(){ RescueAPICon con = new RescueAPICon(); ApexPages.PageReference ref = con.emailPin(); test.setCurrentPageReference(ref); } static testMethod void getPinLinkTests(){ RescueApiCon c = new RescueApiCon(); string link = c.getPinLink(); system.assertEquals(link,'https://secure.logmeinrescue.com/R?i=2&Code='); } }
got around this by forcing
to be
instead, but i'm curious as to why this would have happened. is it possible to override/extend the system class in another appexchange package, to cause this?
ugh, now this is happening with my own methods.
this test method
static testMethod void rescueLoginTests1(){
RescueSingleSignOn r = new RescueSingleSignOn();
r.setLoginUrl('');
ApexPages.PageReference ref = new ApexPages.PageReference(r.rescueLogin());
}
which i'm writing to test this method
public ApexPages.PageReference rescueLogin(){
String url = this.getLoginUrl();
if(url != null && url != ''){
if(url.Contains('OK:')){
loginUrl = loginUrl.subString(3);
PageReference ref = new PageReference(loginUrl);
ref.setRedirect(true);
return ref;
}else{
//do nothing and display the message to the user
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'The Rescue API returned an error: ' + loginUrl );
ApexPages.addMessage(msg);
return null;
}
}else{
return null;
}
}
is throwing the same behavior. notice how I'm defining the method that I"m testing as ApexPages.PageReference in the RescueSingleSignOn class. The error being thrown is
Save error: Constructor not defined: [System.PageReference].<Constructor>(System.PageReference) RescueSingleSignOnTests.cls DEV - NEW (lmir)/src/classes line 32 Force.com save problem
this is getting really frustrating. why is it that I can take this block of code from NA1 (our prod org), literally copy and paste it back into the NA7 org (the one causing issues), and have that code throw this error? am i just on the bad end of the fact that they, for whatever reason, implemented both system.pagereference and apexpages.pagereference? if this was the case, it'd prove that the underlying engine validating this syntax is definnitely different on NA1 vs. NA7. same code, different org, different results.