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