php Sabre-HTTP-Sapi类(方法)实例源码

下面列出了php Sabre-HTTP-Sapi 类(方法)源码代码实例,从而了解它的用法。

作者:pagee    项目:sabre-da   
function testExpand()
    {
        $request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1']);
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120205T230000Z" end="20120212T225959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = VObject\Reader::read($body);
        // We only expect 3 events
        $this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body);
        // TZID should be gone
        $this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
    }

作者:BlaBlaNe    项目:hubzill   
function testCheckSuccess()
 {
     $request = HTTP\Sapi::createFromServerArray(['PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'password']);
     $response = new HTTP\Response();
     $backend = new AbstractBasicMock();
     $this->assertEquals([true, 'principals/username'], $backend->check($request, $response));
 }

作者:sebbie4    项目:casebo   
function testCorrect()
    {
        $xml = '<?xml version="1.0"?>
<d:principal-search-property-set xmlns:d="DAV:"/>';
        $serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals');
        $request = HTTP\Sapi::createFromServerArray($serverVars);
        $request->setBody($xml);
        $server = $this->getServer();
        $server->httpRequest = $request;
        $server->exec();
        $this->assertEquals(200, $server->httpResponse->status, $server->httpResponse->body);
        $this->assertEquals(array('X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['application/xml; charset=utf-8']), $server->httpResponse->getHeaders());
        $check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, '/d:principal-search-property-set/d:principal-search-property/d:description' => 2);
        $xml = simplexml_load_string($server->httpResponse->body);
        $xml->registerXPathNamespace('d', 'DAV:');
        $xml->registerXPathNamespace('s', 'http://sabredav.org/ns');
        foreach ($check as $v1 => $v2) {
            $xpath = is_int($v1) ? $v2 : $v1;
            $result = $xml->xpath($xpath);
            $count = 1;
            if (!is_int($v1)) {
                $count = $v2;
            }
            $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
        }
    }

作者:BlaBlaNe    项目:hubzill   
function testRedirectRemoteUser()
 {
     $request = HTTP\Sapi::createFromServerArray(['REDIRECT_REMOTE_USER' => 'username']);
     $response = new HTTP\Response();
     $backend = new Apache();
     $this->assertEquals([true, 'principals/username'], $backend->check($request, $response));
 }

作者:sebbie4    项目:casebo   
function testPatchNoRange()
 {
     $this->node->put('00000000');
     $request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial']);
     $response = $this->request($request);
     $this->assertEquals(400, $response->status, 'Full response body:' . $response->body);
 }

作者:jakobsac    项目:sabre-da   
function testUnsupportedMethod()
 {
     $req = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/outbox', 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', 'HTTP_RECIPIENT' => 'mailto:user2@example.org', 'HTTP_CONTENT_TYPE' => 'text/calendar']);
     $body = ['BEGIN:VCALENDAR', 'METHOD:PUBLISH', 'BEGIN:VEVENT', 'END:VEVENT', 'END:VCALENDAR'];
     $req->setBody(implode("\r\n", $body));
     $this->assertHTTPStatus(501, $req);
 }

作者:BlaBlaNe    项目:hubzill   
function testIssue205()
    {
        $request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1']);
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:comp-filter name="VALARM">
                    <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
                </C:comp-filter>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        $this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
        $this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = VObject\Reader::read($body);
        $this->assertEquals(1, count($vObject->VEVENT));
    }

作者:siit    项目:choose-sa-clou   
function testCheckSuccess()
 {
     $request = HTTP\Sapi::createFromServerArray(array('HTTP_AUTHORIZATION' => 'Bearer valid'));
     $response = new HTTP\Response();
     $backend = new AbstractBearerMock();
     $this->assertEquals([true, 'principals/username'], $backend->check($request, $response));
 }

作者:MetallianFR6    项目:myroundcub   
function setUp()
    {
        $calendars = array(array('principaluri' => 'principals/user2', 'id' => 1, 'uri' => 'calendar1', '{' . CalDAV\Plugin::NS_CALDAV . '}calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR"), array('principaluri' => 'principals/user2', 'id' => 2, 'uri' => 'calendar2', '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT)));
        $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)), 2 => array('2.ics' => array('uri' => '2.ics', 'calendardata' => 'BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20110101T080000
DURATION:PT1H
END:VEVENT
END:VCALENDAR', 'calendarid' => 2)));
        $principalBackend = new DAVACL\PrincipalBackend\Mock();
        $this->caldavBackend = new CalDAV\Backend\MockScheduling($calendars, $calendarobjects);
        $tree = array(new DAVACL\PrincipalCollection($principalBackend), new CalDAV\CalendarRoot($principalBackend, $this->caldavBackend));
        $this->request = HTTP\Sapi::createFromServerArray(['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);
        // CalDAV plugin
        $this->plugin = new CalDAV\Plugin();
        $this->server->addPlugin($this->plugin);
        // Scheduling plugin
        $this->plugin = new Plugin();
        $this->server->addPlugin($this->plugin);
    }

作者:jakobsac    项目:sabre-da   
function testException()
 {
     $this->server->on('exception', [$this, 'exceptionHandler']);
     $req = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/not/exisitng']);
     $this->server->httpRequest = $req;
     $this->server->exec();
     $this->assertInstanceOf('Sabre\\DAV\\Exception\\NotFound', $this->exception);
 }

作者:sebbie4    项目:casebo   
function testComplexIf()
 {
     $serverVars = array('HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1> ["etag1"]) ' . '(Not <opaquelocktoken:token2>) (["etag2"]) <http://www.example.org/node2> ' . '(<opaquelocktoken:token3>) (Not <opaquelocktoken:token4>) (["etag3"])');
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $conditions = $this->server->getIfConditions($request);
     $compare = array(array('uri' => 'node1', 'tokens' => array(array('negate' => false, 'token' => 'opaquelocktoken:token1', 'etag' => '"etag1"'), array('negate' => true, 'token' => 'opaquelocktoken:token2', 'etag' => ''), array('negate' => false, 'token' => '', 'etag' => '"etag2"'))), array('uri' => 'node2', 'tokens' => array(array('negate' => false, 'token' => 'opaquelocktoken:token3', 'etag' => ''), array('negate' => true, 'token' => 'opaquelocktoken:token4', 'etag' => ''), array('negate' => false, 'token' => '', 'etag' => '"etag3"'))));
     $this->assertEquals($compare, $conditions);
 }

作者:sebbie4    项目:casebo   
function sendPROPFIND($body)
 {
     $serverVars = ['REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPFIND', 'HTTP_DEPTH' => '0'];
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
 }

作者:MetallianFR6    项目:myroundcub   
public function testPatchSuccess()
 {
     $this->node->put('00000000');
     $request = HTTP\Sapi::createFromServerArray(array('REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5', 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', 'HTTP_CONTENT_LENGTH' => 3));
     $request->setBody('111');
     $response = $this->request($request);
     $this->assertEquals(204, $response->status, 'Full response body:' . $response->body);
     $this->assertEquals('00011100', $this->node->get());
 }

作者:sebbie4    项目:casebo   
function testCheck()
 {
     $digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/'));
     $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=' . $digestHash . ', opaque=1, qop=auth, nc=1, cnonce=1';
     $request = HTTP\Sapi::createFromServerArray(array('REQUEST_METHOD' => 'GET', 'PHP_AUTH_DIGEST' => $header, 'REQUEST_URI' => '/'));
     $response = new HTTP\Response();
     $backend = new AbstractDigestMock();
     $this->assertEquals([true, 'principals/user'], $backend->check($request, $response));
 }

作者:sebbie4    项目:casebo   
function testCollectionGet()
 {
     $serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET');
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $request->setBody('');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(207, $this->response->status, 'Incorrect status response received. Full response body: ' . $this->response->body);
     $this->assertEquals(array('X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['application/xml; charset=utf-8'], 'DAV' => ['1, 3, extended-mkcol'], 'Vary' => ['Brief,Prefer']), $this->response->getHeaders());
 }

作者:MetallianFR6    项目:myroundcub   
function testRedirectRemoteUser()
 {
     $backend = new Apache();
     $server = new DAV\Server();
     $request = HTTP\Sapi::createFromServerArray(['REDIRECT_REMOTE_USER' => 'username']);
     $server->httpRequest = $request;
     $this->assertTrue($backend->authenticate($server, 'Realm'));
     $userInfo = 'username';
     $this->assertEquals($userInfo, $backend->getCurrentUser());
 }

作者:siit    项目:choose-sa-clou   
function testExport()
 {
     $request = HTTP\Sapi::createFromServerArray(array('REQUEST_URI' => '/addressbooks/user1/book1?export', 'QUERY_STRING' => 'export', 'REQUEST_METHOD' => 'GET'));
     $response = $this->request($request);
     $this->assertEquals(200, $response->status, $response->body);
     $expected = "BEGIN:VCARD\nFN:Person1\nEND:VCARD\nBEGIN:VCARD\nFN:Person2\nEND:VCARD\nBEGIN:VCARD\nFN:Person3\nEND:VCARD\nBEGIN:VCARD\nFN:Person4\nEND:VCARD\n";
     // We actually expected windows line endings
     $expected = str_replace("\n", "\r\n", $expected);
     $this->assertEquals($expected, $response->body);
 }

作者:matte    项目:sabre-da   
function testOptions()
 {
     $serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'OPTIONS');
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('DAV' => '1, 3, extended-mkcol, drinking', 'MS-Author-Via' => 'DAV', 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE', 'Accept-Ranges' => 'bytes', 'Content-Length' => '0', 'X-Sabre-Version' => Version::VERSION), $this->response->getHeaders());
     $this->assertEquals(200, $this->response->status);
     $this->assertEquals('', $this->response->body);
     $this->assertEquals('OPTIONS', $this->testPlugin->beforeMethod);
 }

作者:sebbie4    项目:casebo   
function testUpdateFileParsableBody()
 {
     $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
     $request = HTTP\Sapi::createFromServerArray(array('REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf'));
     $body = "BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n";
     $request->setBody($body);
     $response = $this->request($request);
     $this->assertEquals(204, $response->status);
     $expected = array('uri' => 'blabla.vcf', 'carddata' => $body);
     $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
 }

作者:ninoslavjari    项目:practice-developmen   
/**
  * @depends testNoAdminAccess
  */
 function testAdminAccess()
 {
     $plugin = new Plugin();
     $plugin->adminPrincipals = array('principals/admin');
     $this->server->addPlugin($plugin);
     $request = HTTP\Sapi::createFromServerArray(array('REQUEST_METHOD' => 'OPTIONS', 'HTTP_DEPTH' => 1, 'REQUEST_URI' => '/adminonly'));
     $response = new HTTP\ResponseMock();
     $this->server->httpRequest = $request;
     $this->server->httpResponse = $response;
     $this->server->exec();
     $this->assertEquals(200, $response->status);
 }


问题


面经


文章

微信
公众号

扫码关注公众号