You need to sign in to do that
Don't have an account?
Beekman
Visual force page test method
Hello,
I have a Visual Force Page that I need to test the controller. Both are attached. I cannot figure out how to create a testmethod to perform test against this page. The controller code needs to execute so it can pass testing.
Any help with code would be appreciated.
Thanks
Visual Page Code:
<apex:page showheader="false" controller="systemStatusController"> <style> ul li { margin: 10px 0; } ul.supportLevels li { margin: 5px 0; list-style: none; width:375px; } ul.supportLevels li span { float:right; } </style> <p class="systemDetails"> <ul> <li>You have <a href="#">{!envrCount}</a> Locations with Envysion <a href="mailto:sales@envysion.com?subject=Add%20a%20Site%20to%20my%20Envysion%20Service">add new location</a></li> <li>You have {!cameraCount} Cameras across your Locations <a href="mailto:sales@envysion.com?subject=New%20Cameras%20for%20a%20Site">add/replace cameras</a></li> <li>Your support levels are: <ul class="supportLevels"> <li>{!notifiesCount} Sites with <i>Envysion Notifies</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li> <li>{!respondsCount} Sites with <i>Envysion Responds</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li> <li>{!maintainsCount} Sites with <i>Envysion Maintains</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li> </ul> </li> </ul> </p> </apex:page>
Class Controller code:
public with sharing class systemStatusController { private User currentUser; private Account currentAccount; private String defAcct; public void setDefaultAccount(String acctID) { this.defAcct = acctID; } public User getCurrentUser() { if(this.currentUser == NULL) { this.currentUser = [SELECT Id, FirstName, LastName, Alias, AccountId FROM User WHERE id = :UserInfo.getUserId()]; } return this.currentUser; } public Account getCurrentAccount() { if(this.currentAccount == NULL) { User curUser = this.getCurrentUser(); String accID = curUser.AccountId; if(accID == NULL || accID == '') { accID = this.defAcct; } this.currentAccount = [SELECT Id, Name FROM Account WHERE Id = :accID]; } return this.currentAccount; } public Integer getEnvrCount() { Account curAcct = this.getCurrentAccount(); Integer envrCount = [SELECT COUNT() FROM Envr__c WHERE Account__c = :curAcct.Id]; return envrCount; } public Integer getCameraCount() { Account curAcct = this.getCurrentAccount(); Integer camCount = [SELECT COUNT() FROM Camera__c WHERE Account__c = :curAcct.Id]; return camCount; } public Integer getNotifiesCount() { Account curAcct = this.getCurrentAccount(); Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Notifies']; return siteCount; } public Integer getRespondsCount() { Account curAcct = this.getCurrentAccount(); Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Responds']; return siteCount; } public Integer getMaintainsCount() { Account curAcct = this.getCurrentAccount(); Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Maintains']; return siteCount; } }
Hi
I can start you off. You don't give much details about the page itself. Does this page require any parameters? It doesn't seem like it from the controller so with this test code I am assuming not.
This approach should allow you to reach your code coverage requirement. Adding some assert tests will make it a safer bet though.
Regards
MellowRen
hello MellowRen,
Yes it needs an Account, which I cannot figure out how to pass it. I normally pass it with this type of code (example from others I have tested)
ApexPages.StandardController sc = new ApexPages.standardController(case_list2.get(0));
CaseExtension ext = new CaseExtension(sc);
List<CaseWrapper> open_cases = ext.getOpenCases();
But I cannot get it to work with this VF page (which is also attached with the previous post)
When I try with your code it comes back with an error that its missing or doesnt have the sObject list.
Thanks
nbeekman
Hmmm, OK, try this addition:
I usually write extensions rather than direct controllers but this should work.
Regards
MellowRen