annotate vendor/sabre/vobject/tests/VObject/ITip/BrokerTester.php @ 41:d2414df68d78 default tip

Updated by Alex S Grebenschikov (www.poralix.com) to make it compatible with RoundCube 1.3.0
author Charlie Root
date Fri, 24 Jan 2025 14:20:15 -0500
parents 430dbd5346f7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\ITip;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject\Reader;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * Utilities for testing the broker
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 abstract class BrokerTester extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 function parse($oldMessage, $newMessage, $expected = array(), $currentUser = 'mailto:one@example.org') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 $broker = new Broker();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 $result = $broker->parseEvent($newMessage, $currentUser, $oldMessage);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 $this->assertEquals(count($expected), count($result));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 foreach($expected as $index=>$ex) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 $message = $result[$index];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 foreach($ex as $key=>$val) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 if ($key==='message') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 str_replace("\n", "\r\n", $val),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 rtrim($message->message->serialize(), "\r\n")
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 $this->assertEquals($val, $message->$key);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 function process($input, $existingObject = null, $expected = false) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 $version = \Sabre\VObject\Version::VERSION;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 $vcal = Reader::read($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 foreach($vcal->getComponents() as $mainComponent) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 $message = new Message();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 $message->message = $vcal;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 $message->method = isset($vcal->METHOD)?$vcal->METHOD->getValue():null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 $message->component = $mainComponent->name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 $message->uid = $mainComponent->uid->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 $message->sequence = isset($vcal->VEVENT[0])?(string)$vcal->VEVENT[0]->SEQUENCE:null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 if ($message->method === 'REPLY') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 $message->sender = $mainComponent->ATTENDEE->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 $message->senderName = isset($mainComponent->ATTENDEE['CN'])?$mainComponent->ATTENDEE['CN']->getValue():null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 $message->recipient = $mainComponent->ORGANIZER->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 $message->recipientName = isset($mainComponent->ORGANIZER['CN'])?$mainComponent->ORGANIZER['CN']:null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 $broker = new Broker();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 if (is_string($existingObject)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 $existingObject = str_replace(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 '%foo%',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject $version//EN\nCALSCALE:GREGORIAN",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 $existingObject
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 $existingObject = Reader::read($existingObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 $result = $broker->processMessage($message, $existingObject);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 if (is_string($expected)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 $expected = str_replace(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 '%foo%',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject $version//EN\nCALSCALE:GREGORIAN",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 $expected
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 $expected = str_replace("\n", "\r\n", $expected);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 if ($result instanceof \Sabre\VObject\Component\VCalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 $result = $result->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 $result = rtrim($result,"\r\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 $expected,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 $result
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 }