Skip to content

Commit 0e28a5f

Browse files
Add test on BYMONTHDAY
1 parent 647533a commit 0e28a5f

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

lib/Recur/RRuleIterator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,15 @@ protected function parseRRule($rrule)
921921

922922
case 'BYMONTHDAY':
923923
$this->byMonthDay = (array) $value;
924+
foreach ($this->byMonthDay as $byMonthDay) {
925+
if (!is_numeric($byMonthDay)) {
926+
throw new InvalidDataException('BYMONTHDAY in RRULE has a not numeric value(s)!');
927+
}
928+
$byMonthDay = (int) $byMonthDay;
929+
if ($byMonthDay < -31 || 0 === $byMonthDay || $byMonthDay > 31) {
930+
throw new InvalidDataException('BYMONTHDAY in RRULE must have value(s) from 1 to 31, or -31 to -1!');
931+
}
932+
}
924933
break;
925934

926935
case 'BYYEARDAY':

tests/VObject/Recur/RRuleIteratorTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010

1111
class RRuleIteratorTest extends TestCase
1212
{
13-
public function testInvalidMissingFreq()
14-
{
15-
$this->expectException(InvalidDataException::class);
16-
$this->parse(
17-
'COUNT=6;BYMONTHDAY=24;BYMONTH=1',
18-
'2011-04-07 00:00:00',
19-
[]
20-
);
21-
}
22-
2313
public function testHourly()
2414
{
2515
$this->parse(
@@ -316,6 +306,16 @@ public function testMonthlyByMonthDay()
316306
);
317307
}
318308

309+
public function testInvalidByMonthDay()
310+
{
311+
$this->expectException(InvalidDataException::class);
312+
$this->parse(
313+
'FREQ=MONTHLY;COUNT=6;BYMONTHDAY=1,5,10,42',
314+
'2011-04-07 00:00:00',
315+
[]
316+
);
317+
}
318+
319319
public function testMonthlyByDay()
320320
{
321321
$this->parse(
@@ -895,6 +895,16 @@ public function testInvalidFreq()
895895
);
896896
}
897897

898+
public function testInvalidMissingFreq()
899+
{
900+
$this->expectException(InvalidDataException::class);
901+
$this->parse(
902+
'COUNT=6;BYMONTHDAY=24;BYMONTH=1',
903+
'2011-04-07 00:00:00',
904+
[]
905+
);
906+
}
907+
898908
/**
899909
* @expectedException \Sabre\VObject\InvalidDataException
900910
*/

0 commit comments

Comments
 (0)