diff options
author | zotlabs <mike@macgirvin.com> | 2016-10-20 16:14:01 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2016-10-20 16:14:01 -0700 |
commit | 8a34f7ca7b446be390153d805965bf4cd0501b3d (patch) | |
tree | df551849a823dbaf10741fc6c2af344217e2fedb | |
parent | e2e3b81f323957495a643a9087b663df03dac2d9 (diff) | |
parent | edde78521959ee544f5e77b134e3e6dd4f75bf02 (diff) | |
download | volse-hubzilla-8a34f7ca7b446be390153d805965bf4cd0501b3d.tar.gz volse-hubzilla-8a34f7ca7b446be390153d805965bf4cd0501b3d.tar.bz2 volse-hubzilla-8a34f7ca7b446be390153d805965bf4cd0501b3d.zip |
Merge branch 'dev' into pdo
-rw-r--r-- | .travis.yml | 12 | ||||
-rw-r--r-- | Zotlabs/Lib/PermissionDescription.php | 54 | ||||
-rw-r--r-- | include/conversation.php | 6 | ||||
-rw-r--r-- | tests/unit/Lib/PermissionDescriptionTest.php | 110 |
4 files changed, 146 insertions, 36 deletions
diff --git a/.travis.yml b/.travis.yml index 583b2a1a8..2830d1b9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,6 @@ language: php php: # using major version aliases - # aliased to a recent 5.4.x version - - 5.4 - # aliased to a recent 5.5.x version - - 5.5 # aliased to a recent 5.6.x version - 5.6 # aliased to a recent 7.x version @@ -27,7 +23,6 @@ matrix: # - php: hhvm # env: DB=pgsql # PDO driver for pgsql is unsupported by HHVM (3rd party install for support) allow_failures: - - php: 7.0 - php: hhvm # execute any number of scripts before the test run, custom env's are available as variables @@ -36,11 +31,14 @@ matrix: # - if [[ "$DB" == "pgsql" ]]; then psql -c "create database hello_world_test;" -U postgres; fi # - if [[ "$DB" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS hello_world_test;" -uroot; fi +install: + - composer require phpunit/phpunit + # omitting "script:" will default to phpunit # use the $DB env variable to determine the phpunit.xml to use -script: phpunit tests/*php +script: vendor/bin/phpunit tests/unit/ # configure notifications (email, IRC, campfire etc) notifications: # irc: "irc.freenode.org#yourfavouriteroomfortravis" -# a plugin/script to post to a hubzilla channel would be neat here
\ No newline at end of file +# a plugin/script to post to a hubzilla channel would be neat here diff --git a/Zotlabs/Lib/PermissionDescription.php b/Zotlabs/Lib/PermissionDescription.php index b6c6dd29d..51d5f890d 100644 --- a/Zotlabs/Lib/PermissionDescription.php +++ b/Zotlabs/Lib/PermissionDescription.php @@ -12,22 +12,25 @@ require_once("include/text.php"); * permission settings for an item with an empty ACL. * i.e the caption, icon, and tooltip for the no-ACL option in the ACL dialog. */ -class PermissionDescription { +class PermissionDescription { private $global_perm; private $channel_perm; private $fallback_description; - + /** * Constructor is private. - * Use static methods fromGlobalPermission(), fromStandalonePermission(), or fromDescription() - * to create instances. + * Use static methods fromGlobalPermission(), fromStandalonePermission(), + * or fromDescription() to create instances. + * + * @internal + * @param int $global_perm + * @param int $channel_perm + * @param string $description (optional) default empty */ private function __construct($global_perm, $channel_perm, $description = '') { - $this->global_perm = $global_perm; $this->channel_perm = $channel_perm; - $this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description; } @@ -43,23 +46,22 @@ class PermissionDescription { return new PermissionDescription('', 0x80000, $description); } - /** * Use this method only if the interpretation of an empty ACL doesn't fall back to a global * default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC, * PERMS_NETWORK etc. - * + * * @param integer $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc. * @return a new instance of PermissionDescription */ public static function fromStandalonePermission($perm) { $result = new PermissionDescription('', $perm); - - $checkPerm = $this->get_permission_description(); - if ($checkPerm == $this->fallback_description) { + + $checkPerm = $result->get_permission_description(); + if($checkPerm == $result->fallback_description) { $result = null; - logger('null PermissionDescription from unknown standalone permission: ' . $perm ,LOGGER_DEBUG, LOG_ERROR); + logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR); } return $result; @@ -67,9 +69,9 @@ class PermissionDescription { /** * This is the preferred way to create a PermissionDescription, as it provides the most details. - * Use this method if you know an empty ACL will result in one of the global default permissions + * Use this method if you know an empty ACL will result in one of the global default permissions * being used, such as channel_r_stream (for which you would pass 'view_stream'). - * + * * @param string $permname - a key for the global perms array from get_perms() in permissions.php, * e.g. 'view_stream', 'view_profile', etc. * @return a new instance of PermissionDescription @@ -80,19 +82,19 @@ class PermissionDescription { $global_perms = \Zotlabs\Access\Permissions::Perms(); - if (array_key_exists($permname, $global_perms)) { + if(array_key_exists($permname, $global_perms)) { - $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'],$permname); + $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'], $permname); $result = new PermissionDescription('', $channelPerm); } else { // The acl dialog can handle null arguments, but it shouldn't happen - logger('null PermissionDescription from unknown global permission: ' . $permname ,LOGGER_DEBUG, LOG_ERROR); + logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR); } + return $result; } - /** * Gets a localized description of the permission, or a generic message if the permission * is unknown. @@ -101,8 +103,7 @@ class PermissionDescription { */ public function get_permission_description() { - switch($this->channel_perm) { - + switch($this->channel_perm) { case 0: return t('Only me'); case PERMS_PUBLIC: return t('Public'); case PERMS_NETWORK: return t('Anybody in the $Projectname network'); @@ -117,19 +118,18 @@ class PermissionDescription { /** * Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public, - * otherwise returns empty string. + * otherwise returns empty string. * * @return string icon css class name (often FontAwesome) */ public function get_permission_icon() { - switch($this->channel_perm) { - + switch($this->channel_perm) { case 0:/* only me */ return 'fa-eye-slash'; case PERMS_PUBLIC: return 'fa-globe'; case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use - case PERMS_SITE: return 'fa-sitemap'; - case PERMS_CONTACTS: return 'fa-group'; + case PERMS_SITE: return 'fa-sitemap'; + case PERMS_CONTACTS: return 'fa-group'; case PERMS_SPECIFIC: return 'fa-list'; case PERMS_AUTHED: return ''; case PERMS_PENDING: return ''; @@ -137,7 +137,6 @@ class PermissionDescription { } } - /** * Returns a localized description of where the permission came from, if this is known. * If it's not know, or if the permission is standalone and didn't come from a default @@ -147,8 +146,7 @@ class PermissionDescription { */ public function get_permission_origin_description() { - switch($this->global_perm) { - + switch($this->global_perm) { case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.'); case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile'); case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections'); diff --git a/include/conversation.php b/include/conversation.php index bc8f8ce8b..43533e3c1 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1536,7 +1536,11 @@ function network_tabs() { // tabs $tabs = array(); - if(! get_config('system','disable_discover_tab')) { + $d = get_config('system','disable_discover_tab'); + if($d === false) + $d = 1; + + if(! $d) { $tabs[] = array( 'label' => t('Discover'), 'url' => z_root() . '/' . $cmd . '?f=&fh=1' , diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php new file mode 100644 index 000000000..b1da5a0fd --- /dev/null +++ b/tests/unit/Lib/PermissionDescriptionTest.php @@ -0,0 +1,110 @@ +<?php +/* + * Copyright (c) 2016 Hubzilla + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// Global namespace for fully qualified \App class. +namespace { + // General channel permissions in boot.php + // 0 = Only you + define ( 'PERMS_PUBLIC' , 0x0001 ); // anybody + define ( 'PERMS_NETWORK' , 0x0002 ); // anybody in this network + define ( 'PERMS_SITE' , 0x0004 ); // anybody on this site + define ( 'PERMS_CONTACTS' , 0x0008 ); // any of my connections + define ( 'PERMS_SPECIFIC' , 0x0080 ); // only specific connections + define ( 'PERMS_AUTHED' , 0x0100 ); // anybody authenticated (could include visitors from other networks) + define ( 'PERMS_PENDING' , 0x0200 ); // any connections including those who haven't yet been approved + // log levels in boot.php + define ( 'LOGGER_DEBUG', 2 ); + + // Stub global fully qualified \App class for static function calls + class App { + // Stub get_hostname() + public static function get_hostname() { + return 'phpunit'; + } + } +} + +// Stub global functions used in PermissionDescription with the help of +// PHP's namespace resolution rules. +namespace Zotlabs\Lib { + // Stub global translate function t() + function t($s) { + return $s; + } + // Stub global log function logger() + function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { + // doesn't matter + } +} + +// regular namespace for this unit test +namespace Zotlabs\Tests\Unit\Lib { + + use Zotlabs\Tests\Unit\UnitTestCase; + use Zotlabs\Lib\PermissionDescription; + + /** + * @brief Unit Test case for ConnectionPool class. + */ + class PermissionDescriptionTest extends UnitTestCase { + + public function testFromDescription() { + $permDesc = PermissionDescription::fromDescription('test'); + $permDesc2 = PermissionDescription::fromDescription('test'); + $permDesc3 = PermissionDescription::fromDescription('test2'); + + $this->assertEquals($permDesc, $permDesc2); + $this->assertNotEquals($permDesc, $permDesc3); + } + + public function testFromStandalonePermission() { + $permDescUnknown = PermissionDescription::fromStandalonePermission(-1); + $permDescSelf = PermissionDescription::fromStandalonePermission(0); + + $this->assertNull($permDescUnknown); + $this->assertNotNull($permDescSelf); + } + + public function testFromGlobalPermission() { + //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); + + $this->markTestIncomplete( + 'For this test we need more stubs...' + ); + } + + public function testGetPermissionDescription() { + + // fromStandalonePermission uses get_permission_description(), so that will not help + //$permDescSelf = PermissionDescription::fromStandalonePermission(0); + //$permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC); + + $this->markTestIncomplete( + 'For this test we need a mock of PermissionDescription...' + ); + //$permDescSelf = + //$this->assertEquals($permDescSelf->, 'Only me'); + //$this->assertEquals($permDescPublic, 'Public'); + } + } +} |