ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BrokerTester.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject\ITip;
4
5use PHPUnit\Framework\TestCase;
7
15abstract class BrokerTester extends TestCase {
16
17 use \Sabre\VObject\PHPUnitAssertions;
18
19 function parse($oldMessage, $newMessage, $expected = [], $currentUser = 'mailto:one@example.org') {
20
21 $broker = new Broker();
22 $result = $broker->parseEvent($newMessage, $currentUser, $oldMessage);
23
24 $this->assertEquals(count($expected), count($result));
25
26 foreach ($expected as $index => $ex) {
27
29
30 foreach ($ex as $key => $val) {
31
32 if ($key === 'message') {
33 $this->assertVObjectEqualsVObject(
34 $val,
35 $message->message->serialize()
36 );
37 } else {
38 $this->assertEquals($val, $message->$key);
39 }
40
41 }
42
43 }
44
45 }
46
47 function process($input, $existingObject = null, $expected = false) {
48
50
52
53 foreach ($vcal->getComponents() as $mainComponent) {
54 break;
55 }
56
57 $message = new Message();
58 $message->message = $vcal;
59 $message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null;
60 $message->component = $mainComponent->name;
61 $message->uid = $mainComponent->UID->getValue();
62 $message->sequence = isset($vcal->VEVENT[0]) ? (string)$vcal->VEVENT[0]->SEQUENCE : null;
63
64 if ($message->method === 'REPLY') {
65
66 $message->sender = $mainComponent->ATTENDEE->getValue();
67 $message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null;
68 $message->recipient = $mainComponent->ORGANIZER->getValue();
69 $message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null;
70
71 }
72
73 $broker = new Broker();
74
75 if (is_string($existingObject)) {
76 $existingObject = str_replace(
77 '%foo%',
78 "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject $version//EN\nCALSCALE:GREGORIAN",
79 $existingObject
80 );
81 $existingObject = Reader::read($existingObject);
82 }
83
84 $result = $broker->processMessage($message, $existingObject);
85
86 if (is_null($expected)) {
87 $this->assertTrue(!$result);
88 return;
89 }
90
91 $this->assertVObjectEqualsVObject(
92 $expected,
94 );
95
96 }
97}
$result
$version
Definition: build.php:27
An exception for terminatinating execution or to throw for unit testing.
Utilities for testing the broker.
parse($oldMessage, $newMessage, $expected=[], $currentUser='mailto:one @example.org')
process($input, $existingObject=null, $expected=false)
The ITip\Broker class is a utility class that helps with processing so-called iTip messages.
Definition: Broker.php:38
This class represents an iTip message.
Definition: Message.php:17
iCalendar/vCard/jCal/jCard/xCal/xCard reader object.
Definition: Reader.php:15
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
const VERSION
Full version number.
Definition: Version.php:17
$key
Definition: croninfo.php:18
$index
Definition: metadata.php:60
catch(Exception $e) $message
foreach( $paths as $path) if(!class_exists( 'Sabre\\VObject\\Version'))
foreach($paths as $path) if($argc< 3) $input