summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-04-27 22:07:35 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-05-04 10:46:20 +0200
commit2e0c3665b0a2a9635d5adf5e4339e4d329a600ce (patch)
tree50990d0a49ea943df27b31c825cf2d5a8b371b54
parentb1a9e26c453316ef27915bfedf2f1435cd443952 (diff)
downloadnextcloud-server-2e0c3665b0a2a9635d5adf5e4339e4d329a600ce.tar.gz
nextcloud-server-2e0c3665b0a2a9635d5adf5e4339e4d329a600ce.zip
Add tests for the remote sharing url
-rw-r--r--tests/lib/share/share.php55
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 43539866508..cbb54bf09ff 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 ($c) use ($httpHelper) {
+ return $httpHelper;
+ });
+ }
+
public function testShareInvalidShareType() {
$message = 'Share type foobar is not valid for test.txt';
try {
@@ -1015,10 +1021,55 @@ 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]]])]);
+
+ $httpHelperMock->expects($this->at(2))
+ ->method('post')
+ ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything())
+ ->willReturn(['success' => false, 'result' => 'Exception']);
+ $httpHelperMock->expects($this->at(3))
+ ->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);
+ \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) {