From 39b0f0725ec4a253c07e14d7b734b0260bcb0735 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 7 Feb 2015 08:07:53 +0100 Subject: [PATCH 1/7] Add file_sharing info to capabilities Display the capabilities regarding file sharing in the capabilities API. This will allow the clients to provide users a better experince. --- apps/files_sharing/lib/capabilities.php | 74 ++++++++ apps/files_sharing/tests/capabilities.php | 208 ++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 apps/files_sharing/lib/capabilities.php create mode 100644 apps/files_sharing/tests/capabilities.php diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php new file mode 100644 index 00000000000..95ee810bc9f --- /dev/null +++ b/apps/files_sharing/lib/capabilities.php @@ -0,0 +1,74 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing; + +use \OCP\IConfig; + +/** + * Class Capabilities + * + * @package OCA\Files_Sharing + */ +class Capabilities { + + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return \OC_OCS_Result + */ + public static function getCapabilities() { + $config = \OC::$server->getConfig(); + $cap = new Capabilities($config); + return $cap->getCaps(); + } + + + /** + * @return \OC_OCS_Result + */ + public function getCaps() { + $res = 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'] = 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', '7'); + $public['expire_date']['enforce'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; + } + + $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_sharing' => $res + ), + )); + } + +} diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php new file mode 100644 index 00000000000..1b63030501b --- /dev/null +++ b/apps/files_sharing/tests/capabilities.php @@ -0,0 +1,208 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\Tests; + +use OCA\Files_Sharing\Capabilities; +use OCA\Files_Sharing\Tests\TestCase; + +/** + * Class FilesSharingCapabilitiesTest + */ +class FilesSharingCapabilitiesTest extends \Test\TestCase { + + /** + * Test for the general part in each return statement and assert. + * Strip of the general part on the way. + * + * @param string[] $data Capabilities + * @return string[] + */ + function getFilesSharingPart(array $data) { + $this->assertArrayHasKey('capabilities', $data); + $this->assertArrayHasKey('files_sharing', $data['capabilities']); + return $data['capabilities']['files_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 + * + * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock + * @return string[] + */ + function getResults(array $map) { + $stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock(); + $stub->method('getAppValue')->will($this->returnValueMap($map)); + $cap = new Capabilities($stub); + $result = $this->getFilesSharingPart($cap->getCaps()->getData()); + return $result; + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testNoLinkSharing() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertFalse($result['public']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testOnlyLinkSharing() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertInternalType('array', $result['public']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkPassword() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), + ); + $result = $this->getResults($map); + $this->assertArrayHasKey('password_enforced', $result['public']); + $this->assertTrue($result['public']['password_enforced']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkNoPassword() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_enforce_links_password', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertArrayHasKey('password_enforced', $result['public']); + $this->assertFalse($result['public']['password_enforced']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkNoExpireDate() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_default_expire_date', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertArrayHasKey('expire_date', $result['public']); + $this->assertFalse($result['public']['expire_date']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkExpireDate() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_default_expire_date', 'yes', 'yes'), + array('core', 'shareapi_expire_after_n_days', '7', '7'), + 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->assertArrayHasKey('days', $result['public']['expire_date']); + $this->assertFalse($result['public']['expire_date']['enforce']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkExpireDateEnforced() { + $map = array( + array('core', 'shareapi_allow_links', 'yes', 'yes'), + array('core', 'shareapi_default_expire_date', 'yes', 'yes'), + 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->assertTrue($result['public']['expire_date']['enforce']); + } + + /** + * @covers OCA\Files_Sharing\Capabilities::getCaps + */ + public function testLinkSendMail() { + $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 testLinkNoSendMail() { + $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 testUserSendMail() { + $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 testUserNoSendMail() { + $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 testResharing() { + $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 testNoResharing() { + $map = array( + array('core', 'shareapi_allow_resharing', 'yes', 'no'), + ); + $result = $this->getResults($map); + $this->assertFalse($result['resharing']); + } +} From 0bf1152a512d72a390da3b6ae9432066db4df1fa Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 9 Feb 2015 14:23:18 +0100 Subject: [PATCH 2/7] Added route again --- apps/files_sharing/appinfo/routes.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index dd9509575b7..307b4acfcd1 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -56,3 +56,9 @@ $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); From af76716775f0f16755fa3369b6336feded291f70 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 9 Feb 2015 14:26:49 +0100 Subject: [PATCH 3/7] Now added enabled element This change allows for more generic parsing for the capabilities. --- apps/files_sharing/lib/capabilities.php | 14 +++++++------- apps/files_sharing/tests/capabilities.php | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 95ee810bc9f..21822b18503 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -5,7 +5,7 @@ * later. * See the COPYING-README file. */ - + namespace OCA\Files_Sharing; use \OCP\IConfig; @@ -43,14 +43,14 @@ class Capabilities { public function getCaps() { $res = array(); - $public = false; - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { - $public = array(); + $public = array(); + $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; + if ($public['enabled']) { $public['password_enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); - $public['expire_date'] = false; - if ($this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes') { - $public['expire_date'] = array(); + $public['expire_date'] = array(); + $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes'; + if ($public['expire_date']['enabled']) { $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); $public['expire_date']['enforce'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; } diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index 1b63030501b..a9980c63fea 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -53,7 +53,8 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { array('core', 'shareapi_allow_links', 'yes', 'no'), ); $result = $this->getResults($map); - $this->assertFalse($result['public']); + $this->assertInternalType('array', $result['public']); + $this->assertFalse($result['public']['enabled']); } /** @@ -65,6 +66,7 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { ); $result = $this->getResults($map); $this->assertInternalType('array', $result['public']); + $this->assertTrue($result['public']['enabled']); } /** @@ -103,7 +105,8 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { ); $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); - $this->assertFalse($result['public']['expire_date']); + $this->assertInternalType('array', $result['public']['expire_date']); + $this->assertFalse($result['public']['expire_date']['enabled']); } /** @@ -119,6 +122,7 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); $this->assertInternalType('array', $result['public']['expire_date']); + $this->assertTrue($result['public']['expire_date']['enabled']); $this->assertArrayHasKey('days', $result['public']['expire_date']); $this->assertFalse($result['public']['expire_date']['enforce']); } From c98518624620beb7159b4d50d6e0228c9c0d678b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 26 Feb 2015 08:35:41 +0100 Subject: [PATCH 4/7] Added new header --- apps/files_sharing/lib/capabilities.php | 22 ++++++++++++++++----- apps/files_sharing/tests/capabilities.php | 24 +++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 21822b18503..37ce9084137 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -1,11 +1,23 @@ - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * @author Roeland Jago Douma + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * */ - namespace OCA\Files_Sharing; use \OCP\IConfig; diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index a9980c63fea..64d198e070b 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -1,11 +1,23 @@ - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - + * @author Roeland Jago Douma + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ namespace OCA\Files_Sharing\Tests; use OCA\Files_Sharing\Capabilities; From 09ee297356d80c4c20897860b2ef05b81bd2ad44 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 26 Feb 2015 08:39:55 +0100 Subject: [PATCH 5/7] New array syntax --- apps/files_sharing/lib/capabilities.php | 14 ++-- apps/files_sharing/tests/capabilities.php | 98 +++++++++++------------ 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 37ce9084137..896378eacae 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -53,14 +53,14 @@ class Capabilities { * @return \OC_OCS_Result */ public function getCaps() { - $res = array(); + $res = []; - $public = array(); + $public = []; $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; if ($public['enabled']) { $public['password_enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); - $public['expire_date'] = array(); + $public['expire_date'] = []; $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes'; if ($public['expire_date']['enabled']) { $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); @@ -76,11 +76,11 @@ class Capabilities { $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; - return new \OC_OCS_Result(array( - 'capabilities' => array( + return new \OC_OCS_Result([ + 'capabilities' => [ 'files_sharing' => $res - ), - )); + ], + ]); } } diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index 64d198e070b..2d7a0fe0222 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -61,9 +61,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testNoLinkSharing() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertInternalType('array', $result['public']); $this->assertFalse($result['public']['enabled']); @@ -73,9 +73,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testOnlyLinkSharing() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertInternalType('array', $result['public']); $this->assertTrue($result['public']['enabled']); @@ -85,10 +85,10 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkPassword() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_enforce_links_password', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enforce_links_password', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertArrayHasKey('password_enforced', $result['public']); $this->assertTrue($result['public']['password_enforced']); @@ -98,10 +98,10 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkNoPassword() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_enforce_links_password', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_enforce_links_password', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertArrayHasKey('password_enforced', $result['public']); $this->assertFalse($result['public']['password_enforced']); @@ -111,10 +111,10 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkNoExpireDate() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_default_expire_date', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_default_expire_date', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); $this->assertInternalType('array', $result['public']['expire_date']); @@ -125,12 +125,12 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkExpireDate() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_default_expire_date', 'yes', 'yes'), - array('core', 'shareapi_expire_after_n_days', '7', '7'), - array('core', 'shareapi_enforce_expire_date', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_default_expire_date', 'yes', 'yes'], + ['core', 'shareapi_expire_after_n_days', '7', '7'], + ['core', 'shareapi_enforce_expire_date', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); $this->assertInternalType('array', $result['public']['expire_date']); @@ -143,11 +143,11 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkExpireDateEnforced() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_default_expire_date', 'yes', 'yes'), - array('core', 'shareapi_enforce_expire_date', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_default_expire_date', 'yes', 'yes'], + ['core', 'shareapi_enforce_expire_date', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); $this->assertInternalType('array', $result['public']['expire_date']); @@ -158,10 +158,10 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkSendMail() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_allow_public_notification', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_allow_public_notification', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertTrue($result['public']['send_mail']); } @@ -170,10 +170,10 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testLinkNoSendMail() { - $map = array( - array('core', 'shareapi_allow_links', 'yes', 'yes'), - array('core', 'shareapi_allow_public_notification', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_allow_public_notification', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertFalse($result['public']['send_mail']); } @@ -182,9 +182,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testUserSendMail() { - $map = array( - array('core', 'shareapi_allow_mail_notification', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_mail_notification', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertTrue($result['user']['send_mail']); } @@ -193,9 +193,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testUserNoSendMail() { - $map = array( - array('core', 'shareapi_allow_mail_notification', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_mail_notification', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertFalse($result['user']['send_mail']); } @@ -204,9 +204,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testResharing() { - $map = array( - array('core', 'shareapi_allow_resharing', 'yes', 'yes'), - ); + $map = [ + ['core', 'shareapi_allow_resharing', 'yes', 'yes'], + ]; $result = $this->getResults($map); $this->assertTrue($result['resharing']); } @@ -215,9 +215,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @covers OCA\Files_Sharing\Capabilities::getCaps */ public function testNoResharing() { - $map = array( - array('core', 'shareapi_allow_resharing', 'yes', 'no'), - ); + $map = [ + ['core', 'shareapi_allow_resharing', 'yes', 'no'], + ]; $result = $this->getResults($map); $this->assertFalse($result['resharing']); } From e9a003fe211f1ba800aeed4efa85827baaca24a0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 11 Mar 2015 15:11:50 +0100 Subject: [PATCH 6/7] Slight better formatting --- apps/files_sharing/lib/capabilities.php | 5 ++- apps/files_sharing/tests/capabilities.php | 53 ++++------------------- 2 files changed, 11 insertions(+), 47 deletions(-) diff --git a/apps/files_sharing/lib/capabilities.php b/apps/files_sharing/lib/capabilities.php index 896378eacae..ac6454c3433 100644 --- a/apps/files_sharing/lib/capabilities.php +++ b/apps/files_sharing/lib/capabilities.php @@ -58,13 +58,14 @@ class Capabilities { $public = []; $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; if ($public['enabled']) { - $public['password_enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); + $public['password'] = []; + $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'yes') === 'yes'); $public['expire_date'] = []; $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'yes') === 'yes'; if ($public['expire_date']['enabled']) { $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); - $public['expire_date']['enforce'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; + $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'yes') === 'yes'; } $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'yes') === 'yes'; diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index 2d7a0fe0222..91173985f5c 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -57,9 +57,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { return $result; } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testNoLinkSharing() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'no'], @@ -69,9 +66,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertFalse($result['public']['enabled']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testOnlyLinkSharing() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -81,35 +75,28 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertTrue($result['public']['enabled']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkPassword() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], ['core', 'shareapi_enforce_links_password', 'yes', 'yes'], ]; $result = $this->getResults($map); - $this->assertArrayHasKey('password_enforced', $result['public']); - $this->assertTrue($result['public']['password_enforced']); + $this->assertArrayHasKey('password', $result['public']); + $this->assertArrayHasKey('enforced', $result['public']['password']); + $this->assertTrue($result['public']['password']['enforced']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkNoPassword() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], ['core', 'shareapi_enforce_links_password', 'yes', 'no'], ]; $result = $this->getResults($map); - $this->assertArrayHasKey('password_enforced', $result['public']); - $this->assertFalse($result['public']['password_enforced']); + $this->assertArrayHasKey('password', $result['public']); + $this->assertArrayHasKey('enforced', $result['public']['password']); + $this->assertFalse($result['public']['password']['enforced']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkNoExpireDate() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -121,9 +108,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertFalse($result['public']['expire_date']['enabled']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkExpireDate() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -136,12 +120,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertInternalType('array', $result['public']['expire_date']); $this->assertTrue($result['public']['expire_date']['enabled']); $this->assertArrayHasKey('days', $result['public']['expire_date']); - $this->assertFalse($result['public']['expire_date']['enforce']); + $this->assertFalse($result['public']['expire_date']['enforced']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkExpireDateEnforced() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -151,12 +132,9 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $result = $this->getResults($map); $this->assertArrayHasKey('expire_date', $result['public']); $this->assertInternalType('array', $result['public']['expire_date']); - $this->assertTrue($result['public']['expire_date']['enforce']); + $this->assertTrue($result['public']['expire_date']['enforced']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkSendMail() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -166,9 +144,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertTrue($result['public']['send_mail']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testLinkNoSendMail() { $map = [ ['core', 'shareapi_allow_links', 'yes', 'yes'], @@ -178,9 +153,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertFalse($result['public']['send_mail']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testUserSendMail() { $map = [ ['core', 'shareapi_allow_mail_notification', 'yes', 'yes'], @@ -189,9 +161,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertTrue($result['user']['send_mail']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testUserNoSendMail() { $map = [ ['core', 'shareapi_allow_mail_notification', 'yes', 'no'], @@ -200,9 +169,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertFalse($result['user']['send_mail']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testResharing() { $map = [ ['core', 'shareapi_allow_resharing', 'yes', 'yes'], @@ -211,9 +177,6 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { $this->assertTrue($result['resharing']); } - /** - * @covers OCA\Files_Sharing\Capabilities::getCaps - */ public function testNoResharing() { $map = [ ['core', 'shareapi_allow_resharing', 'yes', 'no'], From ec31ee911779aeba9c81a95ceb5891bd93b97dd5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 11 Mar 2015 16:30:54 +0100 Subject: [PATCH 7/7] Mark functions private --- apps/files_sharing/tests/capabilities.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/tests/capabilities.php b/apps/files_sharing/tests/capabilities.php index 91173985f5c..a7c487bf589 100644 --- a/apps/files_sharing/tests/capabilities.php +++ b/apps/files_sharing/tests/capabilities.php @@ -35,7 +35,7 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @param string[] $data Capabilities * @return string[] */ - function getFilesSharingPart(array $data) { + private function getFilesSharingPart(array $data) { $this->assertArrayHasKey('capabilities', $data); $this->assertArrayHasKey('files_sharing', $data['capabilities']); return $data['capabilities']['files_sharing']; @@ -49,7 +49,7 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase { * @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock * @return string[] */ - function getResults(array $map) { + private function getResults(array $map) { $stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock(); $stub->method('getAppValue')->will($this->returnValueMap($map)); $cap = new Capabilities($stub);