<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class AuthRegisterSecurityContractTest extends TestCase
{
    use ProjectFileAssertionSupport;

    public function testRegisterPageVerifiesCsrfBeforeHandlingPostPayload(): void
    {
        $content = $this->readProjectFile('pages/auth/register().php');

        $this->assertStringContainsString("if (\$request->isMethod('POST')) {", $content);
        $this->assertStringContainsString("if (!Session::checkCsrfToken()) {", $content);
        $this->assertStringContainsString("t('Form expired, please try again')", $content);
        $this->assertMatchesRegularExpression(
            '/if \(\$request->isMethod\(\'POST\'\)\) \{\s*if \(!Session::checkCsrfToken\(\)\) \{/s',
            $content
        );
    }
}
