<?php // iCalcvnTest.php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
$startTime = microtime( TRUE );
$encoded = FALSE;
$_log = TRUE;
/**/
if( !isset( $_REQUEST['testcase'] )) $_REQUEST['testcase'] = 11;
/**/
if( $encoded ) {
require_once 'encoded/iCalcreator.class.php';
require_once 'encoded/iCalcnv.class.php';
}
else {
require_once 'iCalcreator.class.php';
require_once 'iCalcnv.class.php';
}
/**/
if( $_log ) {
/* define default loglevel, set to 'NO_LOG', if not using pear LOG extension */
$loglevels = array( 'PEAR_LOG_EMERG' => 0 // System is unusable
, 'PEAR_LOG_ALERT' => 1 // Immediate action required
, 'PEAR_LOG_CRIT' => 2 // Critical conditions
, 'PEAR_LOG_ERR' => 3 // Error conditions
, 'PEAR_LOG_WARNING' => 4 // Warning conditions
, 'PEAR_LOG_NOTICE' => 5 // Normal but significant
, 'PEAR_LOG_INFO' => 6 // Informational
, 'PEAR_LOG_DEBUG' => 7 // Debug-level messages
, 'NO_LOG' => 8 ); // no logging at all
$logConf = array( 'append' => TRUE,
'locking' => TRUE,
'lineFormat' => '%1$s %3$s %8$s.%7$s:%6$s %4$s',
// Timestamp, priority, class, function, line number, text
// 'lineFormat' => '%1$s %4$s', 'timeFormat' => '%X'), // only time + text
'timeFormat' => '%Y%m%d %X' );
$logfile = 'iCalcnv_'.date('Ymd').'.log'; // create a new logfile every day
require_once 'Log.php';
class iCalLog extends Log { function __destruct() { $this->flush(); } }
$_log = iCalLog::singleton( 'file', $logfile, ICALCNVVERSION, $logConf, $loglevels['PEAR_LOG_DEBUG'] );
$_log->log( '******************** start '.ICALCNVVERSION.' (test) ********************', PEAR_LOG_NOTICE );
}
/**/
$iCalcnv = new iCalcnv( $_log );
/**/
switch( $_REQUEST['testcase'] ) {
case 11: // iCal2xls
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2xls 11, input file, output save to file (+backup)', PEAR_LOG_ERR );
if( FALSE !== $iCalcnv->setConfig( array( 'inputfilename' => 'testFile.ics'
, 'inputdirectory' => 'calendars'
, 'outputfilename' => 'testFile.xls'
, 'outputdirectory' => 'csvxlsStorage'
, 'save' => TRUE
, 'backup' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART' )))
$iCalcnv->iCal2xls();
break;
/**/
case 12: // iCal2xls
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2xls 12, input url, output save to file (write over)', PEAR_LOG_ERR );
$filenameICS = 'http://localhost/work/iCal/iCalcnv/iCalcnv-3.0/calendars/testFile.ics';
if( FALSE !== $iCalcnv->setConfig( array( 'inputurl' => $filenameICS
, 'outputfilename' => 'testFile.xls'
, 'outputdirectory' => 'csvxlsStorage'
, 'save' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART' )))
$iCalcnv->iCal2xls();
break;
/**/
case 13: // iCal2xls
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2xls 13, input object, output redirect to browser', PEAR_LOG_ERR );
$calendar = new vcalendar( array( 'unique_id' => 'kigkonsult.se', 'directory' => 'calendars', 'filename' => 'testFile.ics' ));
$calendar->parse();
if( FALSE !== $iCalcnv->setConfig( array( 'outputfilename' => 'testFile.xls'
, 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART'
, 'skip' => array( 'CREATED', 'COMMENT' ))))
$iCalcnv->iCal2xls( $calendar );
break;
/**/
/**/
case 21: // iCal2csv
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2csv 21, input file, output save to file (backup)', PEAR_LOG_ERR );
if( FALSE !== $iCalcnv->setConfig( array( 'inputfilename' => 'testFile.ics'
, 'inputdirectory' => 'calendars'
, 'outputfilename' => 'testFile.csv'
, 'outputdirectory' => 'csvxlsStorage'
, 'save' => TRUE
, 'backup' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART'
, 'skip' => array( 'CREATED', 'COMMENT' ))));
$iCalcnv->iCal2csv();
break;
/**/
case 22: // iCal2csv
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2csv 22, input url, output save to file (write over)', PEAR_LOG_ERR );
$filenameICS = 'http://localhost/work/iCal/iCalcnv/iCalcnv-3.0/calendars/testFile.ics';
if( FALSE !== $iCalcnv->setConfig( array( 'inputurl' => $filenameICS
, 'outputfilename' => 'testFile.csv'
, 'outputdirectory' => 'csvxlsStorage'
, 'save' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART' )))
$iCalcnv->iCal2csv();
break;
/**/
case 23: // iCal2csv
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start iCal2csv 23, input object, output redirect to browser', PEAR_LOG_ERR );
$calendar = new vcalendar( array( 'unique_id' => 'kigkonsult.se', 'directory' => 'calendars', 'filename' => 'testFile.ics' ));
$calendar->parse();
if( FALSE !== $iCalcnv->setConfig( array( 'UID' => 'eventId'
, 'DTSTART' => 'Start'
, 'SUMMARY' => 'Subject'
, 2 => 'DESCRIPTION'
, 6 => 'UID'
, 8 => 'DTSTART'
, 'skip' => array( 'CREATED', 'COMMENT' ))))
$iCalcnv->iCal2csv( $calendar );
break;
/**/
/**/
case 31: // csv2iCal
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start csv2iCal 31, input file, output object (+redirect)', PEAR_LOG_ERR );
if( FALSE !== $iCalcnv->setConfig( array( 'inputfilename' => 'testFile.csv'
, 'inputdirectory' => 'csvxlsStorage'
, 'outputobj' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'DTSTART' => 'Start'
, 'UID' => 'eventId'
, 'SUMMARY' => 'Subject' ))) {
$calendar = $iCalcnv->csv2iCal();
if( FALSE !== $calendar )
$calendar->returnCalendar();
}
break;
/**/
case 32: // csv2iCal
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start csv2iCal 32, input url, output file (save+backup)', PEAR_LOG_ERR );
$filenameCSV = 'http://localhost/work/iCal/iCalcnv/iCalcnv-3.0/csvxlsStorage/testFile.csv';
copy( 'calendars/testFile.ics', 'calendars/testFile.org.ics' );
if( FALSE !== $iCalcnv->setConfig( array( 'inputurl' => $filenameCSV
, 'outputfilename' => 'testFile.ics'
, 'outputdirectory' => 'calendars'
, 'save' => TRUE
, 'backup' => TRUE
, 'unique_id' => 'kigkonsult.se'
, 'DTSTART' => 'Start'
, 'UID' => 'eventId'
, 'SUMMARY' => 'Subject' ))) {
$iCalcnv->csv2iCal();
}
// compare and display diff result
$cmd = 'diff calendars/testFile.org.ics calendars/testFile.ics';
$a = array();
exec( $cmd, $a );
echo $cmd.chr(10).implode( chr(10), $a );
$cmd = 'diff -b -H --side-by-side -W 160 calendars/testFile.org.ics calendars/testFile.ics';
$a = array();
exec( $cmd, $a );
echo chr(10).$cmd.chr(10).implode( chr(10), $a );
unlink( 'calendars/testFile.org.ics' );
break;
/**/
case 33: // csv2iCal
if( $_log )
$_log->log( str_repeat( '* ', 5 ).' start csv2iCal 33, input file, output redirect', PEAR_LOG_ERR );
if( FALSE !== $iCalcnv->setConfig( array( 'inputfilename' => 'testFile.csv'
, 'inputdirectory' => 'csvxlsStorage'
, 'unique_id' => 'kigkonsult.se'
, 'DTSTART' => 'Start'
, 'UID' => 'eventId'
, 'SUMMARY' => 'Subject' ))) {
$iCalcnv->csv2iCal();
}
break;
/**/
default:
if( $_log )
$_log->log( 'unvalid testcase number', PEAR_LOG_NOTICE );
break;
}
/**/
if( $_log ) {
$_log->log( 'total time:'.number_format(( microtime( TRUE ) - $startTime ), 5 ).' sec', PEAR_LOG_ERR );
$_log->flush();
}
?>