You need to sign in to do that
Don't have an account?

test class for calendercontroller class
please help with dis test class
public with sharing class CalendarController {
public String selectedEvent{get;set;}
public String selectedEventName{get;set;}
public Date selectedEventStartDate{get;set;}
public String selectedEventDescription{get;set;}
public String selectedStartDateStr{get;set;}
public String customerId{get;set;}
public String customerName{get;set;}
public String contactId{get;set;}
public String contactName{get;set;}
public Event eventObject{get;set;}
public void next() {
addMonth(1);
}
public void prev() {
addMonth(-1);
}
public CalendarController() {
eventObject = new Event();
Date d = system.today(); // default to today
Integer mo = d.month();
String m_param = System.currentPageReference().getParameters().get('mo');
String y_param = System.currentPageReference().getParameters().get('yr');
// allow a month to be passed in on the url as mo=10
if (m_param != null) {
Integer mi = Integer.valueOf(m_param);
if (mi > 0 && mi <= 12) {
d = Date.newInstance(d.year(),mi,d.day());
}
}
// and year as yr=2008
if (y_param != null) {
Integer yr = Integer.valueOf(y_param);
d = Date.newInstance(yr, d.month(), d.day());
}
setMonth(d);
}
public Month getMonth() { return month; }
public List<Month.Week> getWeeks() {
system.assert(month!=null,'month is null');
return month.getWeeks();
}
private void setMonth(Date d) {
month = new Month(d);
system.assert(month != null);
Date[] da = month.getValidDateRange(); // gather events that fall in this month
events = [ select id,subject,WhatId,whoId,description,StartDateTime,activitydate,activitydatetime,DurationInMinutes
from Event
where OwnerId =: userinfo.getuserid() AND activitydate >= :da[0] AND activityDate <= :da[1]
order by activitydatetime];
month.setEvents(events); // merge those events into the month class
}
private void addMonth(Integer val) {
Date d = month.getFirstDate();
d = d.addMonths(val);
setMonth(d);
}
private List<Event> events;
private Month month;
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
public PageReference processLinkClick() {
Event ev = [ select id,subject,WhatId,whoId,description,StartDateTime,activitydate,activitydatetime,DurationInMinutes from Event where id=:selectedEvent];
selectedEventStartDate = date.newinstance(ev.StartDateTime.year(), ev.StartDateTime.month(), ev.StartDateTime.day());
//selectedStartDateStr = ev.StartDateTime.format('MM/dd/yyyy');
selectedStartDateStr = LocaleFormatedDateTimeController.getTimeZoneValue(ev.StartDateTime);
//customerId = ev.whatId;
if(ev.whatId != null){
Account acc = [Select name from Account where id=: ev.whatId];
//customerName = acc.Name;
}
//contactId = ev.whoId;
if(ev.whoId != null){
Contact con = [Select name, Account.Name, AccountId from Contact where id=: ev.whoId];
customerId = con.AccountId;
customerName = con.Account.Name;
}
return null;
}
}
test class
@isTest
Private class testCalendarController{
static testmethod void main(){
Apexpages.currentpage().getParameters().put('mo',12);
Apexpages.currentpage().getParameters().put('yr',2014);
CalendarController c = new CalendarController();
c.setMonth(System.today());
c.getFormTag();
c.getTextBox();
}
}
public with sharing class CalendarController {
public String selectedEvent{get;set;}
public String selectedEventName{get;set;}
public Date selectedEventStartDate{get;set;}
public String selectedEventDescription{get;set;}
public String selectedStartDateStr{get;set;}
public String customerId{get;set;}
public String customerName{get;set;}
public String contactId{get;set;}
public String contactName{get;set;}
public Event eventObject{get;set;}
public void next() {
addMonth(1);
}
public void prev() {
addMonth(-1);
}
public CalendarController() {
eventObject = new Event();
Date d = system.today(); // default to today
Integer mo = d.month();
String m_param = System.currentPageReference().getParameters().get('mo');
String y_param = System.currentPageReference().getParameters().get('yr');
// allow a month to be passed in on the url as mo=10
if (m_param != null) {
Integer mi = Integer.valueOf(m_param);
if (mi > 0 && mi <= 12) {
d = Date.newInstance(d.year(),mi,d.day());
}
}
// and year as yr=2008
if (y_param != null) {
Integer yr = Integer.valueOf(y_param);
d = Date.newInstance(yr, d.month(), d.day());
}
setMonth(d);
}
public Month getMonth() { return month; }
public List<Month.Week> getWeeks() {
system.assert(month!=null,'month is null');
return month.getWeeks();
}
private void setMonth(Date d) {
month = new Month(d);
system.assert(month != null);
Date[] da = month.getValidDateRange(); // gather events that fall in this month
events = [ select id,subject,WhatId,whoId,description,StartDateTime,activitydate,activitydatetime,DurationInMinutes
from Event
where OwnerId =: userinfo.getuserid() AND activitydate >= :da[0] AND activityDate <= :da[1]
order by activitydatetime];
month.setEvents(events); // merge those events into the month class
}
private void addMonth(Integer val) {
Date d = month.getFirstDate();
d = d.addMonths(val);
setMonth(d);
}
private List<Event> events;
private Month month;
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
public PageReference processLinkClick() {
Event ev = [ select id,subject,WhatId,whoId,description,StartDateTime,activitydate,activitydatetime,DurationInMinutes from Event where id=:selectedEvent];
selectedEventStartDate = date.newinstance(ev.StartDateTime.year(), ev.StartDateTime.month(), ev.StartDateTime.day());
//selectedStartDateStr = ev.StartDateTime.format('MM/dd/yyyy');
selectedStartDateStr = LocaleFormatedDateTimeController.getTimeZoneValue(ev.StartDateTime);
//customerId = ev.whatId;
if(ev.whatId != null){
Account acc = [Select name from Account where id=: ev.whatId];
//customerName = acc.Name;
}
//contactId = ev.whoId;
if(ev.whoId != null){
Contact con = [Select name, Account.Name, AccountId from Contact where id=: ev.whoId];
customerId = con.AccountId;
customerName = con.Account.Name;
}
return null;
}
}
test class
@isTest
Private class testCalendarController{
static testmethod void main(){
Apexpages.currentpage().getParameters().put('mo',12);
Apexpages.currentpage().getParameters().put('yr',2014);
CalendarController c = new CalendarController();
c.setMonth(System.today());
c.getFormTag();
c.getTextBox();
}
}