• Tim Bauer
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hey Everyone,

I have a really simple controller I wrote to pass in values based on the user that's logged in, into a visual force page that loads as a home page component/layout. 

I don't have any experience with Salesforce and have no idea on how to write a TestClass that covers the code. I don't need 100%, just enough to deploy a slight change to the code.

Here's my controller class:

Public with sharing class iframeLinkController {

    Public String CurrentUserName {get;set;}
    Public String graburlnh { get; set; }    
    Public String graburl { get; set; }
    Public String grabhgt { get; set; }

Public iframeLinkController (){

    CurrentUserName = userinfo.getName();
    
    //testing tim bauer -- should be removed
    
    //salesperson individual dashboard - resin --make sure first line starts with "if" 
    if(CurrentUserName == 'Casey Taylor'){
        graburlnh = '/01Z50000000XORa?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XORa';
        grabhgt = '2936px';
        }

    else if(CurrentUserName == 'Ryan Carter'){
        graburlnh = '/01Z50000000XORk?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XORk';
        grabhgt = '2145px';
        }
    
    else if(CurrentUserName == 'Bryan Schutt'){
        graburlnh = '/01Z50000000XNZn?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XNZn';
        grabhgt = '1871px';
        }
        
    else if(CurrentUserName == 'Scott Moros'){
        graburlnh = '/01Z50000000XOS4?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOS4';
        grabhgt = '1870px';
        }
        
    else if(CurrentUserName == 'Jonas Lee'){
        graburlnh = '/01Z50000000XOSJ?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOSJ';
        grabhgt = '2119px';
        }
        
    else if(CurrentUserName == 'Mark Powers'){
        graburlnh = '/01Z50000000XORu?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XORu';
        grabhgt = '2090px';
        }
        
    //**************************************************************************************************
    //**************************************************************************************************
        
    //sales director dashboard - resin  
    else if(CurrentUserName == 'Luke Rains'){
        graburlnh = '/01Z50000000XOST?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOST';
        grabhgt = '3734px';
        }
        
    else if(CurrentUserName == 'Miguel Pena'){
        graburlnh = '/01Z50000000XOST?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOST';
        grabhgt = '3734px';
        }
        
    else if(CurrentUserName == 'Brad Phillips'){
        graburlnh = '/01Z50000000XOST?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOST';
        grabhgt = '3734px';
        }                

    //**************************************************************************************************
    //**************************************************************************************************
    
    //sales director dashboard - dustpro  
    else if(CurrentUserName == 'Marc McQuesten'){
        graburlnh = '/01Z50000000XOSY?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOSY';
        grabhgt = '2670px';
        }   

    else if(CurrentUserName == 'Chris Shaknis'){
        graburlnh = '/01Z50000000XOSY?isdtp=nv';
        graburl = 'https://na3.salesforce.com/01Z50000000XOSY';
        grabhgt = '2670px';
        } 
        
    else{
        graburlnh = '';
        graburl = '';
        grabhgt = '';
        }
    }
}

********************************************************************************************************************************************
********************************************************************************************************************************************
********************************************************************************************************************************************

Here's my test class that is garbage, most of it is commented out:

@isTest
public class iframeLinkControllerTests{
    
    public static testMethod void testMyController() {
        
        iframeLinkController controller = new iframeLinkController();
        PageReference pageRef = Page.NoClick_Page;
        Test.setCurrentPage(pageRef);
        
        //Verify that page fails without parameters
        //System.assertEquals('/apex/failure?error=noParam', nextPage);
    
        // Add parameters to page URL
        ApexPages.currentPage().getParameters().put('qp', 'yyyy');
      
        // Instantiate a new controller with all parameters in the page
        controller = new iframeLinkController(); 
        controller.CurrentUserName = 'Casey Taylor';
        controller.graburlnh = '/01Z50000000XORa?isdtp=nv';
        controller.graburl = 'https://na3.salesforce.com/01Z50000000XORa';
        controller.grabhgt = '2936px';

        // Verify that the success page displays
        //System.assertEquals('/apex/success', nextPage);
        //Lead[] leads = [select id, email from lead where Company = 'acme'];
        //System.assertEquals('firstlast@acme.com', leads[0].email);
    
    }
}