I have a VF page with some required fields on it. These fields are not marked as required in the data model, and my controller is not doing any validation on them either. How can I properly test this page so that when save() is called I get the page validation error? Using ApexPages.hasMessages()
returns false in my unit test.
<apex:page standardController="Account" extensions="AccountPortalController">
<apex:pageMessages />
<apex:form >
<apex:pageBlock title="Account Information">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Details">
<apex:inputField value="{!Account.PublicName__c}" required="true"/>
<apex:inputField value="{!Account.Code__c}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlock
</apex:form>
</apex:page>
The controller overrides save() in which some logic is performed before calling StandardController.save().
public class AccountPortalController
{
...
public PageReference save()
{
...
PageReference pr;
try
{
pr = m_stdCon.save();
...
}
catch (Exception e)
{
ApexPages.addMessages(e);
return null;
}
return pr;
}