1<?php 2 3namespace Sabre\VObject\ITip; 4 5use Sabre\VObject\Reader; 6 7/** 8 * Utilities for testing the broker 9 * 10 * @copyright Copyright (C) fruux GmbH (https://fruux.com/) 11 * @author Evert Pot (http://evertpot.com/) 12 * @license http://sabre.io/license/ Modified BSD License 13 */ 14abstract class BrokerTester extends \PHPUnit_Framework_TestCase { 15 16 use \Sabre\VObject\PHPUnitAssertions; 17 18 function parse($oldMessage, $newMessage, $expected = [], $currentUser = 'mailto:one@example.org') { 19 20 $broker = new Broker(); 21 $result = $broker->parseEvent($newMessage, $currentUser, $oldMessage); 22 23 $this->assertEquals(count($expected), count($result)); 24 25 foreach ($expected as $index => $ex) { 26 27 $message = $result[$index]; 28 29 foreach ($ex as $key => $val) { 30 31 if ($key === 'message') { 32 $this->assertVObjectEqualsVObject( 33 $val, 34 $message->message->serialize() 35 ); 36 } else { 37 $this->assertEquals($val, $message->$key); 38 } 39 40 } 41 42 } 43 44 } 45 46 function process($input, $existingObject = null, $expected = false) { 47 48 $version = \Sabre\VObject\Version::VERSION; 49 50 $vcal = Reader::read($input); 51 52 foreach ($vcal->getComponents() as $mainComponent) { 53 break; 54 } 55 56 $message = new Message(); 57 $message->message = $vcal; 58 $message->method = isset($vcal->METHOD) ? $vcal->METHOD->getValue() : null; 59 $message->component = $mainComponent->name; 60 $message->uid = $mainComponent->UID->getValue(); 61 $message->sequence = isset($vcal->VEVENT[0]) ? (string)$vcal->VEVENT[0]->SEQUENCE : null; 62 63 if ($message->method === 'REPLY') { 64 65 $message->sender = $mainComponent->ATTENDEE->getValue(); 66 $message->senderName = isset($mainComponent->ATTENDEE['CN']) ? $mainComponent->ATTENDEE['CN']->getValue() : null; 67 $message->recipient = $mainComponent->ORGANIZER->getValue(); 68 $message->recipientName = isset($mainComponent->ORGANIZER['CN']) ? $mainComponent->ORGANIZER['CN'] : null; 69 70 } 71 72 $broker = new Broker(); 73 74 if (is_string($existingObject)) { 75 $existingObject = str_replace( 76 '%foo%', 77 "VERSION:2.0\nPRODID:-//Sabre//Sabre VObject $version//EN\nCALSCALE:GREGORIAN", 78 $existingObject 79 ); 80 $existingObject = Reader::read($existingObject); 81 } 82 83 $result = $broker->processMessage($message, $existingObject); 84 85 if (is_null($expected)) { 86 $this->assertTrue(!$result); 87 return; 88 } 89 90 $this->assertVObjectEqualsVObject( 91 $expected, 92 $result 93 ); 94 95 } 96} 97