<?php

declare(strict_types=1);

/*
 * 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\Form\Admin;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\CatalogConfigurationType;
use CpCreation\VitiCore\Commerce\Catalog\Model\CatalogConfiguration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CatalogConfigurationTypeTest extends TestCase
{
    public function testOnlyTheExpectedAdministrativeFieldsAreEditable(): void
    {
        $fields = [];
        $builder = $this->createMock(FormBuilderInterface::class);
        $builder->method('add')
            ->willReturnCallback(static function (string $child) use (&$fields, $builder): FormBuilderInterface {
                $fields[] = $child;

                return $builder;
            });

        new CatalogConfigurationType()->buildForm($builder, []);

        self::assertSame(['enabled', 'monitoringEnabled', 'hubUrl'], $fields);
    }

    public function testItMapsThePersistentConfiguration(): void
    {
        $resolver = new OptionsResolver();
        new CatalogConfigurationType()->configureOptions($resolver);

        $options = $resolver->resolve();
        self::assertSame(CatalogConfiguration::class, $options['data_class']);
        self::assertSame('messages', $options['translation_domain']);
    }
}
