From 21cd4a1b4845858c3421dbd5f2673eceee421f5d Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Nov 2020 08:43:03 +0000 Subject: psr-4 autoloading standard --- Tests/Unit/Lib/PermissionDescriptionTest.php | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Tests/Unit/Lib/PermissionDescriptionTest.php (limited to 'Tests/Unit/Lib/PermissionDescriptionTest.php') diff --git a/Tests/Unit/Lib/PermissionDescriptionTest.php b/Tests/Unit/Lib/PermissionDescriptionTest.php new file mode 100644 index 000000000..96c381d0c --- /dev/null +++ b/Tests/Unit/Lib/PermissionDescriptionTest.php @@ -0,0 +1,97 @@ +assertEquals($permDesc, $permDesc2); + $this->assertNotEquals($permDesc, $permDesc3); + } + + public function testFromStandalonePermission() { + // Create a stub for global function t() + $t = $this->getFunctionMock('Zotlabs\Lib', 't'); + $t->expects($this->atLeastOnce())->willReturnCallback( + function ($string) { + return $string; + } + ); + // Create a mock for global function logger() + $this->getFunctionMock('Zotlabs\Lib', 'logger'); + + $permDescUnknown = PermissionDescription::fromStandalonePermission(-1); + $permDescSelf = PermissionDescription::fromStandalonePermission(0); + + $this->assertNull($permDescUnknown); + $this->assertNotNull($permDescSelf); + } + + public function testFromGlobalPermission() { + //$permDesc = PermissionDescription::fromGlobalPermission('view_profile'); + + $this->markTestIncomplete( + 'The method fromGlobalPermission() is not yet testable ...' + ); + } + + public function testGetPermissionDescription() { + // Create a stub for global function t() + $t = $this->getFunctionMock('Zotlabs\Lib', 't'); + $t->expects($this->atLeastOnce())->willReturnCallback( + function ($string) { + return $string; + } + ); + // Create a mock for global function logger() + $this->getFunctionMock('Zotlabs\Lib', 'logger'); + + // Create a stub for the PermissionDescription class + $stub = $this->createMock(PermissionDescription::class); + $stub->method('get_permission_description') + ->will($this->returnArgument(0)); + + $permDescSelf = PermissionDescription::fromStandalonePermission(0); + $this->assertInstanceOf(PermissionDescription::class, $permDescSelf); + $this->assertEquals($permDescSelf->get_permission_description(), 'Only me'); + + $permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC); + $this->assertEquals($permDescPublic->get_permission_description(), 'Public'); + } +} -- cgit v1.2.3