'principals/user2', 'id' => 1, 'uri' => 'calendar1', ), ); $calendarobjects = array( 1 => array( '1.ics' => array( 'uri' => '1.ics', 'calendardata' => 'BEGIN:VCALENDAR BEGIN:VEVENT DTSTART:20110101T130000 DURATION:PT1H END:VEVENT END:VCALENDAR', 'calendarid' => 1, )) ); $principalBackend = new DAVACL\PrincipalBackend\Mock(); $caldavBackend = new Backend\Mock($calendars, $calendarobjects); $tree = array( new DAVACL\PrincipalCollection($principalBackend), new CalendarRootNode($principalBackend, $caldavBackend), ); $this->request = new HTTP\Request(array( 'CONTENT_TYPE' => 'text/calendar', )); $this->response = new HTTP\ResponseMock(); $this->server = new DAV\Server($tree); $this->server->httpRequest = $this->request; $this->server->httpResponse = $this->response; $this->aclPlugin = new DAVACL\Plugin(); $this->server->addPlugin($this->aclPlugin); $authBackend = new DAV\Auth\Backend\Mock(); $authBackend->setCurrentUser('user1'); $this->authPlugin = new DAV\Auth\Plugin($authBackend,'SabreDAV'); $this->server->addPlugin($this->authPlugin); $this->plugin = new Plugin(); $this->server->addPlugin($this->plugin); } function testWrongMethod() { $this->assertNull( $this->plugin->unknownMethod('PUT','calendars/user1/outbox') ); } function testWrongContentType() { $this->server->httpRequest = new HTTP\Request(array( 'CONTENT_TYPE' => 'text/plain', )); $this->assertNull( $this->plugin->unknownMethod('POST','calendars/user1/outbox') ); } function testNotFound() { $this->assertNull( $this->plugin->unknownMethod('POST','calendars/user1/blabla') ); } function testNotOutbox() { $this->assertNull( $this->plugin->unknownMethod('POST','calendars/user1/inbox') ); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testNoItipMethod() { $body = <<request->setBody($body); $this->plugin->unknownMethod('POST','calendars/user1/outbox'); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testNoVFreeBusy() { $body = <<request->setBody($body); $this->plugin->unknownMethod('POST','calendars/user1/outbox'); } /** * @expectedException Sabre\DAV\Exception\Forbidden */ function testIncorrectOrganizer() { $body = <<request->setBody($body); $this->plugin->unknownMethod('POST','calendars/user1/outbox'); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testNoAttendees() { $body = <<request->setBody($body); $this->plugin->unknownMethod('POST','calendars/user1/outbox'); } /** * @expectedException Sabre\DAV\Exception\BadRequest */ function testNoDTStart() { $body = <<request->setBody($body); $this->plugin->unknownMethod('POST','calendars/user1/outbox'); } function testSucceed() { $body = <<aclPlugin->adminPrincipals[] = 'principals/user1'; $this->request->setBody($body); $this->assertFalse($this->plugin->unknownMethod('POST','calendars/user1/outbox')); $this->assertEquals('HTTP/1.1 200 OK' , $this->response->status); $this->assertEquals(array( 'Content-Type' => 'application/xml', ), $this->response->headers); $strings = array( 'mailto:user2.sabredav@sabredav.org', 'mailto:user3.sabredav@sabredav.org', '2.0;Success', '3.7;Could not find principal', 'FREEBUSY;FBTYPE=BUSY:20110101T130000Z/20110101T140000Z', ); foreach($strings as $string) { $this->assertTrue( strpos($this->response->body, $string)!==false, 'The response body did not contain: ' . $string .'Full response: ' . $this->response->body ); } } function testNoPrivilege() { $body = <<request->setBody($body); $this->assertFalse($this->plugin->unknownMethod('POST','calendars/user1/outbox')); $this->assertEquals('HTTP/1.1 200 OK' , $this->response->status); $this->assertEquals(array( 'Content-Type' => 'application/xml', ), $this->response->headers); $strings = array( 'mailto:user2.sabredav@sabredav.org', '3.7;No calendar-home-set property found', ); foreach($strings as $string) { $this->assertTrue( strpos($this->response->body, $string)!==false, 'The response body did not contain: ' . $string .'Full response: ' . $this->response->body ); } } }