public function testPostException() { $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock(); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $client->expects($this->once())->method('post')->with('https://owncloud.org', ['body' => ['Foo' => 'Bar'], 'connect_timeout' => 10])->will($this->throwException(new \Exception('Something failed'))); $response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']); $expected = ['success' => false, 'result' => 'Something failed']; $this->assertSame($expected, $response); }
/** * inform remote server whether server-to-server share was accepted/declined * * @param string $remote * @param string $token * @param int $remoteId Share id on the remote host * @param string $feedback * @return boolean */ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { $url = rtrim($remote, '/') . \OCP\Share::BASE_PATH_TO_SHARE_API . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; $fields = array('token' => $token); $result = $this->httpHelper->post($url, $fields); $status = json_decode($result['result'], true); return $result['success'] && $status['ocs']['meta']['statuscode'] === 100; }
/** * inform remote server whether server-to-server share was accepted/declined * * @param string $remote * @param string $token * @param int $remoteId Share id on the remote host * @param string $feedback * @return boolean */ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; $fields = array('token' => $token); $result = $this->httpHelper->post($url, $fields); $status = json_decode($result['result'], true); return $result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); }