Skip to content

Commit 7b30773

Browse files
committed
Updating unit tests
1 parent 7627ba3 commit 7b30773

File tree

8 files changed

+83
-5
lines changed

8 files changed

+83
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
vendor/
22
.idea/
33
bin/
4+
examples/simpleEvent.ics
45
composer.lock
56
.php_cs.cache
67
.phpunit.result.cache

examples/simpleevent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@
5050

5151
// write iCalendar feed to stdout
5252
echo $icalobj->export();
53+
54+
file_put_contents('simpleEvent.ics', $icalobj->export());

src/ICalendarOrg/ZCiCalDataNode.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,21 @@ public function __toString() : string
126126
$output .= ':' . $this->getValues();
127127
}
128128

129-
return $output . "\n";
129+
$final = $output;
130+
131+
if (\strlen($final) > 70)
132+
{
133+
$final = '';
134+
135+
while (\strlen($output) > 70)
136+
{
137+
$final = $final . \substr($output, 0, 67) . " \r\n";
138+
$output = \substr($output, 67);
139+
}
140+
$final .= $output;
141+
}
142+
143+
return $final . "\r\n";
130144
}
131145

132146
/**

src/ICalendarOrg/ZCiCalNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function export(?ZCiCalNode $node = null, int $level = 0) : string
146146
//die("levels nested too deep<br/>\n");
147147
throw new \Exception('levels nested too deep');
148148
}
149-
$txtstr .= 'BEGIN:' . $node->getName() . "\n";
149+
$txtstr .= 'BEGIN:' . $node->getName() . "\r\n";
150150

151151
if (\property_exists($node, 'data'))
152152
{
@@ -173,7 +173,7 @@ public function export(?ZCiCalNode $node = null, int $level = 0) : string
173173
$txtstr .= $node->export($c, $level + 1);
174174
}
175175
}
176-
$txtstr .= 'END:' . $node->getName() . "\n";
176+
$txtstr .= 'END:' . $node->getName() . "\r\n";
177177

178178
return $txtstr;
179179
}

tests/FileTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ public function testICSFiles(string $contents, string $file) : void
1919
$this->assertNotEmpty($contents);
2020
$calendar = new \ICalendarOrg\ZCiCal($contents);
2121
$generated = $calendar->export();
22-
$this->assertEquals($this->clean($contents), $this->clean($generated), $file . ' has an error');
23-
// $this->assertEquals($contents, $generated, $file . ' has an error');
22+
// $this->assertEquals($this->clean($contents), $this->clean($generated), $file . ' has an error');
23+
foreach (\explode("\n", $generated) as $line)
24+
{
25+
$this->assertLessThan(72, \strlen($file), "Line ->{$line}<- is too long (>72 chars)");
26+
}
2427
}
2528

2629
/**

tests/SyntaxTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
class SyntaxTest extends \PHPFUI\PHPUnitSyntaxCoverage\Extensions
4+
{
5+
/** @group SyntaxTest */
6+
public function testDirectory() : void
7+
{
8+
$this->addSkipDirectory('makefont');
9+
$this->assertValidPHPDirectory(__DIR__ . '/../src', 'src directory has an error');
10+
$this->assertValidPHPDirectory(__DIR__ . '/../tests', 'tests directory has an error');
11+
$this->assertValidPHPDirectory(__DIR__ . '/../examples', 'examples directory has an error');
12+
}
13+
14+
/** @group SyntaxTest */
15+
public function testValidPHPFile() : void
16+
{
17+
$this->assertValidPHPFile(__DIR__ . '/../.php-cs-fixer.dist.php', '.php-cs-fixer.dist.php file is bad');
18+
}
19+
}

tests/examples/abrahamlincoln.ics

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//ZContent.net//Zap Calendar 1.0//EN
4+
CALSCALE:GREGORIAN
5+
METHOD:PUBLISH
6+
BEGIN:VEVENT
7+
SUMMARY:Abraham Lincoln
8+
9+
SEQUENCE:0
10+
STATUS:CONFIRMED
11+
TRANSP:TRANSPARENT
12+
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12
13+
DTSTART:20080212
14+
DTEND:20080213
15+
DTSTAMP:20150421T141403
16+
CATEGORIES:U.S. Presidents,Civil War People
17+
LOCATION:Hodgenville\, Kentucky
18+
GEO:37.5739497;-85.7399606
19+
DESCRIPTION:Born February 12\, 1809\nSixteenth President (1861-1865)\n\n\n
20+
\nhttp://AmericanHistoryCalendar.com
21+
URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincol
22+
n
23+
END:VEVENT
24+
END:VCALENDAR

tests/examples/simpleEvent.ics

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//ZContent.net//ZapCalLib 1.0//EN
4+
CALSCALE:GREGORIAN
5+
METHOD:PUBLISH
6+
BEGIN:VEVENT
7+
SUMMARY:Simple Event
8+
DTSTART:20200101T120000
9+
DTEND:20200101T130000
10+
11+
DTSTAMP:20230213T180927
12+
Description: This is a simple event, using the Zap Calendar PHP lib
13+
rary. Visit http://icalendar.org to validate icalendar files.
14+
END:VEVENT
15+
END:VCALENDAR

0 commit comments

Comments
 (0)