From b3ea849a8704d29fad0a738af8af3430ebb5b3af Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 26 Jan 2015 16:09:14 +0100 Subject: [PATCH 1/9] Added capabilities whether a server allows public links This fixes #13673. It now lists link sharing, passwords enforced, and if public uploads are allowed. --- apps/files_sharing/appinfo/routes.php | 7 ++++ apps/files_sharing/lib/capabilities.php | 53 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 apps/files_sharing/lib/capabilities.php diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index dd9509575b..44ab5c0de9 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -56,3 +56,10 @@ $this->create('sharing_external_test_remote', '/testremote') '/apps/files_sharing/api/v1/shares/{id}', array('\OCA\Files_Sharing\API\Local', 'deleteShare'), 'files_sharing'); + +// Register with the capabilities API +\OC_API::register('get', + '/cloud/capabilities', + array('OCA\Files_Sharing\Capabilities', 'getCapabilities'), + 'files_sharing', + \OC_API::USER_AUTH); diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php new file mode 100644 index 0000000000..712eb2317b --- /dev/null +++ b/apps/files_sharing/lib/capabilities.php @@ -0,0 +1,53 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing; + + +/** + * Class Capabilities + * + * @package OCA\Files_Sharing + */ +class Capabilities { + + /** + * @return \OC_OCS_Result + */ + public static function getCapabilities() { + $config = \OC::$server->getConfig(); + + $res = array(); + if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === "yes") { + $res["allow_links"] = 1; + + if ($config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === "yes") { + $res["enforce_links_password"] = 1; + } else { + $res["enforce_links_password"] = 0; + } + + if ($config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === "yes") { + $res["allow_public_upload"] = 1; + } else { + $res["allow_public_upload"] = 0; + } + } else { + $res["allow_links"] = 0; + } + + return new \OC_OCS_Result(array( + 'capabilities' => array( + 'files' => array( + 'sharing' => $res + ), + ), + )); + } + +} From ea1f726b7defe1161e22c3d2972d85fbb530d182 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 26 Jan 2015 16:14:05 +0100 Subject: [PATCH 2/9] Only return capabilities if they are set --- apps/files_sharing/lib/capabilities.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 712eb2317b..25b0484b2e 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -24,28 +24,22 @@ class Capabilities { $res = array(); if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === "yes") { - $res["allow_links"] = 1; + $res["allow_links"] = true; if ($config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === "yes") { - $res["enforce_links_password"] = 1; - } else { - $res["enforce_links_password"] = 0; - } + $res["enforce_links_password"] = true; + } if ($config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === "yes") { - $res["allow_public_upload"] = 1; - } else { - $res["allow_public_upload"] = 0; + $res["allow_public_upload"] = true; } - } else { - $res["allow_links"] = 0; - } + + $res = array("sharing" => $res); + } return new \OC_OCS_Result(array( 'capabilities' => array( - 'files' => array( - 'sharing' => $res - ), + 'files' => $res ), )); } From 4801d9c02a01999aea0d637d257e57b9b2f05bc4 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 27 Jan 2015 16:15:03 +0100 Subject: [PATCH 3/9] Use single quotes --- apps/files_sharing/lib/capabilities.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 25b0484b2e..f6228e3ec7 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -23,18 +23,18 @@ class Capabilities { $config = \OC::$server->getConfig(); $res = array(); - if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === "yes") { - $res["allow_links"] = true; + if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { + $res['allow_links'] = true; - if ($config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === "yes") { - $res["enforce_links_password"] = true; + if ($config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes') { + $res['enforce_links_password'] = true; } - if ($config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === "yes") { - $res["allow_public_upload"] = true; + if ($config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes') { + $res['allow_public_upload'] = true; } - $res = array("sharing" => $res); + $res = array('sharing' => $res); } return new \OC_OCS_Result(array( From 0452fde212e45645503c4bc1cd4a1c8d7f911ec5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 29 Jan 2015 09:17:58 +0100 Subject: [PATCH 4/9] Converted getCapabilities to non static function --- apps/files_sharing/lib/capabilities.php | 31 +++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index f6228e3ec7..6e14a60921 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -16,27 +16,44 @@ namespace OCA\Files_Sharing; */ class Capabilities { - /** - * @return \OC_OCS_Result + private $config; + + /* + * @codeCoverageIgnore + */ + public function __construct($config) { + $this->config = $config; + } + + /* + * @codeCoverageIgnore */ public static function getCapabilities() { $config = \OC::$server->getConfig(); + $cap = new Capabilities($config); + return $cap->getCaps(); + } + + /** + * @return \OC_OCS_Result + */ + public function getCaps() { $res = array(); - if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { $res['allow_links'] = true; - if ($config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes') { + if ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes') { $res['enforce_links_password'] = true; } - if ($config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes') { + if ($this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes') { $res['allow_public_upload'] = true; } $res = array('sharing' => $res); - } - + } + return new \OC_OCS_Result(array( 'capabilities' => array( 'files' => $res From 083ebca812ebeb48bfc4aca0e5ff9cd7a6861042 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 29 Jan 2015 09:18:33 +0100 Subject: [PATCH 5/9] Added unit test to test getCapabilities for files_sharing --- apps/files_sharing/tests/capabilities.php | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 apps/files_sharing/tests/capabilities.php diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php new file mode 100644 index 0000000000..aa5e58ba32 --- /dev/null +++ b/apps/files_sharing/tests/capabilities.php @@ -0,0 +1,113 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +use OCA\Files\Share; +use OCA\Files_sharing\Tests\TestCase; + +/** + * Class Test_Files_Sharing_Capabilties + */ +class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { + + /** + * Test for the general part in each return statement and assert + */ + function getFilesPart($data) { + $this->assertArrayHasKey('capabilities', $data); + $this->assertArrayHasKey('files', $data['capabilities']); + return $data['capabilities']['files']; + } + + /** + * Extract the sharing part and some asserts + */ + function getSharing($data) { + $this->assertCount(1, $data); + $this->assertArrayHasKey('sharing', $data); + return $data['sharing']; + } + + /** + * Create a mock config object and insert the values in $map tot the getAppValue + * function. Then obtain the capabilities and extract the first few + * levels in the array + */ + function getResults($map) { + $stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock(); + $stub->method('getAppValue')->will($this->returnValueMap($map)); + $cap = new \OCA\Files_Sharing\Capabilities($stub); + $result = $this->getFilesPart($cap->getCaps()->getData()); + return $result; + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testCapabilities() { + /* + * Test for no link sharing + */ + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'no') + ); + $result = $this->getResults($map); + $this->assertEmpty($result); + + /* + * Test only link sharing + */ + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'no'), + array('core', 'shareapi_allow_public_upload', 'yes', 'no') + ); + $result = $this->getSharing($this->getResults($map)); + $this->assertCount(1, $result); + $this->assertArrayHasKey('allow_links', $result); + + /* + * Test link sharing with enforced passwords + */ + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), + array('core', 'shareapi_allow_public_upload', 'yes', 'no') + ); + $result = $this->getSharing($this->getResults($map)); + $this->assertCount(2, $result); + $this->assertArrayHasKey('allow_links', $result); + $this->assertArrayHasKey('enforce_links_password', $result); + + /* + * Test link sharing with public upload + */ + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'no'), + array('core', 'shareapi_allow_public_upload', 'yes', 'yes') + ); + $result = $this->getSharing($this->getResults($map)); + $this->assertCount(2, $result); + $this->assertArrayHasKey('allow_links', $result); + $this->assertArrayHasKey('allow_public_upload', $result); + + /* + * Test link sharing with all options on + */ + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), + array('core', 'shareapi_allow_public_upload', 'yes', 'yes') + ); + $result = $this->getSharing($this->getResults($map)); + $this->assertCount(3, $result); + $this->assertArrayHasKey('allow_links', $result); + $this->assertArrayHasKey('enforce_links_password', $result); + $this->assertArrayHasKey('allow_public_upload', $result); + } +} From bcae79a85a5cc266c0874e8894b383309dd46388 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 4 Feb 2015 15:49:20 +0100 Subject: [PATCH 6/9] Split up unit tests --- apps/files_sharing/tests/capabilities.php | 40 ++++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index aa5e58ba32..daf022caea 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -1,18 +1,18 @@ + * Copyright (c) 2015 Roeland Jago Douma * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ -use OCA\Files\Share; +use OCA\Files\Share\Tests; use OCA\Files_sharing\Tests\TestCase; /** * Class Test_Files_Sharing_Capabilties */ -class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { +class Test_Files_Sharing_Capabilities extends \Test\TestCase { /** * Test for the general part in each return statement and assert @@ -48,19 +48,18 @@ class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { /** * @covers OCA\Files_Sharing\Capabilities::getCaps */ - public function testCapabilities() { - /* - * Test for no link sharing - */ + public function test_no_link_sharing() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'no') ); $result = $this->getResults($map); $this->assertEmpty($result); + } - /* - * Test only link sharing - */ + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_only_link_sharing() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), array('core', 'shareapi_enforce_links_password', 'yes', 'no'), @@ -69,10 +68,12 @@ class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { $result = $this->getSharing($this->getResults($map)); $this->assertCount(1, $result); $this->assertArrayHasKey('allow_links', $result); + } - /* - * Test link sharing with enforced passwords - */ + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_sharing_password() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), @@ -82,10 +83,12 @@ class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { $this->assertCount(2, $result); $this->assertArrayHasKey('allow_links', $result); $this->assertArrayHasKey('enforce_links_password', $result); + } - /* - * Test link sharing with public upload - */ + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_sharing_public_uploads() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), array('core', 'shareapi_enforce_links_password', 'yes', 'no'), @@ -95,7 +98,12 @@ class Test_Files_Sharing_Capabilities extends \PHPUnit_Framework_TestCase { $this->assertCount(2, $result); $this->assertArrayHasKey('allow_links', $result); $this->assertArrayHasKey('allow_public_upload', $result); + } + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_sharing_all() { /* * Test link sharing with all options on */ From d4e361db44e50787d5f660d5947aeeef82c38bf4 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 6 Feb 2015 10:33:08 +0100 Subject: [PATCH 7/9] Updated sharing capabilities Moved to files_sharing Added more capabilities. Tried to order to capabilities more OO style --- apps/files_sharing/lib/capabilities.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 6e14a60921..50db775e3e 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -40,23 +40,29 @@ class Capabilities { */ public function getCaps() { $res = array(); + + $public = array(); if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { - $res['allow_links'] = true; + $public['password_enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); - if ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes') { - $res['enforce_links_password'] = true; - } - - if ($this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes') { - $res['allow_public_upload'] = true; + $public['expire_date'] = array(); + if ($this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes') { + $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', false); + $public['expire_date']['enforce'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; } - $res = array('sharing' => $res); + $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'yes') === 'yes'; } + $res["public"] = $public; + + $res['user']['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'yes') === 'yes'; + + $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; + return new \OC_OCS_Result(array( 'capabilities' => array( - 'files' => $res + 'files_sharing' => $res ), )); } From 3be3e20c0f3f1f11fe08a3ce97aef0e7164908b9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 6 Feb 2015 10:53:58 +0100 Subject: [PATCH 8/9] Bit better formatting when using json output --- apps/files_sharing/lib/capabilities.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 50db775e3e..ff01770719 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -41,12 +41,14 @@ class Capabilities { public function getCaps() { $res = array(); - $public = array(); + $public = false;; if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { + $public = array(); $public['password_enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); - $public['expire_date'] = array(); + $public['expire_date'] = false; if ($this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes') { + $public['expire_date'] = array(); $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', false); $public['expire_date']['enforce'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; } From fe2aca5aa84a7ccc13a0d1e29a386a8392845707 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 6 Feb 2015 12:13:53 +0100 Subject: [PATCH 9/9] Updated unit tests --- apps/files_sharing/tests/capabilities.php | 166 ++++++++++++++++------ 1 file changed, 123 insertions(+), 43 deletions(-) diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index daf022caea..cafd5c4652 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -17,19 +17,10 @@ class Test_Files_Sharing_Capabilities extends \Test\TestCase { /** * Test for the general part in each return statement and assert */ - function getFilesPart($data) { + function getFilesSharingPart($data) { $this->assertArrayHasKey('capabilities', $data); - $this->assertArrayHasKey('files', $data['capabilities']); - return $data['capabilities']['files']; - } - - /** - * Extract the sharing part and some asserts - */ - function getSharing($data) { - $this->assertCount(1, $data); - $this->assertArrayHasKey('sharing', $data); - return $data['sharing']; + $this->assertArrayHasKey('files_sharing', $data['capabilities']); + return $data['capabilities']['files_sharing']; } /** @@ -41,7 +32,7 @@ class Test_Files_Sharing_Capabilities extends \Test\TestCase { $stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock(); $stub->method('getAppValue')->will($this->returnValueMap($map)); $cap = new \OCA\Files_Sharing\Capabilities($stub); - $result = $this->getFilesPart($cap->getCaps()->getData()); + $result = $this->getFilesSharingPart($cap->getCaps()->getData()); return $result; } @@ -50,10 +41,10 @@ class Test_Files_Sharing_Capabilities extends \Test\TestCase { */ public function test_no_link_sharing() { $map = array( - array('core', 'shareapi_allow_links', 'yes', 'no') + array('core', 'shareapi_allow_links', 'yes', 'no'), ); $result = $this->getResults($map); - $this->assertEmpty($result); + $this->assertFalse($result['public']); } /** @@ -62,60 +53,149 @@ class Test_Files_Sharing_Capabilities extends \Test\TestCase { public function test_only_link_sharing() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_enforce_links_password', 'yes', 'no'), - array('core', 'shareapi_allow_public_upload', 'yes', 'no') ); - $result = $this->getSharing($this->getResults($map)); - $this->assertCount(1, $result); - $this->assertArrayHasKey('allow_links', $result); + $result = $this->getResults($map); + $this->assertInternalType('array', $result['public']); } /** * @covers OCA\Files_Sharing\Capabilities::getCaps */ - public function test_link_sharing_password() { + public function test_link_password() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), - array('core', 'shareapi_allow_public_upload', 'yes', 'no') ); - $result = $this->getSharing($this->getResults($map)); - $this->assertCount(2, $result); - $this->assertArrayHasKey('allow_links', $result); - $this->assertArrayHasKey('enforce_links_password', $result); + $result = $this->getResults($map); + $this->assertArrayHasKey('password_enforced', $result['public']); + $this->assertTrue($result['public']['password_enforced']); } /** * @covers OCA\Files_Sharing\Capabilities::getCaps */ - public function test_link_sharing_public_uploads() { + public function test_link_no_password() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), array('core', 'shareapi_enforce_links_password', 'yes', 'no'), - array('core', 'shareapi_allow_public_upload', 'yes', 'yes') ); - $result = $this->getSharing($this->getResults($map)); - $this->assertCount(2, $result); - $this->assertArrayHasKey('allow_links', $result); - $this->assertArrayHasKey('allow_public_upload', $result); + $result = $this->getResults($map); + $this->assertArrayHasKey('password_enforced', $result['public']); + $this->assertFalse($result['public']['password_enforced']); } /** * @covers OCA\Files_Sharing\Capabilities::getCaps */ - public function test_link_sharing_all() { - /* - * Test link sharing with all options on - */ + public function test_link_no_expire_date() { $map = array( array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), - array('core', 'shareapi_allow_public_upload', 'yes', 'yes') + array('core', 'shareapi_default_expire_date', 'yes', 'no'), ); - $result = $this->getSharing($this->getResults($map)); - $this->assertCount(3, $result); - $this->assertArrayHasKey('allow_links', $result); - $this->assertArrayHasKey('enforce_links_password', $result); - $this->assertArrayHasKey('allow_public_upload', $result); + $result = $this->getResults($map); + $this->assertArrayHasKey('expire_date', $result['public']); + $this->assertFalse($result['public']['expire_date']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_expire_date() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_default_expire_date', 'yes', 'yes'), + array('core', 'shareapi_expire_after_n_days', false, 0), + array('core', 'shareapi_enforce_expire_date', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertArrayHasKey('expire_date', $result['public']); + $this->assertInternalType('array', $result['public']['expire_date']); + $this->assertInternalType('int', $result['public']['expire_date']['days']); + $this->assertFalse($result['public']['expire_date']['enforce']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_expire_date_enforced() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_default_expire_date', 'yes', 'yes'), + array('core', 'shareapi_expire_after_n_days', false, 0), + array('core', 'shareapi_enforce_expire_date', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertArrayHasKey('expire_date', $result['public']); + $this->assertInternalType('array', $result['public']['expire_date']); + $this->assertInternalType('int', $result['public']['expire_date']['days']); + $this->assertTrue($result['public']['expire_date']['enforce']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_send_mail() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_allow_public_notification', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertTrue($result['public']['send_mail']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_link_no_send_mail() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_allow_public_notification', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertFalse($result['public']['send_mail']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_user_send_mail() { + $map = array( + array('core', 'shareapi_allow_mail_notification', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertTrue($result['user']['send_mail']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_user_no_send_mail() { + $map = array( + array('core', 'shareapi_allow_mail_notification', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertFalse($result['user']['send_mail']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_resharing() { + $map = array( + array('core', 'shareapi_allow_resharing', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertTrue($result['resharing']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function test_no_resharing() { + $map = array( + array('core', 'shareapi_allow_resharing', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertFalse($result['resharing']); } }