<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Controller;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Controller\Admin\OrderController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

final class AdminHomepageTodoTest extends TestCase
{
    public function testOfflinePendingOrderFilterIsAccepted(): void
    {
        $reflection = new \ReflectionClass(OrderController::class);
        $controller = $reflection->newInstanceWithoutConstructor();
        $buildOrderFilters = $reflection->getMethod('buildOrderFilters');

        /** @var array{status: string} $filters */
        $filters = $buildOrderFilters->invoke($controller, new Request([
            'status' => 'offline_pending',
        ]));

        self::assertSame('offline_pending', $filters['status']);
        self::assertSame('offline_pending', $filters['query_parameters']['status']);
    }

    public function testDashboardLinksToEachFilteredTodoList(): void
    {
        $template = file_get_contents(
            __DIR__ . '/../../src/Bridge/Symfony/Bundle/Resources/views/admin/homepage.html.twig',
        );

        self::assertIsString($template);
        self::assertStringContainsString("path('admin_withdrawal', { status: 'pending' })", $template);
        self::assertStringContainsString("path('admin_marketing_product_reviews', { status: 'pending' })", $template);
        self::assertStringContainsString("path('admin_order', { status: 'offline_pending' })", $template);
        self::assertStringContainsString("path('admin_order', { status: 'paid_not_delivered' })", $template);
    }
}
