Skip to content
Snippets Groups Projects
Commit 5c9fc1b7 authored by Joseph Olstad's avatar Joseph Olstad
Browse files

Issue #3455186 by cmlara, joseph.olstad - Refactor tests for D11 phpunit 10+...

Issue #3455186 by cmlara, joseph.olstad - Refactor tests for D11 phpunit 10+ compatibility refactoring test.
parent 288d4ebb
No related branches found
No related tags found
No related merge requests found
Pipeline #332487 failed
......@@ -51,16 +51,19 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
foreach ($terms_to_view as $index => $term) {
$expected_parents = array_reverse($terms[$index]);
// Configure loadAllParents pour renvoyer la hiérarchie correcte selon l'ID.
// Adjust the loadAllParents mock callback to handle missing parents gracefully.
$term_storage->method('loadAllParents')
->willReturnCallback(function ($term_id) use ($parentRelationships, $created) {
$parents = [];
while (isset($parentRelationships[$term_id])) {
$parent_id = $parentRelationships[$term_id];
$parents[] = $created[array_search($parent_id, array_column($created, 'id'))];
if (isset($created[array_search($parent_id, array_column($created, 'id'))])) {
$parents[] = $created[$parent_id];
}
$term_id = $parent_id;
}
return array_reverse($parents);
// Return parents array after filtering any nulls.
return array_filter(array_reverse($parents));
});
}
......@@ -110,6 +113,7 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
// Array to store parent relationships.
$parentRelationships = [];
// Create terms based on the hierarchy tree and store parent relationships.
return array_map(function (array $lineage) use (&$created, &$parentRelationships): array {
$terms = [];
foreach ($lineage as $name) {
......@@ -127,12 +131,13 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$terms[] = $created[$name];
}
// Populate parent relationships.
foreach (array_reverse($lineage) as $index => $name) {
$parent = next($lineage);
// Store parent relationships for the reversed lineage.
$parent = NULL;
foreach (array_reverse($lineage) as $name) {
if ($parent) {
$parentRelationships[$created[$name]->id()] = $created[$parent]->id();
$parentRelationships[$created[$name]->id()] = $parent->id();
}
$parent = $created[$name];
}
return $terms;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment