/********************************************************************
*DM_MarketingCloudPolicyController_Test * *Test class for DM_MarketingCloudPolicyController * *Author: Daniel Mason *Created: 14/09/2015 *The @isTest class annotation indicates this class only contains test methods. *Classes defined with the @isTest annotation do not count against the organization *size limit for all Apex scripts.See the Apex Language Reference for more information *about Testing and Code Coverage. Look @ BG coding standards if any doubts ** Using Profile System admin X japan as FIELD_CUSTOM_VALIDATION_EXCEPTION on System Admin profile ********************************************************************/
@isTest private class DM_MarketingCloudPolicyController_Test{ static testMethod void DM_MarketingCloudPolicyController_Test(){
/*
Test Accept & Decline of Marketing Cloude policy */
Profile prof1 = [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator']; User user1 = new User(); user1.FirstName = 'Daniel'; user1.LastName = 'Mason'; user1.Email = '[email protected]'; user1.Username = '[email protected]'; user1.Alias = 'DMaso'; user1.CommunityNickname = 'DMaso'; user1.TimeZoneSidKey = 'America/Los_Angeles'; user1.LocaleSidKey = 'en_US'; user1.EmailEncodingKey = 'UTF-8'; user1.ProfileId = prof1.Id; user1.LanguageLocaleKey = 'en_US'; user1.Reason_for_Admin__c = 'CRM Team'; user1.Marketing_Cloud_Acceptance_Date__c = null; insert user1;
//Setup Custom Setting for profile Data_Policy_Settings__c dps = new Data_Policy_Settings__c(); dps.Show_Marketing_Policy__c = true; dps.SetupOwnerId = prof1.Id;
//Create Test Policy Data_Policy__c dp1 = new Data_Policy__c(); dp1.Name = 'Test Data Policy'; dp1.Start_Date__c = date.today(); dp1.MarketingCloudPolicyText__c = 'Everyone Loves creating test classes ...'; insert dp1;
*DM_MarketingCloudPolicyController_Test
*
*Test class for DM_MarketingCloudPolicyController
*
*Author: Daniel Mason
*Created: 14/09/2015
*The @isTest class annotation indicates this class only contains test methods.
*Classes defined with the @isTest annotation do not count against the organization
*size limit for all Apex scripts.See the Apex Language Reference for more information
*about Testing and Code Coverage. Look @ BG coding standards if any doubts
** Using Profile System admin X japan as FIELD_CUSTOM_VALIDATION_EXCEPTION on System Admin profile
********************************************************************/
@isTest
private class DM_MarketingCloudPolicyController_Test{
static testMethod void DM_MarketingCloudPolicyController_Test(){
/*
* Test Accept & Decline of Marketing Cloude policy
*/
Profile prof1 = [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator'];
User user1 = new User();
user1.FirstName = 'Daniel';
user1.LastName = 'Mason';
user1.Email = '[email protected]';
user1.Username = '[email protected]';
user1.Alias = 'DMaso';
user1.CommunityNickname = 'DMaso';
user1.TimeZoneSidKey = 'America/Los_Angeles';
user1.LocaleSidKey = 'en_US';
user1.EmailEncodingKey = 'UTF-8';
user1.ProfileId = prof1.Id;
user1.LanguageLocaleKey = 'en_US';
user1.Reason_for_Admin__c = 'CRM Team';
user1.Marketing_Cloud_Acceptance_Date__c = null;
insert user1;
//Setup Custom Setting for profile
Data_Policy_Settings__c dps = new Data_Policy_Settings__c();
dps.Show_Marketing_Policy__c = true;
dps.SetupOwnerId = prof1.Id;
//Create Test Policy
Data_Policy__c dp1 = new Data_Policy__c();
dp1.Name = 'Test Data Policy';
dp1.Start_Date__c = date.today();
dp1.MarketingCloudPolicyText__c = 'Everyone Loves creating test classes ...';
insert dp1;
system.assertEquals(1, [SELECT Count() FROM User WHERE email = '[email protected]' LIMIT 1]);
PageReference pageRef = Page.MarketingCloudPolicyPage;
System.runAs(user1){
test.startTest();
DM_MarketingCloudPolicyController controllerInstance = new DM_MarketingCloudPolicyController();
boolean redirect = controllerInstance.getRedirect();
test.setCurrentPage(pageRef);
DM_MarketingCloudPolicyController controller = new DM_MarketingCloudPolicyController();
//Declining VF Page
PageReference logout = controller.closePopupDecline();
system.assertEquals('/secur/logout.jsp',logout.getURL());
//Accepting VF Page controller.closePopupAccept(); user1 = [SELECT Marketing_Cloud_Acceptance_Date__c FROM User WHERE email = '[email protected]'LIMIT 1];
//Declining VF Page
PageReference logout = controller.closePopupDecline();
system.assertEquals('/secur/logout.jsp',logout.getURL());
//Accepting VF Page
controller.closePopupAccept();
user1 = [SELECT Marketing_Cloud_Acceptance_Date__c FROM User WHERE email = '[email protected]'LIMIT 1];
system.assertEquals(date.today(),user1.Marketing_Cloud_Acceptance_Date__c);
Data_Policy__c dataPolicy = DM_MarketingCloudPolicyController.getPolicy();
system.assertEquals(true,dataPolicy != null);
test.stopTest();
}
}
}
}