<?php

namespace MintyPHP\Tests\Http;

use MintyPHP\Http\AccessControl;
use MintyPHP\Http\IntendedUrlService;
use PHPUnit\Framework\TestCase;

class AccessControlTest extends TestCase
{
    private function createAccessControl(array $publicPaths = []): AccessControl
    {
        return new AccessControl($publicPaths, new IntendedUrlService());
    }

    public function testConfiguredPublicPathIsAccessible(): void
    {
        $accessControl = $this->createAccessControl(['imprint', 'privacy']);

        $this->assertTrue($accessControl->isPublicPath('imprint'));
        $this->assertTrue($accessControl->isPublicPath('/privacy'));
    }

    public function testPageSlugPathIsNotAutoPublic(): void
    {
        $accessControl = $this->createAccessControl(['imprint']);

        $this->assertTrue($accessControl->isPublicPath('imprint'));
        $this->assertFalse($accessControl->isPublicPath('page/imprint'));
    }

    public function testAlwaysPublicPrefixesRemainAccessible(): void
    {
        $accessControl = $this->createAccessControl([]);

        $this->assertTrue($accessControl->isPublicPath('api/v1/health'));
        $this->assertTrue($accessControl->isPublicPath('auth/microsoft/callback'));
    }
}
