<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Form;

use Ferienpass\AdminBundle\Form\LoginPasswordType;
use Ferienpass\AdminBundle\Form\LoginTargetPathType;
use Ferienpass\AdminBundle\Form\LoginUsernameType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

final class LoginFormTypesTest extends TestCase
{
    // ---- LoginPasswordType ----

    public function testLoginPasswordTypeGetParent(): void
    {
        self::assertSame(PasswordType::class, (new LoginPasswordType())->getParent());
    }

    public function testLoginPasswordTypeBuildViewSetsFullName(): void
    {
        $view = new FormView();
        $form = $this->createMock(FormInterface::class);

        (new LoginPasswordType())->buildView($view, $form, []);

        self::assertSame('_password', $view->vars['full_name']);
    }

    // ---- LoginTargetPathType ----

    public function testLoginTargetPathTypeBuildViewSetsFullName(): void
    {
        $view = new FormView();
        $form = $this->createMock(FormInterface::class);

        (new LoginTargetPathType())->buildView($view, $form, []);

        self::assertSame('_target_path', $view->vars['full_name']);
    }

    // ---- LoginUsernameType ----

    public function testLoginUsernameTypeGetParent(): void
    {
        $authUtils = $this->createMock(AuthenticationUtils::class);
        self::assertSame(EmailType::class, (new LoginUsernameType($authUtils))->getParent());
    }

    public function testLoginUsernameTypeBuildViewSetsFullName(): void
    {
        $authUtils = $this->createMock(AuthenticationUtils::class);
        $view = new FormView();
        $form = $this->createMock(FormInterface::class);

        (new LoginUsernameType($authUtils))->buildView($view, $form, []);

        self::assertSame('_username', $view->vars['full_name']);
    }
}
