aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryVAlarmTest.php
blob: ca06d8ffa7bdf22e5ff8b365485216c79cfd8644 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

namespace Sabre\CalDAV;

use Sabre\VObject;

class CalendarQueryVAlarmTest extends \PHPUnit_Framework_TestCase {

    /**
     * This test is specifically for a time-range query on a VALARM, contained
     * in a VEVENT that's recurring
     */
    function testValarm() {

        $vcalendar = new VObject\Component\VCalendar();

        $vevent = $vcalendar->createComponent('VEVENT');
        $vevent->RRULE = 'FREQ=MONTHLY';
        $vevent->DTSTART = '20120101T120000Z';
        $vevent->UID = 'bla';

        $valarm = $vcalendar->createComponent('VALARM');
        $valarm->TRIGGER = '-P15D';
        $vevent->add($valarm);


        $vcalendar->add($vevent);

        $filter = [
            'name'           => 'VCALENDAR',
            'is-not-defined' => false,
            'time-range'     => null,
            'prop-filters'   => [],
            'comp-filters'   => [
                [
                    'name'           => 'VEVENT',
                    'is-not-defined' => false,
                    'time-range'     => null,
                    'prop-filters'   => [],
                    'comp-filters'   => [
                        [
                            'name'           => 'VALARM',
                            'is-not-defined' => false,
                            'prop-filters'   => [],
                            'comp-filters'   => [],
                            'time-range'     => [
                                'start' => new \DateTime('2012-05-10'),
                                'end'   => new \DateTime('2012-05-20'),
                            ],
                        ],
                    ],
                ],
            ],
        ];

        $validator = new CalendarQueryValidator();
        $this->assertTrue($validator->validate($vcalendar, $filter));

        $vcalendar = new VObject\Component\VCalendar();

        // A limited recurrence rule, should return false
        $vevent = $vcalendar->createComponent('VEVENT');
        $vevent->RRULE = 'FREQ=MONTHLY;COUNT=1';
        $vevent->DTSTART = '20120101T120000Z';
        $vevent->UID = 'bla';

        $valarm = $vcalendar->createComponent('VALARM');
        $valarm->TRIGGER = '-P15D';
        $vevent->add($valarm);

        $vcalendar->add($vevent);

        $this->assertFalse($validator->validate($vcalendar, $filter));
    }

    function testAlarmWayBefore() {

        $vcalendar = new VObject\Component\VCalendar();

        $vevent = $vcalendar->createComponent('VEVENT');
        $vevent->DTSTART = '20120101T120000Z';
        $vevent->UID = 'bla';

        $valarm = $vcalendar->createComponent('VALARM');
        $valarm->TRIGGER = '-P2W1D';
        $vevent->add($valarm);

        $vcalendar->add($vevent);

        $filter = [
            'name'           => 'VCALENDAR',
            'is-not-defined' => false,
            'time-range'     => null,
            'prop-filters'   => [],
            'comp-filters'   => [
                [
                    'name'           => 'VEVENT',
                    'is-not-defined' => false,
                    'time-range'     => null,
                    'prop-filters'   => [],
                    'comp-filters'   => [
                        [
                            'name'           => 'VALARM',
                            'is-not-defined' => false,
                            'prop-filters'   => [],
                            'comp-filters'   => [],
                            'time-range'     => [
                                'start' => new \DateTime('2011-12-10'),
                                'end'   => new \DateTime('2011-12-20'),
                            ],
                        ],
                    ],
                ],
            ],
        ];

        $validator = new CalendarQueryValidator();
        $this->assertTrue($validator->validate($vcalendar, $filter));

    }

}