<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Controller;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Controller\Site\ProductReviewController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

final class ProductReviewControllerTest extends TestCase
{
    public function testInvitationPageDelegatesTheFormToTheLiveComponent(): void
    {
        $routes = Yaml::parseFile(__DIR__ . '/../../src/Bridge/Symfony/Bundle/Resources/config/routes/site_shop.yaml');
        $route = $routes['shop_review_invitation'];

        self::assertSame(ProductReviewController::class . '::invitation', $route['controller']);
        self::assertSame(['GET'], $route['methods']);
        self::assertSame('[A-Za-z0-9_-]{43}', $route['requirements']['token']);

        $template = file_get_contents(
            __DIR__ . '/../../src/Bridge/Symfony/Bundle/Resources/views/marketing/review/invitation.html.twig',
        );

        self::assertIsString($template);
        self::assertStringContainsString('<twig:marketing:ProductReviewForm :token="token" />', $template);
        self::assertStringNotContainsString('form_start(', $template);
    }
}
