diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-29 10:52:43 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-29 10:52:43 +0200 |
commit | 8c7db2536dc1107bca6b427af25d713a97c0be96 (patch) | |
tree | 48442dc437f5855d708f22baa8e24d0ae4c86611 /tests/lib/share | |
parent | 7df7a3b3602cd3a733c79255cee95ce324f729fa (diff) | |
parent | b55ef51a27e73a30e0829e273cdf111e21a77403 (diff) | |
download | nextcloud-server-8c7db2536dc1107bca6b427af25d713a97c0be96.tar.gz nextcloud-server-8c7db2536dc1107bca6b427af25d713a97c0be96.zip |
Merge pull request #15596 from owncloud/issue/15589
Correctly generate the feedback URL for remote share
Diffstat (limited to 'tests/lib/share')
-rw-r--r-- | tests/lib/share/share.php | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index cda895a437d..abdddfb5584 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 { @@ -1024,10 +1030,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) { |