1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Schedule; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\VObject\ITip\Message; 6*a1a3b679SAndreas Boehleruse Sabre\VObject\Reader; 7*a1a3b679SAndreas Boehleruse Sabre\DAV\Server; 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehlerclass IMipPluginTest extends \PHPUnit_Framework_TestCase { 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehler function testGetPluginInfo() { 12*a1a3b679SAndreas Boehler 13*a1a3b679SAndreas Boehler $plugin = new IMipPlugin('system@example.com'); 14*a1a3b679SAndreas Boehler $this->assertEquals( 15*a1a3b679SAndreas Boehler 'imip', 16*a1a3b679SAndreas Boehler $plugin->getPluginInfo()['name'] 17*a1a3b679SAndreas Boehler ); 18*a1a3b679SAndreas Boehler 19*a1a3b679SAndreas Boehler } 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler function testDeliverReply() { 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler $message = new Message(); 24*a1a3b679SAndreas Boehler $message->sender = 'mailto:sender@example.org'; 25*a1a3b679SAndreas Boehler $message->senderName = 'Sender'; 26*a1a3b679SAndreas Boehler $message->recipient = 'mailto:recipient@example.org'; 27*a1a3b679SAndreas Boehler $message->recipientName = 'Recipient'; 28*a1a3b679SAndreas Boehler $message->method = 'REPLY'; 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler $ics = <<<ICS 31*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR\r 32*a1a3b679SAndreas BoehlerMETHOD:REPLY\r 33*a1a3b679SAndreas BoehlerBEGIN:VEVENT\r 34*a1a3b679SAndreas BoehlerSUMMARY:Birthday party\r 35*a1a3b679SAndreas BoehlerEND:VEVENT\r 36*a1a3b679SAndreas BoehlerEND:VCALENDAR\r 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas BoehlerICS; 39*a1a3b679SAndreas Boehler 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler $message->message = Reader::read($ics); 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler $result = $this->schedule($message); 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler $expected = [ 46*a1a3b679SAndreas Boehler [ 47*a1a3b679SAndreas Boehler 'to' => 'Recipient <recipient@example.org>', 48*a1a3b679SAndreas Boehler 'subject' => 'Re: Birthday party', 49*a1a3b679SAndreas Boehler 'body' => $ics, 50*a1a3b679SAndreas Boehler 'headers' => [ 51*a1a3b679SAndreas Boehler 'Reply-To: Sender <sender@example.org>', 52*a1a3b679SAndreas Boehler 'From: system@example.org', 53*a1a3b679SAndreas Boehler 'Content-Type: text/calendar; charset=UTF-8; method=REPLY', 54*a1a3b679SAndreas Boehler 'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION, 55*a1a3b679SAndreas Boehler ], 56*a1a3b679SAndreas Boehler ] 57*a1a3b679SAndreas Boehler ]; 58*a1a3b679SAndreas Boehler 59*a1a3b679SAndreas Boehler $this->assertEquals($expected, $result); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler } 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler function testDeliverReplyNoMailto() { 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler $message = new Message(); 66*a1a3b679SAndreas Boehler $message->sender = 'mailto:sender@example.org'; 67*a1a3b679SAndreas Boehler $message->senderName = 'Sender'; 68*a1a3b679SAndreas Boehler $message->recipient = 'http://example.org/recipient'; 69*a1a3b679SAndreas Boehler $message->recipientName = 'Recipient'; 70*a1a3b679SAndreas Boehler $message->method = 'REPLY'; 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler $ics = <<<ICS 73*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR\r 74*a1a3b679SAndreas BoehlerMETHOD:REPLY\r 75*a1a3b679SAndreas BoehlerBEGIN:VEVENT\r 76*a1a3b679SAndreas BoehlerSUMMARY:Birthday party\r 77*a1a3b679SAndreas BoehlerEND:VEVENT\r 78*a1a3b679SAndreas BoehlerEND:VCALENDAR\r 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas BoehlerICS; 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler $message->message = Reader::read($ics); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $result = $this->schedule($message); 86*a1a3b679SAndreas Boehler 87*a1a3b679SAndreas Boehler $expected = []; 88*a1a3b679SAndreas Boehler 89*a1a3b679SAndreas Boehler $this->assertEquals($expected, $result); 90*a1a3b679SAndreas Boehler 91*a1a3b679SAndreas Boehler } 92*a1a3b679SAndreas Boehler 93*a1a3b679SAndreas Boehler function testDeliverRequest() { 94*a1a3b679SAndreas Boehler 95*a1a3b679SAndreas Boehler $message = new Message(); 96*a1a3b679SAndreas Boehler $message->sender = 'mailto:sender@example.org'; 97*a1a3b679SAndreas Boehler $message->senderName = 'Sender'; 98*a1a3b679SAndreas Boehler $message->recipient = 'mailto:recipient@example.org'; 99*a1a3b679SAndreas Boehler $message->recipientName = 'Recipient'; 100*a1a3b679SAndreas Boehler $message->method = 'REQUEST'; 101*a1a3b679SAndreas Boehler 102*a1a3b679SAndreas Boehler $ics = <<<ICS 103*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR\r 104*a1a3b679SAndreas BoehlerMETHOD:REQUEST\r 105*a1a3b679SAndreas BoehlerBEGIN:VEVENT\r 106*a1a3b679SAndreas BoehlerSUMMARY:Birthday party\r 107*a1a3b679SAndreas BoehlerEND:VEVENT\r 108*a1a3b679SAndreas BoehlerEND:VCALENDAR\r 109*a1a3b679SAndreas Boehler 110*a1a3b679SAndreas BoehlerICS; 111*a1a3b679SAndreas Boehler 112*a1a3b679SAndreas Boehler 113*a1a3b679SAndreas Boehler $message->message = Reader::read($ics); 114*a1a3b679SAndreas Boehler 115*a1a3b679SAndreas Boehler $result = $this->schedule($message); 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler $expected = [ 118*a1a3b679SAndreas Boehler [ 119*a1a3b679SAndreas Boehler 'to' => 'Recipient <recipient@example.org>', 120*a1a3b679SAndreas Boehler 'subject' => 'Birthday party', 121*a1a3b679SAndreas Boehler 'body' => $ics, 122*a1a3b679SAndreas Boehler 'headers' => [ 123*a1a3b679SAndreas Boehler 'Reply-To: Sender <sender@example.org>', 124*a1a3b679SAndreas Boehler 'From: system@example.org', 125*a1a3b679SAndreas Boehler 'Content-Type: text/calendar; charset=UTF-8; method=REQUEST', 126*a1a3b679SAndreas Boehler 'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION, 127*a1a3b679SAndreas Boehler ], 128*a1a3b679SAndreas Boehler ] 129*a1a3b679SAndreas Boehler ]; 130*a1a3b679SAndreas Boehler 131*a1a3b679SAndreas Boehler $this->assertEquals($expected, $result); 132*a1a3b679SAndreas Boehler 133*a1a3b679SAndreas Boehler } 134*a1a3b679SAndreas Boehler 135*a1a3b679SAndreas Boehler function testDeliverCancel() { 136*a1a3b679SAndreas Boehler 137*a1a3b679SAndreas Boehler $message = new Message(); 138*a1a3b679SAndreas Boehler $message->sender = 'mailto:sender@example.org'; 139*a1a3b679SAndreas Boehler $message->senderName = 'Sender'; 140*a1a3b679SAndreas Boehler $message->recipient = 'mailto:recipient@example.org'; 141*a1a3b679SAndreas Boehler $message->recipientName = 'Recipient'; 142*a1a3b679SAndreas Boehler $message->method = 'CANCEL'; 143*a1a3b679SAndreas Boehler 144*a1a3b679SAndreas Boehler $ics = <<<ICS 145*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR\r 146*a1a3b679SAndreas BoehlerMETHOD:CANCEL\r 147*a1a3b679SAndreas BoehlerBEGIN:VEVENT\r 148*a1a3b679SAndreas BoehlerSUMMARY:Birthday party\r 149*a1a3b679SAndreas BoehlerEND:VEVENT\r 150*a1a3b679SAndreas BoehlerEND:VCALENDAR\r 151*a1a3b679SAndreas Boehler 152*a1a3b679SAndreas BoehlerICS; 153*a1a3b679SAndreas Boehler 154*a1a3b679SAndreas Boehler 155*a1a3b679SAndreas Boehler $message->message = Reader::read($ics); 156*a1a3b679SAndreas Boehler 157*a1a3b679SAndreas Boehler $result = $this->schedule($message); 158*a1a3b679SAndreas Boehler 159*a1a3b679SAndreas Boehler $expected = [ 160*a1a3b679SAndreas Boehler [ 161*a1a3b679SAndreas Boehler 'to' => 'Recipient <recipient@example.org>', 162*a1a3b679SAndreas Boehler 'subject' => 'Cancelled: Birthday party', 163*a1a3b679SAndreas Boehler 'body' => $ics, 164*a1a3b679SAndreas Boehler 'headers' => [ 165*a1a3b679SAndreas Boehler 'Reply-To: Sender <sender@example.org>', 166*a1a3b679SAndreas Boehler 'From: system@example.org', 167*a1a3b679SAndreas Boehler 'Content-Type: text/calendar; charset=UTF-8; method=CANCEL', 168*a1a3b679SAndreas Boehler 'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION, 169*a1a3b679SAndreas Boehler ], 170*a1a3b679SAndreas Boehler ] 171*a1a3b679SAndreas Boehler ]; 172*a1a3b679SAndreas Boehler 173*a1a3b679SAndreas Boehler $this->assertEquals($expected, $result); 174*a1a3b679SAndreas Boehler $this->assertEquals('1.1', substr($message->scheduleStatus, 0, 3)); 175*a1a3b679SAndreas Boehler 176*a1a3b679SAndreas Boehler } 177*a1a3b679SAndreas Boehler 178*a1a3b679SAndreas Boehler function schedule(Message $message) { 179*a1a3b679SAndreas Boehler 180*a1a3b679SAndreas Boehler $plugin = new IMip\MockPlugin('system@example.org'); 181*a1a3b679SAndreas Boehler 182*a1a3b679SAndreas Boehler $server = new Server(); 183*a1a3b679SAndreas Boehler $server->addPlugin($plugin); 184*a1a3b679SAndreas Boehler $server->emit('schedule', [$message]); 185*a1a3b679SAndreas Boehler 186*a1a3b679SAndreas Boehler return $plugin->getSentEmails(); 187*a1a3b679SAndreas Boehler 188*a1a3b679SAndreas Boehler } 189*a1a3b679SAndreas Boehler 190*a1a3b679SAndreas Boehler function testDeliverInsignificantRequest() { 191*a1a3b679SAndreas Boehler 192*a1a3b679SAndreas Boehler $message = new Message(); 193*a1a3b679SAndreas Boehler $message->sender = 'mailto:sender@example.org'; 194*a1a3b679SAndreas Boehler $message->senderName = 'Sender'; 195*a1a3b679SAndreas Boehler $message->recipient = 'mailto:recipient@example.org'; 196*a1a3b679SAndreas Boehler $message->recipientName = 'Recipient'; 197*a1a3b679SAndreas Boehler $message->method = 'REQUEST'; 198*a1a3b679SAndreas Boehler $message->significantChange = false; 199*a1a3b679SAndreas Boehler 200*a1a3b679SAndreas Boehler $ics = <<<ICS 201*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR\r 202*a1a3b679SAndreas BoehlerMETHOD:REQUEST\r 203*a1a3b679SAndreas BoehlerBEGIN:VEVENT\r 204*a1a3b679SAndreas BoehlerSUMMARY:Birthday party\r 205*a1a3b679SAndreas BoehlerEND:VEVENT\r 206*a1a3b679SAndreas BoehlerEND:VCALENDAR\r 207*a1a3b679SAndreas Boehler 208*a1a3b679SAndreas BoehlerICS; 209*a1a3b679SAndreas Boehler 210*a1a3b679SAndreas Boehler 211*a1a3b679SAndreas Boehler $message->message = Reader::read($ics); 212*a1a3b679SAndreas Boehler 213*a1a3b679SAndreas Boehler $result = $this->schedule($message); 214*a1a3b679SAndreas Boehler 215*a1a3b679SAndreas Boehler $expected = []; 216*a1a3b679SAndreas Boehler $this->assertEquals($expected, $result); 217*a1a3b679SAndreas Boehler $this->assertEquals('1.0', $message->getScheduleStatus()[0]); 218*a1a3b679SAndreas Boehler 219*a1a3b679SAndreas Boehler } 220*a1a3b679SAndreas Boehler 221*a1a3b679SAndreas Boehler} 222