<?php

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;

class UploadsHtaccessTest extends TestCase
{
    public function test_uploads_htaccess_blocks_php_execution(): void
    {
        // setup.sh does `rm -rf uploads` then `mv uploads_seeder uploads`, so
        // exactly one of these exists depending on whether the project has been
        // installed yet: uploads_seeder/.htaccess before setup (uploads/ is
        // gitignored and absent), uploads/.htaccess after. Assert on whichever
        // is present so the test is correct in both contexts.
        $htaccess = file_exists(base_path('uploads/.htaccess'))
            ? base_path('uploads/.htaccess')
            : base_path('uploads_seeder/.htaccess');
        $this->assertFileExists($htaccess);
        $content = file_get_contents($htaccess);
        $this->assertStringContainsString('Require all denied', $content);
        $this->assertStringContainsString('Deny from all', $content);
        $this->assertMatchesRegularExpression('/FilesMatch\s+"[^"]*php/', $content);
        $this->assertStringContainsString('-Indexes', $content);
    }
}
