From e3d30763dabdf12f961ed3d1d7cf4eaee44c65a9 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 6 Jan 2024 16:34:38 +0000 Subject: tests: Integrate the DB in "unit" tests. --- tests/unit/Lib/PermissionDescriptionTest.php | 47 ++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'tests/unit/Lib/PermissionDescriptionTest.php') diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php index 96c381d0c..fdd676f61 100644 --- a/tests/unit/Lib/PermissionDescriptionTest.php +++ b/tests/unit/Lib/PermissionDescriptionTest.php @@ -63,11 +63,52 @@ class PermissionDescriptionTest extends UnitTestCase { $this->assertNotNull($permDescSelf); } + /** + * Test fetching permission descriptions for the current channel. + */ public function testFromGlobalPermission() { - //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); + // Initiate the global App with a channel_id + \App::$channel = array( + 'channel_id' => 42, + ); + + // Make sure the requested permission is set for this channel. + \Zotlabs\Access\PermissionLimits::Set( + \App::$channel['channel_id'], + 'view_profile', + PERMS_NETWORK + ); + + \Zotlabs\Access\PermissionLimits::Set( + \App::$channel['channel_id'], + 'write_storage', + PERMS_SPECIFIC + ); + + // Set an invalid(?) permission + \Zotlabs\Access\PermissionLimits::Set( + \App::$channel['channel_id'], + 'view_wiki', + 1337 + ); + + $permDesc = PermissionDescription::fromGlobalPermission('view_profile'); + $this->assertEquals( + 'Anybody in the Hubzilla network', + $permDesc->get_permission_description() + ); + + $permDesc = PermissionDescription::fromGlobalPermission('write_storage'); + $this->assertEquals( + 'Only connections I specifically allow', + $permDesc->get_permission_description() + ); - $this->markTestIncomplete( - 'The method fromGlobalPermission() is not yet testable ...' + // Permissions we don't know about will get the fallback description. + $permDesc = PermissionDescription::fromGlobalPermission('view_wiki'); + $this->assertEquals( + 'Visible to your default audience', + $permDesc->get_permission_description() ); } -- cgit v1.2.3