feat(pro): auto-select 'normal' arrangement in generator
- Modified generate() method to loop through arrangements and find 'normal' (case-insensitive) - Falls back to first arrangement if 'normal' not found - Added test: testGenerateSelectsNormalArrangementWhenPresent - Added test: testGenerateFallsBackToFirstArrangementWhenNoNormal - All 12 ProFileGenerator tests pass (82 assertions)
This commit is contained in:
parent
e7c014abfe
commit
7de43f4aec
|
|
@ -112,8 +112,17 @@ final class ProFileGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
$presentation->setArrangements($arrangementProtos);
|
$presentation->setArrangements($arrangementProtos);
|
||||||
if (isset($arrangementProtos[0])) {
|
|
||||||
$presentation->setSelectedArrangement($arrangementProtos[0]->getUuid());
|
$selectedArrangement = null;
|
||||||
|
foreach ($arrangementProtos as $arr) {
|
||||||
|
if (strtolower($arr->getName()) === 'normal') {
|
||||||
|
$selectedArrangement = $arr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$selectedArrangement = $selectedArrangement ?? ($arrangementProtos[0] ?? null);
|
||||||
|
if ($selectedArrangement) {
|
||||||
|
$presentation->setSelectedArrangement($selectedArrangement->getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
self::applyCcliMetadata($presentation, $ccli);
|
self::applyCcliMetadata($presentation, $ccli);
|
||||||
|
|
|
||||||
|
|
@ -466,4 +466,79 @@ class ProFileGeneratorTest extends TestCase
|
||||||
$this->assertNotNull($textScroller);
|
$this->assertNotNull($textScroller);
|
||||||
$this->assertFalse($textScroller->getShouldScroll());
|
$this->assertFalse($textScroller->getShouldScroll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function testGenerateSelectsNormalArrangementWhenPresent(): void
|
||||||
|
{
|
||||||
|
$song = ProFileGenerator::generate(
|
||||||
|
'SelectTest',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'name' => 'V1',
|
||||||
|
'color' => [0, 0, 0, 1],
|
||||||
|
'slides' => [
|
||||||
|
['text' => 'Hello'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['name' => 'other', 'groupNames' => ['V1']],
|
||||||
|
['name' => 'normal', 'groupNames' => ['V1']],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
$filePath = $this->tmpDir . '/select-test.pro';
|
||||||
|
ProFileWriter::write($song, $filePath);
|
||||||
|
$readSong = ProFileReader::read($filePath);
|
||||||
|
$selectedUuid = $readSong->getSelectedArrangementUuid();
|
||||||
|
|
||||||
|
// Find which arrangement has this UUID
|
||||||
|
$selectedArrangement = null;
|
||||||
|
foreach ($readSong->getArrangements() as $arrangement) {
|
||||||
|
if ($arrangement->getUuid() === $selectedUuid) {
|
||||||
|
$selectedArrangement = $arrangement;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertNotNull($selectedArrangement);
|
||||||
|
$this->assertSame('normal', $selectedArrangement->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function testGenerateFallsBackToFirstArrangementWhenNoNormal(): void
|
||||||
|
{
|
||||||
|
$song = ProFileGenerator::generate(
|
||||||
|
'FallbackTest',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'name' => 'V1',
|
||||||
|
'color' => [0, 0, 0, 1],
|
||||||
|
'slides' => [
|
||||||
|
['text' => 'Hello'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['name' => 'custom', 'groupNames' => ['V1']],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
$filePath = $this->tmpDir . '/fallback-test.pro';
|
||||||
|
ProFileWriter::write($song, $filePath);
|
||||||
|
$readSong = ProFileReader::read($filePath);
|
||||||
|
$selectedUuid = $readSong->getSelectedArrangementUuid();
|
||||||
|
|
||||||
|
// Find which arrangement has this UUID
|
||||||
|
$selectedArrangement = null;
|
||||||
|
foreach ($readSong->getArrangements() as $arrangement) {
|
||||||
|
if ($arrangement->getUuid() === $selectedUuid) {
|
||||||
|
$selectedArrangement = $arrangement;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertNotNull($selectedArrangement);
|
||||||
|
$this->assertSame('custom', $selectedArrangement->getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue