Skip to content
Snippets Groups Projects
Commit 58922d9d 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 7e947bc7
No related branches found
No related tags found
No related merge requests found
Pipeline #332545 failed
......@@ -56,11 +56,11 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
// Adjust `loadAllParents` to use the class property for parent relationships.
$term_storage->method('loadAllParents')
->willReturnCallback(function ($term_id) {
$parents = [];
while (isset($this->parentRelationships[$term_id])) {
$parent = $this->parentRelationships[$term_id];
if ($parent === NULL) {
->willReturnCallback(function ($term_id) use ($parentRelationships) {
$parents = [];
while (isset($parentRelationships[$term_id])) {
$parent = $parentRelationships[$term_id];
if (!$parent) {
break;
}
$parents[] = $parent;
......@@ -78,23 +78,24 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
LanguageInterface::LANGCODE_DEFAULT,
);
$this->assertCount(count($expectations), $elements);
$this->assertCount(count($expectations), $elements, "Mismatch in expected element count.");
foreach ($expectations as $expected_terms) {
$group_title = (string) array_shift($expected_terms);
$group = current($elements);
// Use array_values to enforce numeric indexing for better comparison.
$this->assertSame(
(string) $group['#title'],
$group_title,
"Group title does not match."
);
(string) $group['#title'],
"Mismatch in group title for expected terms."
);
$actual_labels = array_map(static fn($term) => (string) $term['label'], $group['#terms']);
$this->assertSame(
array_values($actual_labels),
array_values(array_map('strval', $expected_terms)),
"Expected and actual term labels do not match."
);
array_values(array_map('strval', $expected_terms)),
array_values($actual_labels),
"Mismatch in term labels between expected and actual."
);
next($elements);
}
......@@ -111,35 +112,41 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
*/
protected function createTerms(array $tree): array {
$created = [];
$parentRelationships = [];
// Create mock terms based on the hierarchy tree.
return array_map(function (array $lineage) use (&$created): array {
$terms = [];
return array_map(function (array $lineage) use (&$created, &$parentRelationships): array {
$terms = [];
foreach ($lineage as $name) {
if (!isset($created[$name])) {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$term = $this->createMock(TermInterface::class);
$term->method('id')->willReturn($this->getFixedTermId($name));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
$term = $this->createMock(TermInterface::class);
$term->method('id')->willReturn($this->getFixedTermId($name));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
$created[$name] = $term;
$created[$name] = $term;
}
$terms[] = $created[$name];
$terms[] = $created[$name];
}
// Establish parent relationships in reverse lineage.
$previous = NULL;
$previous = NULL;
foreach (array_reverse($terms) as $term) {
if ($previous) {
$this->parentRelationships[$previous->id()] = $term;
$parentRelationships[$previous->id()] = $term;
}
$previous = $term;
$previous = $term;
}
// Debug output of relationships for each term.
echo "Parent relationships:\n";
foreach ($parentRelationships as $child_id => $parent) {
echo "Child ID: $child_id, Parent ID: " . ($parent->id() ?? 'None') . "\n";
}
return $terms;
return $terms;
}, $tree);
}
......
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