Exemplo n.º 1
0
 function testLockEtc()
 {
     mkdir(SABRE_TEMPDIR . '/mstest');
     $tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
     $server = new DAV\Server($tree);
     $server->debugExceptions = true;
     $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
     $locksPlugin = new Plugin($locksBackend);
     $server->addPlugin($locksPlugin);
     $response1 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest();
     $server->httpResponse = $response1;
     $server->sapi = new HTTP\SapiMock();
     $server->exec();
     $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString());
     $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
     $lockToken = $server->httpResponse->getHeader('Lock-Token');
     //sleep(10);
     $response2 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getLockRequest2();
     $server->httpResponse = $response2;
     $server->exec();
     $this->assertEquals(201, $server->httpResponse->status);
     $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token'));
     //sleep(10);
     $response3 = new HTTP\ResponseMock();
     $server->httpRequest = $this->getPutRequest($lockToken);
     $server->httpResponse = $response3;
     $server->exec();
     $this->assertEquals(204, $server->httpResponse->status);
 }
Exemplo n.º 2
0
    function testNotificationGet()
    {
        $notification = new Node($this->caldavBackend, 'principals/user1', new Notification\SystemStatus('foo', '"1"'));
        $server = new DAV\Server(array($notification));
        $caldav = new Plugin();
        $server->httpRequest = HTTP\Sapi::createFromServerArray(array('REQUEST_URI' => '/foo.xml'));
        $httpResponse = new HTTP\ResponseMock();
        $server->httpResponse = $httpResponse;
        $server->addPlugin($caldav);
        $caldav->httpGet($server->httpRequest, $server->httpResponse);
        $this->assertEquals(200, $httpResponse->status);
        $this->assertEquals(array('Content-Type' => ['application/xml'], 'ETag' => ['"1"']), $httpResponse->getHeaders());
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<cs:notification xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cs="http://calendarserver.org/ns/">
  <cs:systemstatus type="high"/>
</cs:notification>
';
        $this->assertEquals($expected, $httpResponse->body);
    }
Exemplo n.º 3
0
    function testNotificationGet()
    {
        $notification = new Node($this->caldavBackend, 'principals/user1', new SystemStatus('foo', '"1"'));
        $server = new DAV\Server([$notification]);
        $caldav = new Plugin();
        $server->httpRequest = new Request('GET', '/foo.xml');
        $httpResponse = new HTTP\ResponseMock();
        $server->httpResponse = $httpResponse;
        $server->addPlugin($caldav);
        $caldav->httpGet($server->httpRequest, $server->httpResponse);
        $this->assertEquals(200, $httpResponse->status);
        $this->assertEquals(['Content-Type' => ['application/xml'], 'ETag' => ['"1"']], $httpResponse->getHeaders());
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<cs:notification xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cs="http://calendarserver.org/ns/">
 <cs:systemstatus type="high"/>
</cs:notification>
';
        $this->assertXmlStringEqualsXmlString($expected, $httpResponse->getBodyAsString());
    }
Exemplo n.º 4
0
 /**
  * Makes a request, and returns a response object.
  *
  * You can either pass an instance of Sabre\HTTP\Request, or an array,
  * which will then be used as the _SERVER array.
  *
  * If $expectedStatus is set, we'll compare it with the HTTP status of
  * the returned response. If it doesn't match, we'll immediately fail
  * the test.
  *
  * @param array|\Sabre\HTTP\Request $request
  * @param int $expectedStatus
  * @return \Sabre\HTTP\Response
  */
 function request($request, $expectedStatus = null)
 {
     if (is_array($request)) {
         $request = HTTP\Request::createFromServerArray($request);
     }
     $response = new HTTP\ResponseMock();
     $this->server->httpRequest = $request;
     $this->server->httpResponse = $response;
     $this->server->exec();
     if ($expectedStatus) {
         $responseBody = $expectedStatus !== $response->getStatus() ? $response->getBodyAsString() : '';
         $this->assertEquals($expectedStatus, $response->getStatus(), 'Incorrect HTTP status received for request. Response body: ' . $responseBody);
     }
     return $this->server->httpResponse;
 }