Skip to content

Commit

Permalink
creat Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Apr 25, 2024
1 parent a848f93 commit 800aac9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/VObject/Component/VCalendarTest.php
Expand Up @@ -756,6 +756,49 @@ public function testCalDAVMETHOD(): void
);
}

public function testNodeInValidationErrorHasLineIndexAndLineStringProps(): void
{
$defectiveInput = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
PRODID:vobject
BEGIN:VEVENT
UID:foo
CLASS:PUBLIC
DTSTART;VALUE=DATE:19931231
DTSTAMP:20240422T070855Z
CREATED:
LAST-MODIFIED:
DESCRIPTION:bar
END:VEVENT
ICS;

$vcal = VObject\Reader::read($defectiveInput);
$result = $vcal->validate();
$warningMessages = [];
foreach( $result as $error ) {
$warningMessages[] = $error['message'];
}
self::assertCount(2, $result, 'We expected exactly 2 validation messages, instead we got ' . count( $result ) . ' results:' . implode(', ', $warningMessages) );
foreach( $result as $idx => $warning ) {
self::assertArrayHasKey( 'node', $warning, 'The validation errors should contain a node key' );
self::assertInstanceOf( VObject\Property\ICalendar\DateTime::class, $warning[ 'node' ], 'We expected the defective node to be of type Sabre\VObject\Property\ICalendar\DateTime, instead we got type ' . gettype( $warning['node'] ) );
self::assertObjectHasProperty( 'lineIndex', $warning['node'], 'We expected the defective node in the validation errors array to have a "lineIndex" property' );
self::assertObjectHasProperty( 'lineString', $warning['node'], 'We expected the defective node in the validation errors array to have a "lineString" property' );
switch( $idx ) {
case 0:
self::assertEquals( '10', $warning['node']->lineIndex, 'We expected the "lineIndex" property of the first defective node to be 10, instead it was ' . $warning['node']->lineIndex );
self::assertEquals( 'CREATED:', $warning['node']->lineString, 'We expected the "lineString" property of the first defective node to be "CREATED:", instead it was ' . $warning['node']->lineString );
break;
case 1:
self::assertEquals( '11', $warning['node']->lineIndex, 'We expected the "lineIndex" property of the second defective node to be 11, instead it was ' . $warning['node']->lineIndex );
self::assertEquals( 'LAST-MODIFIED:', $warning['node']->lineString, 'We expected the "lineString" property of the second defective node to be "LAST-MODIFIED:", instead it was ' . $warning['node']->lineString );
break;
}
}
}

public function assertValidate($ics, $options, $expectedLevel, ?string $expectedMessage = null): void
{
$vcal = VObject\Reader::read($ics);
Expand Down

0 comments on commit 800aac9

Please sign in to comment.