FOSSology  4.4.0
Open Source License Compliance by Open Source Software
GroupPermissionsTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Valens Niyonsenga <valensniyonsenga2003@gmail.com>
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
12 
13 
16 use Monolog\Test\TestCase;
17 
18 class GroupPermissionsTest extends TestCase
19 {
27  private function getGroupPermissionInfo($version = ApiVersion::V2)
28  {
29  $expectedArray = null;
30  if ($version == ApiVersion::V1)
31  {
32  $expectedArray = [
33  "perm" => "Group perm",
34  "group_pk" => 4,
35  "group_name" => "fossy",
36  ];
37  } else {
38  $expectedArray = [
39  "perm" => "Group perm",
40  "groupPk" => 4,
41  "groupName" => "fossy",
42  ];
43  }
44  $obj = new GroupPermission("Group perm",4,"fossy");
45  return [
46  'expectedArray' => $expectedArray,
47  'obj' => $obj
48  ];
49  }
54  public function testDataFormatV1()
55  {
56  $this->testDataFormat(ApiVersion::V1);
57  }
58 
63  public function testDataFormatV2()
64  {
65  $this->testDataFormat(ApiVersion::V2);
66  }
67 
71  private function testDataFormat($version)
72  {
73  $info = $this->getGroupPermissionInfo($version);
74  $expectedArray = $info['expectedArray'];
75  $groupPermission = $info['obj'];
76  $this->assertEquals($expectedArray, $groupPermission->getArray($version));
77  }
83  public function testGetPerm()
84  {
85  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
86  $this->assertEquals("Group perm", $groupPermission->getPerm());
87  }
88 
94  public function testSetPerm()
95  {
96  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
97  $groupPermission->setPerm("New perm");
98  $this->assertEquals("New perm", $groupPermission->getPerm());
99  }
100 
106  public function testGetGroupPk()
107  {
108  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
109  $this->assertEquals("4", $groupPermission->getGroupPk());
110  }
111 
117  public function testSetGroupPk()
118  {
119  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
120  $groupPermission->setGroupPk("10");
121  $this->assertEquals("10", $groupPermission->getGroupPk());
122  }
123 
129  public function testGetGroupName()
130  {
131  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
132  $this->assertEquals("fossy", $groupPermission->getGroupName());
133  }
134 
140  public function testSetGroupName()
141  {
142  $groupPermission = new GroupPermission("Group perm", "4", "fossy");
143  $groupPermission->setGroupName("newName");
144  $this->assertEquals("newName", $groupPermission->getGroupName());
145  }
146 }