Beispiel #1
0
 /**
  * @return string
  * @since 8.1.0
  */
 public function render()
 {
     $r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
     $r->setTotalItems($this->itemscount);
     $r->setItemsPerPage($this->itemsperpage);
     return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
 }
Beispiel #2
0
 public function testUpdateOtherPermissions()
 {
     $ocs = $this->mockFormatShare();
     $file = $this->getMock('\\OCP\\Files\\File');
     $share = \OC::$server->getShareManager()->newShare();
     $share->setPermissions(\OCP\Constants::PERMISSION_ALL)->setSharedBy($this->currentUser->getUID())->setShareType(\OCP\Share::SHARE_TYPE_USER)->setNode($file);
     $this->request->method('getParam')->will($this->returnValueMap([['permissions', null, '31']]));
     $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
     $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
     $this->shareManager->expects($this->once())->method('updateShare')->with($this->callback(function (\OCP\Share\IShare $share) {
         return $share->getPermissions() === \OCP\Constants::PERMISSION_ALL;
     }))->will($this->returnArgument(0));
     $expected = new \OC_OCS_Result(null);
     $result = $ocs->updateShare(42);
     $this->assertEquals($expected->getMeta(), $result->getMeta());
     $this->assertEquals($expected->getData(), $result->getData());
 }
Beispiel #3
0
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === API::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     foreach ($result->getHeaders() as $name => $value) {
         header($name . ': ' . $value);
     }
     $meta = $result->getMeta();
     $data = $result->getData();
     if (self::isV2(\OC::$server->getRequest())) {
         $statusCode = self::mapStatusCodes($result->getStatusCode());
         if (!is_null($statusCode)) {
             $meta['statuscode'] = $statusCode;
             OC_Response::setStatus($statusCode);
         }
     }
     self::setContentType($format);
     $body = self::renderResult($format, $meta, $data);
     echo $body;
 }
Beispiel #4
0
 /**
  * @param \OC_OCS_Result $ocs
  * @param string $message
  */
 protected function assertOCSError(\OC_OCS_Result $ocs, $message)
 {
     $this->assertSame(Http::STATUS_BAD_REQUEST, $ocs->getStatusCode(), 'Expected status code 400');
     $this->assertSame([], $ocs->getData(), 'Expected that no data is send');
     $meta = $ocs->getMeta();
     $this->assertNotEmpty($meta);
     $this->assertArrayHasKey('message', $meta);
     $this->assertSame($message, $meta['message']);
 }
Beispiel #5
0
 public function testCreateShareGroup()
 {
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $this->shareManager->method('newShare')->willReturn($share);
     $ocs = $this->getMockBuilder('OCA\\Files_Sharing\\API\\Share20OCS')->setConstructorArgs([$this->shareManager, $this->groupManager, $this->userManager, $this->request, $this->rootFolder, $this->urlGenerator, $this->currentUser])->setMethods(['formatShare'])->getMock();
     $this->request->method('getParam')->will($this->returnValueMap([['path', null, 'valid-path'], ['permissions', null, \OCP\Constants::PERMISSION_ALL], ['shareType', '-1', \OCP\Share::SHARE_TYPE_GROUP], ['shareWith', null, 'validGroup']]));
     $userFolder = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->once())->method('getUserFolder')->with('currentUser')->willReturn($userFolder);
     $path = $this->getMock('\\OCP\\Files\\Folder');
     $userFolder->expects($this->once())->method('get')->with('valid-path')->willReturn($path);
     $group = $this->getMock('\\OCP\\IGroup');
     $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
     $this->groupManager->method('get')->with('validGroup')->willReturn($group);
     $share->method('setPath')->with($path);
     $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL);
     $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP);
     $share->method('setSharedWith')->with($group);
     $share->method('setSharedBy')->with($this->currentUser);
     $expected = new \OC_OCS_Result();
     $result = $ocs->createShare();
     $this->assertEquals($expected->getMeta(), $result->getMeta());
     $this->assertEquals($expected->getData(), $result->getData());
 }
Beispiel #6
0
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === self::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     $response = array('ocs' => array('meta' => $result->getMeta(), 'data' => $result->getData()));
     if ($format == 'json') {
         OC_JSON::encodedPrint($response);
     } else {
         if ($format == 'xml') {
             header('Content-type: text/xml; charset=UTF-8');
             $writer = new XMLWriter();
             $writer->openMemory();
             $writer->setIndent(true);
             $writer->startDocument();
             self::toXML($response, $writer);
             $writer->endDocument();
             echo $writer->outputMemory(true);
         }
     }
 }
Beispiel #7
0
 /**
  * @param OC_OCS_Result $result
  * @param string $format
  * @return string
  */
 public static function renderResult($result, $format)
 {
     $response = array('ocs' => array('meta' => $result->getMeta(), 'data' => $result->getData()));
     if ($format == 'json') {
         return OC_JSON::encode($response);
     }
     $writer = new XMLWriter();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->startDocument();
     self::toXML($response, $writer);
     $writer->endDocument();
     return $writer->outputMemory(true);
 }