From d056b13e1495b136bb138cc65c4e311b458db380 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 13 May 2017 00:16:50 +0200 Subject: :construction_worker::white_check_mark: Documentation Permissions.php. Also add some phpunit tests for this class, but there are some problems yet with mocking static functions. --- tests/unit/Access/PermissionsTest.php | 148 ++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 tests/unit/Access/PermissionsTest.php (limited to 'tests/unit/Access') diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php new file mode 100644 index 000000000..93c641fb1 --- /dev/null +++ b/tests/unit/Access/PermissionsTest.php @@ -0,0 +1,148 @@ +markTestIncomplete( + 'Need to mock static function Permissions::Perms() ...' + ); + //$this->assertEquals($expected, Permissions::FilledPerms($permarr)); + +/* $perms = $this->getMockBuilder(Permissions::class) + ->setMethods(['Perms']) + ->getMock(); + $perms->expects($this->once()) + ->method('Perms'); + // still calls the static self::Perms() + $perms->FilledPerms($permarr); +*/ + } + public function FilledPermsProvider() { + return [ + 'empty' => [ + [], + ['perm1' => 0, 'perm2' => 0] + ], + 'valild' => [ + [['perm1' => 1]], + ['perm1' => 1, 'perm2' => 0] + ] + ]; + } +/* public function testFilledPermsNull() { + // need to mock global function btlogger(); + Permissions::FilledPerms(null); + } +*/ + /** + * @dataProvider OPermsProvider + * + * @param array $permarr + * @param array $expected + */ + public function testOPerms($permarr, $expected) { + $this->assertEquals($expected, Permissions::OPerms($permarr)); + } + /** + * @return Associative array with test values for OPerms() + * * \e array Array to test + * * \e array Expect array + */ + public function OPermsProvider() { + return [ + 'empty' => [ + [], + [] + ], + 'valid' => [ + ['perm1' => 1, 'perm2' => 0], + [['name' => 'perm1', 'value' => 1], ['name' => 'perm2', 'value' => 0]] + ], + 'null array' => [ + null, + [] + ] + ]; + } + + + /** + * @dataProvider permsCompareProvider + * + * @param array $p1 + * @param array $p2 + * @param boolean $expectedresult + */ + public function testPermsCompare($p1, $p2, $expectedresult) { + $this->assertEquals($expectedresult, Permissions::PermsCompare($p1, $p2)); + } + /** + * @return Associative array with test values for PermsCompare() + * * \e array 1st array + * * \e array 2nd array + * * \e boolean expected result for the test + */ + public function permsCompareProvider() { + return [ + 'equal' => [ + ['perm1' => 1, 'perm2' => 0], + ['perm1' => 1, 'perm2' => 0], + true + ], + 'different values' => [ + ['perm1' => 1, 'perm2' => 0], + ['perm1' => 0, 'perm2' => 1], + false + ], + 'different order' => [ + ['perm1' => 1, 'perm2' => 0], + ['perm2' => 0, 'perm1' => 1], + true + ], + 'partial first in second' => [ + ['perm1' => 1], + ['perm1' => 1, 'perm2' => 0], + true + ], + 'partial second in first' => [ + ['perm1' => 1, 'perm2' => 0], + ['perm1' => 1], + false + ] + ]; + } +} \ No newline at end of file -- cgit v1.2.3