<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\OfferCategory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\String\Slugger\AsciiSlugger;
use Symfony\Component\Uid\Uuid;

final class OfferCategoryTest extends TestCase
{
    public function testGetNameIsNullByDefault(): void
    {
        $category = new OfferCategory();

        self::assertNull($category->getName());
    }

    public function testSetNameAndGetName(): void
    {
        $category = new OfferCategory();
        $category->setName('Summer Activities');

        self::assertSame('Summer Activities', $category->getName());
    }

    public function testGetAliasIsNullByDefault(): void
    {
        $category = new OfferCategory();

        self::assertNull($category->getAlias());
    }

    public function testSetAliasAndGetAlias(): void
    {
        $category = new OfferCategory();
        $category->setAlias('summer-activities');

        self::assertSame('summer-activities', $category->getAlias());
    }

    public function testGetCreatedAtIsSetOnConstruct(): void
    {
        $category = new OfferCategory();

        self::assertInstanceOf(\DateTimeInterface::class, $category->getCreatedAt());
    }

    public function testGenerateAliasGeneratesSlugWhenNoAlias(): void
    {
        $category = new OfferCategory();
        $category->setName('My Category');

        $category->generateAlias(new AsciiSlugger());

        self::assertSame('my-category', $category->getAlias());
    }

    public function testGenerateAliasDoesNotOverwriteExistingAlias(): void
    {
        $category = new OfferCategory();
        $category->setName('My Category');
        $category->setAlias('existing-alias');

        $category->generateAlias(new AsciiSlugger());

        self::assertSame('existing-alias', $category->getAlias());
    }

    public function testGetUuidReturnsSetUuid(): void
    {
        $category = new OfferCategory();
        $prop = new \ReflectionProperty(OfferCategory::class, 'uuid');
        $prop->setValue($category, Uuid::fromString('550e8400-e29b-41d4-a716-446655440000'));

        self::assertSame('550e8400-e29b-41d4-a716-446655440000', (string) $category->getUuid());
    }
}
