Skip to content

Commit a9c7ebb

Browse files
committed
Fix units tests
1 parent 9d674db commit a9c7ebb

File tree

3 files changed

+109
-37
lines changed

3 files changed

+109
-37
lines changed

src/Controller.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,10 @@ private static function addGroupsForActorType(CommonDBTM $item, Config $moconfig
232232
$criteria = [
233233
'groups_id' => $user->fields['groups_id'],
234234
$idField => $object->fields['id'],
235+
'type' => $actorType,
235236
];
236237

237-
// Add type for assigned technicians
238-
if ($actorType == \CommonITILActor::ASSIGN) {
239-
$criteria['type'] = \CommonITILActor::ASSIGN;
240-
}
241-
242238
if (!$t_group->getFromDBByCrit($criteria)) {
243-
if ($actorType == \CommonITILActor::ASSIGN) {
244-
$criteria['type'] = \CommonITILActor::ASSIGN;
245-
}
246-
247239
$t_group->add($criteria);
248240
}
249241
} else {
@@ -261,23 +253,16 @@ private static function addGroupsForActorType(CommonDBTM $item, Config $moconfig
261253
$criteria = [
262254
'groups_id' => $ug['groups_id'],
263255
$idField => $object->fields['id'],
256+
'type' => $actorType,
264257
];
265258

266-
// Add type for assigned technicians
267-
if ($actorType == \CommonITILActor::ASSIGN) {
268-
$criteria['type'] = \CommonITILActor::ASSIGN;
269-
}
270-
271259
if (!$t_group->getFromDBByCrit($criteria)) {
272260
$groupData = [
273261
'groups_id' => $ug['groups_id'],
274262
$idField => $object->fields['id'],
263+
'type' => $actorType,
275264
];
276265

277-
if ($actorType == \CommonITILActor::ASSIGN) {
278-
$groupData['type'] = \CommonITILActor::ASSIGN;
279-
}
280-
281266
$t_group->add($groupData);
282267
}
283268
}

tests/MoreOptionsTestCase.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,49 @@ protected function getCurrentConfig(): Config
131131
}
132132
return $config;
133133
}
134+
135+
/**
136+
* Clear session messages
137+
*/
138+
protected function clearSessionMessages(): void
139+
{
140+
if (isset($_SESSION['MESSAGE_AFTER_REDIRECT'])) {
141+
$_SESSION['MESSAGE_AFTER_REDIRECT'] = [];
142+
}
143+
}
144+
145+
/**
146+
* Clear specific log entries containing a pattern
147+
*/
148+
protected function clearLogEntriesContaining(string $pattern): void
149+
{
150+
if (!isset($this->log_handler)) {
151+
return;
152+
}
153+
154+
$records = $this->log_handler->getRecords();
155+
foreach ($records as $key => $log) {
156+
if (isset($log['message']) && str_contains($log['message'], $pattern)) {
157+
unset($records[$key]);
158+
}
159+
}
160+
161+
$this->log_handler->clear();
162+
foreach (array_values($records) as $record) {
163+
$this->log_handler->handle($record);
164+
}
165+
}
166+
167+
/**
168+
* Initialize session variables for entity management
169+
*/
170+
protected function initEntitySession(): void
171+
{
172+
if (!isset($_SESSION['glpiactiveentities_string'])) {
173+
$_SESSION['glpiactiveentities_string'] = '';
174+
}
175+
if (!isset($_SESSION['glpiactiveentities'])) {
176+
$_SESSION['glpiactiveentities'] = [];
177+
}
178+
}
134179
}

0 commit comments

Comments
 (0)