Skip to content

Commit d2c32f8

Browse files
committed
Added descriptions to calendar and fixed failing unit tests
Signed-off-by: Mua N. Laurent <[email protected]>
1 parent 318da69 commit d2c32f8

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/DataTypes/Calendar.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class Calendar implements DataTypeInterface
7474
*/
7575
protected $dateTimeFormat = "Y-m-d H:i";
7676

77+
/**
78+
* Event full descriptions/notes.
79+
*
80+
* @var string
81+
*/
82+
protected $description;
83+
7784
/**
7885
* Generates the DataType Object and sets all of its properties.
7986
*
@@ -118,6 +125,9 @@ protected function buildCalendarString()
118125
if (isset($this->url)) {
119126
$calendar .= "URL:".$this->url.$this->separator;
120127
}
128+
if (isset($this->description)) {
129+
$calendar .= "DESCRIPTION:".$this->description.$this->separator;
130+
}
121131

122132
$calendar .= $this->suffix;
123133

@@ -154,6 +164,9 @@ protected function setProperties(array $arguments)
154164
if (isset($arguments['url'])) {
155165
$this->setUrl($arguments['url']);
156166
}
167+
if (isset($arguments['description'])) {
168+
$this->description = $arguments['description'];
169+
}
157170
}
158171
}
159172

@@ -246,6 +259,6 @@ protected function convertEventDateTimeToString($dateTime)
246259
} catch (Exception $e) {
247260
throw new InvalidArgumentException('Invalid date provided');
248261
}
249-
return $date->format('yymdTHms');
262+
return $date->format('yymd\THms');
250263
}
251264
}

tests/DataTypes/CalendarTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
use BaconQrCode\Exception\InvalidArgumentException;
8-
use DateTime;
98
use PHPUnit\Framework\TestCase;
109
use SimpleSoftwareIO\QrCode\DataTypes\Calendar;
1110

@@ -18,6 +17,13 @@ class CalendarTest extends TestCase
1817
*/
1918
private $separator;
2019

20+
/**
21+
* The calendar variable
22+
*
23+
* @var Calendar
24+
*/
25+
private $calendar;
26+
2127
public function setUp(): void
2228
{
2329
$this->separator = "\r\n";
@@ -63,7 +69,7 @@ public function test_it_generates_a_proper_format_with_just_the_summary_and_star
6369

6470
$properFormat = "BEGIN:VEVENT".$this->separator.
6571
"SUMMARY:My FooBar Event".$this->separator.
66-
"DTSTART:20201008UTC161000".$this->separator.
72+
"DTSTART:20201008T161000".$this->separator.
6773
"END:VEVENT";
6874

6975
$this->assertEquals($properFormat, strval($this->calendar));
@@ -81,8 +87,8 @@ public function test_it_generates_a_proper_format_with_summary_start_date_time_a
8187

8288
$properFormat = "BEGIN:VEVENT".$this->separator.
8389
"SUMMARY:My FooBar Event".$this->separator.
84-
"DTSTART:20201008UTC161000".$this->separator.
85-
"DTEND:20201008UTC181000".$this->separator.
90+
"DTSTART:20201008T161000".$this->separator.
91+
"DTEND:20201008T181000".$this->separator.
8692
"END:VEVENT";
8793

8894
$this->assertEquals($properFormat, strval($this->calendar));
@@ -101,8 +107,8 @@ public function test_it_generates_a_proper_format_with_specified_date_time_forma
101107

102108
$properFormat = "BEGIN:VEVENT".$this->separator.
103109
"SUMMARY:My FooBar Event".$this->separator.
104-
"DTSTART:20201008UTC161000".$this->separator.
105-
"DTEND:20201008UTC181000".$this->separator.
110+
"DTSTART:20201008T161000".$this->separator.
111+
"DTEND:20201008T181000".$this->separator.
106112
"END:VEVENT";
107113

108114
$this->assertEquals($properFormat, strval($this->calendar));
@@ -133,7 +139,7 @@ public function test_it_generates_a_proper_format_with_summary_start_date_time_a
133139

134140
$properFormat = "BEGIN:VEVENT".$this->separator.
135141
"SUMMARY:My FooBar Event".$this->separator.
136-
"DTSTART:20201008UTC161000".$this->separator.
142+
"DTSTART:20201008T161000".$this->separator.
137143
"LOCATION:Fooon".$this->separator.
138144
"END:VEVENT";
139145

@@ -152,7 +158,7 @@ public function test_it_generates_a_proper_format_with_summary_start_date_time_a
152158

153159
$properFormat = "BEGIN:VEVENT".$this->separator.
154160
"SUMMARY:My FooBar Event".$this->separator.
155-
"DTSTART:20201008UTC161000".$this->separator.
161+
"DTSTART:20201008T161000".$this->separator.
156162
"URL:https://www.google.com".$this->separator.
157163
"END:VEVENT";
158164

@@ -168,16 +174,18 @@ public function test_it_generates_a_proper_format_with_calendar_parameters()
168174
'endDateTime' => '2020-10-08 18:00',
169175
'location' => 'Foo Location',
170176
'url' => 'https://www.google.com',
171-
'dateTimeFormat' => 'Y-m-d H:i'
177+
'dateTimeFormat' => 'Y-m-d H:i',
178+
'description' => 'FooBar\'s Event description can be longer than this.'
172179
],
173180
]);
174181

175182
$properFormat = "BEGIN:VEVENT".$this->separator.
176183
"SUMMARY:My FooBar Event".$this->separator.
177-
"DTSTART:20201008UTC161000".$this->separator.
178-
"DTEND:20201008UTC181000".$this->separator.
184+
"DTSTART:20201008T161000".$this->separator.
185+
"DTEND:20201008T181000".$this->separator.
179186
"LOCATION:Foo Location".$this->separator.
180187
"URL:https://www.google.com".$this->separator.
188+
"DESCRIPTION:FooBar's Event description can be longer than this.".$this->separator.
181189
"END:VEVENT";
182190

183191
$this->assertEquals($properFormat, strval($this->calendar));

0 commit comments

Comments
 (0)