I need test class for the method below:
This class is written for overriding the view..
public PageReference redirectGroup()
{
if(Url.getSalesforceBaseUrl().toExternalForm() == 'https://hello.cs20.force.com') // Checks for Community URL...
{
Id groupId = ApexPages.currentPage().getParameters().get('id');
Id feedId = ApexPages.currentPage().getParameters().get('fid');
if(feedId != null)
{
PageReference pg = new PageReference('/Community_FeedDetail');
pg.getParameters().put('Id', groupId);
pg.getParameters().put('fid', feedId);
return pg;
}
else
{
PageReference pg = new PageReference('/Community_Groups_Feed');
pg.getParameters().put('Id',groupId );
return pg;
}
}
else
{
PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('id')+'?nooverride=1');
pg.setRedirect(true);
return pg;
}
}
Test class:
@isTest
private class ClearSightGroupRedirectExtensionTest{
public ApexPages.StandardController stdController;
public ClearSightGroupRedirectExtensionTest(ApexPages.StandardController con){
stdController = con;
}
public static testMethod void testRedirect() {
Contact c = new Contact();
c.FirstName = 'Joe';
c.LastName = 'Schmoe';
Insert c;
Test.startTest();
ApexPAges.StandardController sc = new ApexPages.StandardController(c);
ClearSightGroupRedirectExtension redirect = new ClearSightGroupRedirectExtension(sc);
PageReference pageRef = Page.Community_Groups_Feed;
Test.setCurrentPage(pageRef);
redirect.redirectGroup();
}
}
I get 45% coverage with that code, but need to check the condition for community url and want coverage with that block