assertInstanceOf(__NAMESPACE__.'\VAvailability', $document->VAVAILABILITY); } public function testGetEffectiveStartEnd() { $vcal = <<assertEquals( [ new DateTimeImmutable('2015-07-17 16:22:00', $tz), new DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->VAVAILABILITY->getEffectiveStartEnd() ); } public function testGetEffectiveStartDuration() { $vcal = <<assertEquals( [ new DateTimeImmutable('2015-07-17 16:22:00', $tz), new DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->VAVAILABILITY->getEffectiveStartEnd() ); } public function testGetEffectiveStartEndUnbound() { $vcal = <<assertEquals( [ null, null, ], $document->VAVAILABILITY->getEffectiveStartEnd() ); } public function testIsInTimeRangeUnbound() { $vcal = <<assertTrue( $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18')) ); } public function testIsInTimeRangeOutside() { $vcal = <<assertFalse( $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18')) ); } public function testRFCxxxSection3_1_availabilityprop_required() { // UID and DTSTAMP are present. $this->assertIsValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsNotValid(Reader::read( <<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([ $property, $property, ]))); } } public function testRFCxxxSection3_1_availabilityprop_dtend_duration() { // Only DTEND. $this->assertIsValid(Reader::read($this->template([ 'DTEND:21111005T133225Z', ]))); // Only DURATION. $this->assertIsValid(Reader::read($this->template([ 'DURATION:PT1H', ]))); // Both (not allowed). $this->assertIsNotValid(Reader::read($this->template([ 'DTEND:21111005T133225Z', 'DURATION:PT1H', ]))); } public function testAvailableSubComponent() { $vcal = <<assertInstanceOf(__NAMESPACE__, $document->VAVAILABILITY->AVAILABLE); } public function testRFCxxxSection3_1_availableprop_required() { // UID, DTSTAMP and DTSTART are present. $this->assertIsValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsNotValid(Reader::read( <<assertIsValid(Reader::read($this->templateAvailable([ 'DTEND:21111005T133225Z', ]))); // Only DURATION. $this->assertIsValid(Reader::read($this->templateAvailable([ 'DURATION:PT1H', ]))); // Both (not allowed). $this->assertIsNotValid(Reader::read($this->templateAvailable([ 'DTEND:21111005T133225Z', 'DURATION:PT1H', ]))); } public function testRFCxxxSection3_1_available_optional_once() { $properties = [ '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([ $property, $property, ]))); } } public function testRFCxxxSection3_2() { $this->assertEquals( 'BUSY', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY', ])) ->VAVAILABILITY ->AVAILABLE ->BUSYTYPE ->getValue() ); $this->assertEquals( 'BUSY-UNAVAILABLE', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY-UNAVAILABLE', ])) ->VAVAILABILITY ->AVAILABLE ->BUSYTYPE ->getValue() ); $this->assertEquals( 'BUSY-TENTATIVE', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY-TENTATIVE', ])) ->VAVAILABILITY ->AVAILABLE ->BUSYTYPE ->getValue() ); } protected function assertIsValid(VObject\Document $document) { $validationResult = $document->validate(); if ($validationResult) { $messages = array_map(function ($item) { return $item['message']; }, $validationResult); $this->fail('Failed to assert that the supplied document is a valid document. Validation messages: '.implode(', ', $messages)); } $this->assertEmpty($document->validate()); } protected function assertIsNotValid(VObject\Document $document) { $this->assertNotEmpty($document->validate()); } protected function template(array $properties) { return $this->_template( <<_template( <<