123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- /**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
- namespace OCA\Files_Sharing\Tests;
- use OCA\Files_Sharing\Capabilities;
- use OCP\IConfig;
- /**
- * Class CapabilitiesTest
- *
- * @group DB
- */
- class CapabilitiesTest 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[]
- */
- private function getFilesSharingPart(array $data) {
- $this->assertArrayHasKey('files_sharing', $data);
- return $data['files_sharing'];
- }
- /**
- * Create a mock config object and insert the values in $map to 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[]
- */
- private function getResults(array $map) {
- $config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock();
- $config->method('getAppValue')->will($this->returnValueMap($map));
- $cap = new Capabilities($config);
- $result = $this->getFilesSharingPart($cap->getCapabilities());
- return $result;
- }
- public function testEnabledSharingAPI() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertTrue($result['api_enabled']);
- $this->assertContains('public', $result);
- $this->assertContains('user', $result);
- $this->assertContains('resharing', $result);
- }
- public function testDisabledSharingAPI() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertFalse($result['api_enabled']);
- $this->assertNotContains('public', $result);
- $this->assertNotContains('user', $result);
- $this->assertNotContains('resharing', $result);
- }
- public function testNoLinkSharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertInternalType('array', $result['public']);
- $this->assertFalse($result['public']['enabled']);
- }
- public function testOnlyLinkSharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertInternalType('array', $result['public']);
- $this->assertTrue($result['public']['enabled']);
- }
- public function testLinkPassword() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_enforce_links_password', 'no', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('password', $result['public']);
- $this->assertArrayHasKey('enforced', $result['public']['password']);
- $this->assertTrue($result['public']['password']['enforced']);
- }
- public function testLinkNoPassword() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_enforce_links_password', 'no', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('password', $result['public']);
- $this->assertArrayHasKey('enforced', $result['public']['password']);
- $this->assertFalse($result['public']['password']['enforced']);
- }
- public function testLinkNoExpireDate() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_default_expire_date', 'no', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('expire_date', $result['public']);
- $this->assertInternalType('array', $result['public']['expire_date']);
- $this->assertFalse($result['public']['expire_date']['enabled']);
- }
- public function testLinkExpireDate() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_default_expire_date', 'no', 'yes'],
- ['core', 'shareapi_expire_after_n_days', '7', '7'],
- ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
- ];
- $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']['enforced']);
- }
- public function testLinkExpireDateEnforced() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_default_expire_date', 'no', 'yes'],
- ['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('expire_date', $result['public']);
- $this->assertInternalType('array', $result['public']['expire_date']);
- $this->assertTrue($result['public']['expire_date']['enforced']);
- }
- public function testLinkSendMail() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_allow_public_notification', 'no', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertTrue($result['public']['send_mail']);
- }
- public function testLinkNoSendMail() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_allow_public_notification', 'no', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertFalse($result['public']['send_mail']);
- }
- public function testResharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertTrue($result['resharing']);
- }
- public function testNoResharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_resharing', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertFalse($result['resharing']);
- }
- public function testLinkPublicUpload() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertTrue($result['public']['upload']);
- $this->assertTrue($result['public']['upload_files_drop']);
- }
- public function testLinkNoPublicUpload() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_links', 'yes', 'yes'],
- ['core', 'shareapi_allow_public_upload', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertFalse($result['public']['upload']);
- $this->assertFalse($result['public']['upload_files_drop']);
- }
- public function testNoGroupSharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertFalse($result['group_sharing']);
- }
- public function testGroupSharing() {
- $map = [
- ['core', 'shareapi_enabled', 'yes', 'yes'],
- ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertTrue($result['group_sharing']);
- }
- public function testFederatedSharingIncomming() {
- $map = [
- ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('federation', $result);
- $this->assertTrue($result['federation']['incoming']);
- }
- public function testFederatedSharingNoIncomming() {
- $map = [
- ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('federation', $result);
- $this->assertFalse($result['federation']['incoming']);
- }
- public function testFederatedSharingOutgoing() {
- $map = [
- ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'yes'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('federation', $result);
- $this->assertTrue($result['federation']['outgoing']);
- }
- public function testFederatedSharingNoOutgoing() {
- $map = [
- ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
- ];
- $result = $this->getResults($map);
- $this->assertArrayHasKey('federation', $result);
- $this->assertFalse($result['federation']['outgoing']);
- }
- }
|