summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-05-20 09:14:05 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-05-20 09:14:05 +0200
commit0c231f5ac65b22654ea6a41b96eaa5422119cb42 (patch)
tree1d991db9c051b3e51d2baf255b4e0800a3e380d3 /tests
parent7015dd74ce27db6e7c7cb2596e61343ac9f22902 (diff)
parent5733878d6657c6e02ba3ded9e7eab4a9ba3dafe3 (diff)
downloadnextcloud-server-0c231f5ac65b22654ea6a41b96eaa5422119cb42.tar.gz
nextcloud-server-0c231f5ac65b22654ea6a41b96eaa5422119cb42.zip
Merge pull request #15959 from owncloud/backport-15596-remote-share-feedback-urls
Backport 15596 remote share feedback urls
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share/share.php58
1 files changed, 56 insertions, 2 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 43539866508..8f3d927be34 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -105,6 +105,12 @@ class Test_Share extends \Test\TestCase {
parent::tearDown();
}
+ protected function setHttpHelper($httpHelper) {
+ \OC::$server->registerService('HTTPHelper', function () use ($httpHelper) {
+ return $httpHelper;
+ });
+ }
+
public function testShareInvalidShareType() {
$message = 'Share type foobar is not valid for test.txt';
try {
@@ -1015,10 +1021,58 @@ class Test_Share extends \Test\TestCase {
);
}
+ public function dataRemoteShareUrlCalls() {
+ return [
+ ['admin@localhost', 'localhost'],
+ ['admin@https://localhost', 'localhost'],
+ ['admin@http://localhost', 'localhost'],
+ ['admin@localhost/subFolder', 'localhost/subFolder'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataRemoteShareUrlCalls
+ *
+ * @param string $shareWith
+ * @param string $urlHost
+ */
+ public function testRemoteShareUrlCalls($shareWith, $urlHost) {
+ $oldHttpHelper = \OC::$server->query('HTTPHelper');
+ $httpHelperMock = $this->getMockBuilder('OC\HttpHelper')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->setHttpHelper($httpHelperMock);
+
+ $httpHelperMock->expects($this->at(0))
+ ->method('post')
+ ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything())
+ ->willReturn(['success' => false, 'result' => 'Exception']);
+ $httpHelperMock->expects($this->at(1))
+ ->method('post')
+ ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything())
+ ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
+
+ \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith, \OCP\Constants::PERMISSION_READ);
+ $shares = \OCP\Share::getItemShared('test', 'test.txt');
+ $share = array_shift($shares);
+
+ $httpHelperMock->expects($this->at(0))
+ ->method('post')
+ ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())
+ ->willReturn(['success' => false, 'result' => 'Exception']);
+ $httpHelperMock->expects($this->at(1))
+ ->method('post')
+ ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything())
+ ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]);
+
+ \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith);
+ $this->setHttpHelper($oldHttpHelper);
+ }
+
/**
* @dataProvider dataProviderTestGroupItems
- * @param type $ungrouped
- * @param type $grouped
+ * @param array $ungrouped
+ * @param array $grouped
*/
function testGroupItems($ungrouped, $grouped) {