<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Twig;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Twig\LegalContentRenderer;
use CpCreation\VitiCore\Contact\Model\Contact;
use PHPUnit\Framework\TestCase;

final class LegalContentRendererTest extends TestCase
{
    public function testRendersWhitelistedContactVariables(): void
    {
        $contact = new Contact();
        $contact->setCompany('Maison <Exemple>');
        $contact->setEditorCompany('Éditeur & Associés');
        $contact->setEditorAddress('1 rue des Vignes');
        $contact->setEditorPostal('51200');
        $contact->setEditorCity('Épernay');
        $contact->setEditorRcs('123 456 789');
        $contact->setEditorTva('FR00123456789');

        $content = <<<'HTML'
            <p>{{ contact.company }}</p>
            <p>{{contact.companyUpper}}</p>
            <p>{{ contact.editorCompany }} - {{ contact.editorFullAddress }}</p>
            <p>{{ contact.editorRcs }} - {{ contact.editorTva }}</p>
            <p>{{ contact.unknown }}</p>
            HTML;

        $rendered = new LegalContentRenderer()->render($content, $contact);

        self::assertStringContainsString('Maison &lt;Exemple&gt;', $rendered);
        self::assertStringContainsString('MAISON &lt;EXEMPLE&gt;', $rendered);
        self::assertStringContainsString('Éditeur &amp; Associés - 1 rue des Vignes 51200 Épernay', $rendered);
        self::assertStringContainsString('123 456 789 - FR00123456789', $rendered);
        self::assertStringContainsString('{{ contact.unknown }}', $rendered);
    }
}
