Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/NestedSetsQueryBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,54 @@ public function testLeavesMethodRequiresLeftAttributeOrderingForConsistentResult
}
}
}

public function testRootsMethodRequiresLeftAttributeOrderingWhenTreeAttributeIsDisabled(): void
{
$this->createDatabase();

$root = new Tree(['name' => 'Root']);

$root->makeRoot();

$query = Tree::find()->roots();

$sql = $query->createCommand()->getRawSql();

self::assertStringContainsString(
'ORDER BY',
$sql,
'\'roots()\' query should include \'ORDER BY\' clause for consistent results.',
);
self::assertStringContainsString(
'`lft`',
$sql,
'\'roots()\' query should order by \'left\' attribute for deterministic ordering.',
);

$roots = $query->all();

self::assertCount(
1,
$roots,
'Should return exactly \'1\' root node when \'treeAttribute\' is disabled.',
);

if (isset($roots[0])) {
self::assertInstanceOf(
Tree::class,
$roots[0],
'Root node should be an instance of \'Tree\'.',
);
self::assertEquals(
'Root',
$roots[0]->getAttribute('name'),
'Root should have the correct name.',
);
self::assertEquals(
1,
$roots[0]->getAttribute('lft'),
'Root should have left value of \'1\' indicating it is a root node.',
);
}
}
}