function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amoldavskyamoldavsky 

Unable to test a custom controller

I am trying to write unit test to test a class dealing with cookies and it is complaining that is can't find the variable Page.

 

Code:

PageReference page = new Page.Login;
String zisession = '123';
Integer maxAge = 10000;
Cookie ziSessionCookie = new Cookie(ZoomSessionManager.ZISESSION_COOKIE_NAME, zisession, null, maxAge, false);
page.setCookies(new Cookie[]{ziSessionCookie});
Test.setCurrentPage(page);

 IDE Error:

Save error: Variable does not exist: Page.Login

 

I followed the examples provieded by SalesForce but that clearly does not work out:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm

 

I should note that the test code is in a separate unit test class and the Page.Login does work fine in the destination class (ZoomSessionManager.cls), just doesn't exist in the unit test for some reason...

 

 

Any ideas what I might be doing wrong?

Thanks!

 

 

Starz26Starz26

Is the page part of  a different namespace?

amoldavskyamoldavsky

 

hmm that is possible how can I check if that's the case?

Pamela NicholasPamela Nicholas
I realize that this is an old question.  But I ran into this today and thought I'd share my solution.  I hope that will help someone else.  
I think it might be the same solution for the example above. 

I was, like you, using the variable name 'page' for a PageReference variable (line 4).  I think this messed with reference to Page.Login. 
PageReference pageRef = Page.Login;
Test.setCurrentPageReference(pageRef);
LoginController lc = new LoginController();
PageReference page = lc.save();
 
When I changed my variable name from page to myPage, on the 4th line, it all worked fine.
PageReference myPage = cuc.save();
 
The way I found it was commenting out most of my test method and adding one line back in until I found the one that made the error pop up.  When I saw it was that line, I tried changing the name of the variable and that did the trick.