本文整理汇总了PHP中Sabre_HTTP_Request::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Sabre_HTTP_Request::setBody方法的具体用法?PHP Sabre_HTTP_Request::setBody怎么用?PHP Sabre_HTTP_Request::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre_HTTP_Request
的用法示例。
在下文中一共展示了Sabre_HTTP_Request::setBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetBodyStream
function testSetGetBodyStream()
{
$h = fopen('php://memory', 'r+');
fwrite($h, 'testing');
rewind($h);
$this->request->setBody($h);
$this->assertEquals('testing', stream_get_contents($this->request->getBody()), 'We didn\'t get our testbody back');
}
示例2: substr
function testIssue205()
{
$request = new Sabre_HTTP_Request(array('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(' ', '', $body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));
}
示例3: testExpand
function testExpand()
{
$request = new Sabre_HTTP_Request(array('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(' ', '', $body);
$vObject = Sabre_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']));
}
示例4: testExpand
/**
* @depends testSimple
*/
function testExpand()
{
$xml = '<?xml version="1.0"?>
<d:expand-property xmlns:d="DAV:">
<d:property name="current-user-principal">
<d:property name="displayname" />
</d:property>
</d:expand-property>';
$serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/');
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody($xml);
$server = $this->getServer();
$server->httpRequest = $request;
$server->exec();
$this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status);
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
$check = array('/d:multistatus', '/d:multistatus/d:response' => 1, '/d:multistatus/d:response/d:href' => 1, '/d:multistatus/d:response/d:propstat' => 1, '/d:multistatus/d:response/d:propstat/d:prop' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:href' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat/d:prop' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat/d:prop/d:displayname' => 1);
$xml = simplexml_load_string($server->httpResponse->body);
$xml->registerXPathNamespace('d', 'DAV:');
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));
}
}
示例5: testCorrect
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 = new Sabre_HTTP_Request($serverVars);
$request->setBody($xml);
$server = $this->getServer();
$server->httpRequest = $request;
$server->exec();
$this->assertEquals('HTTP/1.1 200 Ok', $server->httpResponse->status, $server->httpResponse->body);
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
$check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property', '/d:principal-search-property-set/d:principal-search-property/d:prop', '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname', '/d:principal-search-property-set/d:principal-search-property/d:description');
$xml = simplexml_load_string($server->httpResponse->body);
$xml->registerXPathNamespace('d', 'DAV:');
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);
}
}
示例6: testQueryTimerange
function testQueryTimerange()
{
$request = new Sabre_HTTP_Request(array('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="20120226T230000Z" end="20120228T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
$this->fail('Got no events instead of 1. Output: ' . $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(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
}
示例7: sendPROPFIND
public function sendPROPFIND($body)
{
$serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPFIND', 'HTTP_DEPTH' => '0');
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
}
示例8: testPatchSuccess
public function testPatchSuccess()
{
$this->node->put('00000000');
$request = new Sabre_HTTP_Request(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('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
$this->assertEquals('00111000', $this->node->get());
}
示例9: testUpdateFileParsableBody
function testUpdateFileParsableBody()
{
$this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
$request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics'));
$request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
$this->assertEquals('HTTP/1.1 204 No Content', $response->status);
$expected = array('uri' => 'blabla.ics', 'calendardata' => "BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", 'calendarid' => 'calendar1');
$this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
}
示例10: testCollectionGet
function testCollectionGet()
{
$serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET');
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('');
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8', 'DAV' => '1, 3, extended-mkcol'), $this->response->headers);
$this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Incorrect status response received. Full response body: ' . $this->response->body);
}
示例11: testUpdateFileParsableBody
function testUpdateFileParsableBody()
{
$this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
$request = new Sabre_HTTP_Request(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('HTTP/1.1 204 No Content', $response->status);
$expected = array('uri' => 'blabla.vcf', 'carddata' => $body);
$this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
}
示例12: testPutFail
function testPutFail()
{
$serverVars = array('REQUEST_URI' => '/testput.txt', 'REQUEST_METHOD' => 'PUT', 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20');
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('');
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status);
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $this->response->headers);
$this->assertFalse(file_exists(SABRE_TEMPDIR . '/testput.txt'));
}
示例13: testReportPassThrough
function testReportPassThrough()
{
$fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleDirectory('bla')));
$plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'realm');
$fakeServer->addPlugin($plugin);
$request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/'));
$request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
$fakeServer->httpRequest = $request;
$fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
$fakeServer->exec();
$this->assertEquals('HTTP/1.1 501 Not Implemented', $fakeServer->httpResponse->status);
}
示例14: testPutUpdate
function testPutUpdate()
{
$serverVars = array('REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT');
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('Testing updated file');
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals('0', $this->response->headers['Content-Length']);
$this->assertEquals('HTTP/1.1 204 No Content', $this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertEquals('Testing updated file', file_get_contents($this->tempDir . '/test.txt'));
}
示例15: testDigestAuthInt
public function testDigestAuthInt()
{
$this->auth->setQOP(Sabre_HTTP_DigestAuth::QOP_AUTHINT | Sabre_HTTP_DigestAuth::QOP_AUTH);
list($nonce, $opaque) = $this->getServerTokens(Sabre_HTTP_DigestAuth::QOP_AUTHINT | Sabre_HTTP_DigestAuth::QOP_AUTH);
$username = 'admin';
$password = 12345;
$nc = '00003';
$cnonce = uniqid();
$digestHash = md5(md5($username . ':' . self::REALM . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . 'auth-int:' . md5('POST' . ':' . '/' . ':' . md5('body')));
$request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'POST', 'PHP_AUTH_DIGEST' => 'username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"'));
$request->setBody('body');
$this->auth->setHTTPRequest($request);
$this->auth->init();
$this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1');
}