LightningSelfRegisterControllerTest. testSiteAsContainerEnabled() method returning null and not passing tests when org has mydomain
Last updated 2017-06-10 ·Reference W-3721128 ·Reported By 9 users
Summary
LightningSelfRegisterControllerTest.apex is the sample Apex class we gave to customer for LightningSelfRegisterController,
LightningSelfRegisterControllerTest.testSiteAsContainerEnabled() doesn't pass when org has my domain.
Repro
In demo org you can recreate the issue if you enable communities and choose the Template Salesforce Tabs + Visualforce
1.In the LightningSelfRegisterController add the @TestVisible
For Example:
@TestVisible
private static boolean siteAsContainerEnabled(Id networkId) {
Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(networkId,'');
return authConfig.isCommunityUsingSiteAsContainer();
}
2. Create a test class called LightningSelfRegisterControllerTest with the following code:
@IsTest(SeeAllData = true)
public with sharing class LightningSelfRegisterControllerTest {
/* Verifies the default value of siteAsContainerEnabled method. */
@IsTest
static void testSiteAsContainerEnabled() {
String networkId = Network.getNetworkId();
System.assertNotEquals(null, LightningSelfRegisterController.siteAsContainerEnabled(networkId));
}
}
3. Click the Test Run button.
4.Wait till the error generates System.AssertException: Assertion Failed:
Workaround
In LightningSelfRegisterController, change
/*@TestVisible
private static boolean siteAsContainerEnabled(Id networkId) {
Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(networkId,'');
System.debug('Auth configuration: ' + authConfig);
return authConfig.isCommunityUsingSiteAsContainer();
}*/
@TestVisible
private static boolean siteAsContainerEnabled(String communityUrl) {
Auth.AuthConfiguration authConfig = new Auth.AuthConfiguration(communityUrl,'');
System.debug('Auth configuration: ' + authConfig);
return authConfig.isCommunityUsingSiteAsContainer();
}
In LightningSelfRegisterControllerTest,
change to
@IsTest
static void testSiteAsContainerEnabled() {
//String networkId = Network.getNetworkId();
System.assertNotEquals(null, LightningSelfRegisterController.siteAsContainerEnabled('mydomainname.mysalesforce.com'));
}
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.