/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * 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.
 */
@isTest
private class DeleteEventEntryControllerTest {
	/*
	private Boolean wsFlg;
	private String Catagory;
	private Datetime st = Datetime.now().addDays(3);
	private Datetime et = st.addHours(2);
	private Date sd = Date.today().adddays(3);
	private Date ed = Date.today().adddays(5);
*/
    //日報から何も修正しない場合
    static testMethod void EventDeleteTest1() {
        Boolean wsFlg = false ;
    	String Catagory = 'HP';
    	Id ob = null;
    	Datetime st = Datetime.now().addDays(3);
    	Datetime et = st.addHours(1);
        Event toDeleteEvent = initEvent(wsFlg, Catagory, ob, st, et);
        toDeleteEvent = [select EventC_ID__c, WS_flg__c from Event where id = :toDeleteEvent.id];
        Apexpages.currentPage().getParameters().put('id', toDeleteEvent.id);
        Apexpages.currentPage().getParameters().put('retURL', '');
        ApexPages.StandardController sc = new ApexPages.standardController(toDeleteEvent);
        DeleteEventEntryController dec = new DeleteEventEntryController(sc);
        dec.init();
    }
    //日報から何も修正した場合
    static testMethod void EventDeleteTest2() {
        Boolean wsFlg = false ;
    	String Catagory = 'HP';
    	Datetime st = Datetime.now().addDays(3);
    	Datetime et = st.addHours(1);
    	Daily_Report__c dr = initReport(st);
    	Id ob = dr.Id;
    	
        Event toDeleteEvent = initEvent(wsFlg, Catagory, ob, st, et);
        toDeleteEvent = [select EventC_ID__c, WS_flg__c, Subject, StartDateTime, EndDateTime, ActivityDate, Id, DurationInMinutes, whatId,Location from Event where id = :toDeleteEvent.id];
        system.debug('<><><><><><><><><><><><>EventC_ID__c<><><><><><><><><><><><>'+toDeleteEvent.EventC_ID__c);
        initEventC(toDeleteEvent);
        Apexpages.currentPage().getParameters().put('id', toDeleteEvent.id);
        Apexpages.currentPage().getParameters().put('retURL', '');
        ApexPages.StandardController sc = new ApexPages.standardController(toDeleteEvent);
        DeleteEventEntryController dec = new DeleteEventEntryController(sc);
        dec.init();
    }
    //学会から新規したeventを削除する場合
    static testMethod void EventDeleteTest3() {
        Boolean wsFlg = true ;
    	String Catagory = 'Workshop';
    	
    	Date sd = Date.today().addDays(3);
    	Date ed = Date.today().addDays(5);
    	Campaign c = initCampaign(sd,ed);
    	Id ob = c.id;
    	
        Event toDeleteEvent = initEvent(wsFlg, Catagory, ob, sd, ed);
        toDeleteEvent = [select EventC_ID__c, WS_flg__c from Event where id = :toDeleteEvent.id];
        Apexpages.currentPage().getParameters().put('id', toDeleteEvent.id);
        Apexpages.currentPage().getParameters().put('retURL', '');
        ApexPages.StandardController sc = new ApexPages.standardController(toDeleteEvent);
        DeleteEventEntryController dec = new DeleteEventEntryController(sc);
        dec.init();
    }
    
    private  static Campaign initCampaign(Date sd, Date ed){
    	Campaign newCampaign = new Campaign();
        newCampaign.OwnerId = Userinfo.getUserId();
        newCampaign.Name = 'testnewCampaign';
        newCampaign.StartDate = sd;
        newCampaign.EndDate = ed;
        newCampaign.IsActive = true;
        newCampaign.Status = 'planed';

        insert newCampaign;
        return newCampaign;
    }
    private  static Event initEvent(Boolean wsflg, String cata, Id ob, datetime startTime, datetime endTime){
    	Event toDeleteEvent = new Event();
    	
    	if(wsflg != true){
    		toDeleteEvent.IsAllDayEvent = false;
        	toDeleteEvent.IsRecurrence = false;
        	// 行動簡易登録画面空登録するときだけに立つフラグ
        	toDeleteEvent.isScheduled__c = true;
    	}else{
    		toDeleteEvent.IsAllDayEvent = true;
    	}
        toDeleteEvent.OwnerId = Userinfo.getUserId();      
        toDeleteEvent.Subject = 'test';
        toDeleteEvent.Main_Visit_Location__c = 'test_location';
        toDeleteEvent.Purpose_Type__c = '';
        toDeleteEvent.Activity_Type2__c = cata;
        toDeleteEvent.WS_flg__c = wsflg;
        toDeleteEvent.WhatId = ob;
        toDeleteEvent.StartDateTime = startTime;
        toDeleteEvent.EndDateTime = endTime;
        
        insert toDeleteEvent;
        toDeleteEvent = [select EventC_ID__c, WS_flg__c from Event where id = :toDeleteEvent.id];
        system.debug(':::::::::::::::::::::::::::'+toDeleteEvent);
        return toDeleteEvent;
    }
	private static Daily_Report__c initReport(Datetime d){
		Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = d.date();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        return dr;
	}
	private static Event__c initEventC(Event e){
		Event__c ec = new Event__c(
            Daily_Report__c = e.whatId,
            StartDateTime__c = e.StartDateTime,
            EndDateTime__c = e.EndDateTime,
            Subject__c = e.Subject,
            Location__c = e.Location,
            ActivityDate__c = e.ActivityDate,
            Description__c  = 'test',
            Event_ID__c = e.Id
        );
        insert ec;
        e.EventC_ID__c = ec.Id;
        update e;
        return ec;
	}
}