
What you can do is Add one varaable in mail class like below. public boolead isTest {get;set;} // add this varaible in class
public PageReference redirectGroup()
{
if(Url.getSalesforceBaseUrl().toExternalForm() == 'https://hello.cs20.force.com' || isTest ) // 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;
}
}
Then try below test class.
Please let us know if this will help you@isTest
private class ClearSightGroupRedirectExtensionTest
{
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.isTest= false;
redirect.redirectGroup();
Test.StopTest();
}
public static testMethod void testRedirect1()
{
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.isTest= true;
redirect.redirectGroup();
Test.StopTest();
}
}