| 
 | 1 | +<?php  | 
 | 2 | + | 
 | 3 | +/**  | 
 | 4 | + * This file is part of the ICalendarOrg package  | 
 | 5 | + *  | 
 | 6 | + * (c) Bruce Wells  | 
 | 7 | + *  | 
 | 8 | + * For the full copyright and license information, please view  | 
 | 9 | + * the LICENSE file that was distributed with this source  | 
 | 10 | + * code  | 
 | 11 | + */  | 
 | 12 | +class SimpleEventTest extends \PHPUnit\Framework\TestCase  | 
 | 13 | +	{  | 
 | 14 | +	public function testAddInvalidNode() : void  | 
 | 15 | +		{  | 
 | 16 | +		$this->expectException(\UnexpectedValueException::class);  | 
 | 17 | +		$icalobj = new \ICalendarOrg\ZCiCal();  | 
 | 18 | + | 
 | 19 | +		$icalobj->addDataNode(new \ICalendarOrg\ZCiCalDataNode('NAME:My Calendar Name'), new \ICalendarOrg\ZCiCalDataNode('FRED:Flintstone'));  | 
 | 20 | +		}  | 
 | 21 | + | 
 | 22 | +	public function testSimpleEvent() : void  | 
 | 23 | +		{  | 
 | 24 | +		$title = 'Simple Event';  | 
 | 25 | +		// date/time is in SQL datetime format  | 
 | 26 | +		$event_start = '2020-01-01 12:00:00';  | 
 | 27 | +		$event_end = '2020-01-01 13:00:00';  | 
 | 28 | + | 
 | 29 | +		// create the ical object  | 
 | 30 | +		$icalobj = new \ICalendarOrg\ZCiCal();  | 
 | 31 | + | 
 | 32 | +		// add name  | 
 | 33 | +		$icalobj->addDataNode(new \ICalendarOrg\ZCiCalDataNode('NAME:My Calendar Name'), new \ICalendarOrg\ZCiCalDataNode('PRODID:-//ZContent.net//ZapCalLib 1.0//EN'));  | 
 | 34 | + | 
 | 35 | +		// create the event within the ical object  | 
 | 36 | +		$eventobj = new \ICalendarOrg\ZCiCalNode('VEVENT', $icalobj->curnode);  | 
 | 37 | + | 
 | 38 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('SUMMARY:' . $title));  | 
 | 39 | + | 
 | 40 | +		// add start date  | 
 | 41 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('DTSTART:' . \ICalendarOrg\ZDateHelper::fromSqlDateTime($event_start)));  | 
 | 42 | + | 
 | 43 | +		// add end date  | 
 | 44 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('DTEND:' . \ICalendarOrg\ZDateHelper::fromSqlDateTime($event_end)));  | 
 | 45 | + | 
 | 46 | +		// UID is a required item in VEVENT, create unique string for this event  | 
 | 47 | +		// Adding your domain to the end is a good way of creating uniqueness  | 
 | 48 | +		$uid = \date('Y-m-d-H-i-s') . '@demo.icalendar.org';  | 
 | 49 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('UID:' . $uid));  | 
 | 50 | + | 
 | 51 | +		// DTSTAMP is a required item in VEVENT  | 
 | 52 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('DTSTAMP:' . \ICalendarOrg\ZDateHelper::fromSqlDateTime()));  | 
 | 53 | + | 
 | 54 | +		// Add description  | 
 | 55 | +		$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('Description: This is a simple event, using the Zap Calendar PHP library. Visit http://icalendar.org to validate icalendar files.'));  | 
 | 56 | + | 
 | 57 | +		$icalString = $icalobj->export();  | 
 | 58 | +		$this->assertStringContainsString('My Calendar Name', $icalString);  | 
 | 59 | +		}  | 
 | 60 | +	}  | 
0 commit comments