Files
Investidor-V2/tests/Feature/DeskReceiptCompatibilityTest.php
2026-11-02 20:31:15 +02:00

29 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
final class DeskReceiptCompatibilityTest extends TestCase
{
public function test_existing_direct_receipt_consumers_keep_their_contract_and_escape_preserved_answers(): void
{
$definition = ['title' => 'Synthetic receipt', 'fields' => [
'branch' => ['label' => 'Synthetic branch', 'type' => 'select', 'options' => ['no' => 'No', 'yes' => 'Yes']],
'detail' => ['label' => 'Synthetic preserved detail', 'type' => 'text', 'when' => ['field' => 'branch', 'equals' => 'yes']],
]];
$payload = ['branch' => 'no', 'detail' => '<script>alert("synthetic")</script>'];
$record = (object) ['id' => 'synthetic-id', 'protocol' => 'SYNTHETIC-QA', 'submitted_at' => '2026-11-02 10:00:00', 'version' => 2];
$html = view('desk.receipt', ['record' => $record, 'snapshot' => ['payload' => $payload], 'definition' => $definition])->render();
[$active, $preserved] = explode('Respostas conservadas de perguntas não aplicáveis', $html, 2);
$this->assertStringNotContainsString('Synthetic preserved detail', $active);
$this->assertStringContainsString('Synthetic preserved detail', $preserved);
$this->assertStringContainsString('&lt;script&gt;', $preserved);
$this->assertStringNotContainsString('<script>', $html);
$payload['branch'] = 'yes';
$html = view('desk.receipt', ['record' => $record, 'snapshot' => ['payload' => $payload], 'definition' => $definition])->render();
$this->assertStringNotContainsString('Respostas conservadas de perguntas não aplicáveis', $html);
$this->assertStringContainsString('Synthetic preserved detail', $html);
}
}