123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- <?php
- namespace Sabre\VObject\Component;
- use Sabre\VObject;
- use Sabre\VObject\Reader;
- use Sabre\VObject\Component;
- use Sabre\VObject\Component\VAvailability;
- /**
- * We use `RFCxxx` has a placeholder for the
- * https://tools.ietf.org/html/draft-daboo-calendar-availability-05 name.
- */
- class VAvailabilityTest extends \PHPUnit_Framework_TestCase {
- function testVAvailabilityComponent() {
- $vcal = <<<VCAL
- BEGIN:VCALENDAR
- BEGIN:VAVAILABILITY
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL;
- $document = Reader::read($vcal);
- $this->assertInstanceOf(__NAMESPACE__ . '\VAvailability', $document->VAVAILABILITY);
- }
- function testRFCxxxSection3_1_availabilityprop_required() {
- // UID and DTSTAMP are present.
- $this->assertIsValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // UID and DTSTAMP are missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // DTSTAMP is missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // UID is missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- DTSTAMP:20111005T133225Z
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- }
- function testRFCxxxSection3_1_availabilityprop_optional_once() {
- $properties = array(
- 'BUSYTYPE:BUSY',
- 'CLASS:PUBLIC',
- 'CREATED:20111005T135125Z',
- 'DESCRIPTION:Long bla bla',
- 'DTSTART:20111005T020000',
- 'LAST-MODIFIED:20111005T135325Z',
- 'ORGANIZER:mailto:foo@example.com',
- 'PRIORITY:1',
- 'SEQUENCE:0',
- 'SUMMARY:Bla bla',
- 'URL:http://example.org/'
- );
- // They are all present, only once.
- $this->assertIsValid(Reader::read($this->template($properties)));
- // We duplicate each one to see if it fails.
- foreach ($properties as $property) {
- $this->assertIsNotValid(Reader::read($this->template(array(
- $property,
- $property
- ))));
- }
- }
- function testRFCxxxSection3_1_availabilityprop_dtend_duration() {
- // Only DTEND.
- $this->assertIsValid(Reader::read($this->template(array(
- 'DTEND:21111005T133225Z'
- ))));
- // Only DURATION.
- $this->assertIsValid(Reader::read($this->template(array(
- 'DURATION:PT1H'
- ))));
- // Both (not allowed).
- $this->assertIsNotValid(Reader::read($this->template(array(
- 'DTEND:21111005T133225Z',
- 'DURATION:PT1H'
- ))));
- }
- function testAvailableSubComponent() {
- $vcal = <<<VCAL
- BEGIN:VCALENDAR
- BEGIN:VAVAILABILITY
- BEGIN:AVAILABLE
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL;
- $document = Reader::read($vcal);
- $this->assertInstanceOf(__NAMESPACE__, $document->VAVAILABILITY->AVAILABLE);
- }
- function testRFCxxxSection3_1_availableprop_required() {
- // UID, DTSTAMP and DTSTART are present.
- $this->assertIsValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- UID:foo@test
- DTSTAMP:20111005T133225Z
- DTSTART:20111005T133225Z
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // UID, DTSTAMP and DTSTART are missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // UID is missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- DTSTAMP:20111005T133225Z
- DTSTART:20111005T133225Z
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // DTSTAMP is missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- UID:foo@test
- DTSTART:20111005T133225Z
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- // DTSTART is missing.
- $this->assertIsNotValid(Reader::read(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- UID:foo@test
- DTSTAMP:20111005T133225Z
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ));
- }
- function testRFCxxxSection3_1_available_dtend_duration() {
- // Only DTEND.
- $this->assertIsValid(Reader::read($this->templateAvailable(array(
- 'DTEND:21111005T133225Z'
- ))));
- // Only DURATION.
- $this->assertIsValid(Reader::read($this->templateAvailable(array(
- 'DURATION:PT1H'
- ))));
- // Both (not allowed).
- $this->assertIsNotValid(Reader::read($this->templateAvailable(array(
- 'DTEND:21111005T133225Z',
- 'DURATION:PT1H'
- ))));
- }
- function testRFCxxxSection3_1_available_optional_once() {
- $properties = array(
- 'CREATED:20111005T135125Z',
- 'DESCRIPTION:Long bla bla',
- 'LAST-MODIFIED:20111005T135325Z',
- 'RECURRENCE-ID;RANGE=THISANDFUTURE:19980401T133000Z',
- 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
- 'SUMMARY:Bla bla'
- );
- // They are all present, only once.
- $this->assertIsValid(Reader::read($this->templateAvailable($properties)));
- // We duplicate each one to see if it fails.
- foreach ($properties as $property) {
- $this->assertIsNotValid(Reader::read($this->templateAvailable(array(
- $property,
- $property
- ))));
- }
- }
- function testRFCxxxSection3_2() {
- $this->assertEquals(
- 'BUSY',
- Reader::read($this->templateAvailable(array(
- 'BUSYTYPE:BUSY'
- )))
- ->VAVAILABILITY
- ->AVAILABLE
- ->BUSYTYPE
- ->getValue()
- );
- $this->assertEquals(
- 'BUSY-UNAVAILABLE',
- Reader::read($this->templateAvailable(array(
- 'BUSYTYPE:BUSY-UNAVAILABLE'
- )))
- ->VAVAILABILITY
- ->AVAILABLE
- ->BUSYTYPE
- ->getValue()
- );
- $this->assertEquals(
- 'BUSY-TENTATIVE',
- Reader::read($this->templateAvailable(array(
- 'BUSYTYPE:BUSY-TENTATIVE'
- )))
- ->VAVAILABILITY
- ->AVAILABLE
- ->BUSYTYPE
- ->getValue()
- );
- }
- protected function assertIsValid(VObject\Document $document) {
- $this->assertEmpty($document->validate());
- }
- protected function assertIsNotValid(VObject\Document $document) {
- $this->assertNotEmpty($document->validate());
- }
- protected function template(array $properties) {
- return $this->_template(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- …
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ,
- $properties
- );
- }
- protected function templateAvailable(array $properties) {
- return $this->_template(
- <<<VCAL
- BEGIN:VCALENDAR
- VERSION:2.0
- PRODID:-//id
- BEGIN:VAVAILABILITY
- UID:foo@test
- DTSTAMP:20111005T133225Z
- BEGIN:AVAILABLE
- UID:foo@test
- DTSTAMP:20111005T133225Z
- DTSTART:20111005T133225Z
- …
- END:AVAILABLE
- END:VAVAILABILITY
- END:VCALENDAR
- VCAL
- ,
- $properties
- );
- }
- protected function _template($template, array $properties) {
- return str_replace('…', implode("\r\n", $properties), $template);
- }
- }
|