<?php

namespace Tests\Unit;

use Mtc\Cms\Support\PagedataGuard;
use PHPUnit\Framework\TestCase;

class PagedataGuardTest extends TestCase
{
    public function test_rejects_type_name_as_value_for_image_fields(): void
    {
        $this->assertTrue(PagedataGuard::isCorruptFileValue('image', 'image'));
    }

    public function test_rejects_type_name_as_value_for_file_fields(): void
    {
        $this->assertTrue(PagedataGuard::isCorruptFileValue('file', 'file'));
    }

    public function test_allows_real_filenames(): void
    {
        $this->assertFalse(PagedataGuard::isCorruptFileValue('image', '1784234406customers.png'));
        $this->assertFalse(PagedataGuard::isCorruptFileValue('file', '1784234406terms.pdf'));
    }

    public function test_allows_clearing_an_image(): void
    {
        $this->assertFalse(PagedataGuard::isCorruptFileValue('image', ''));
        $this->assertFalse(PagedataGuard::isCorruptFileValue('image', null));
    }

    public function test_ignores_non_file_field_types(): void
    {
        // A text field may legitimately contain the word "image".
        $this->assertFalse(PagedataGuard::isCorruptFileValue('text', 'image'));
        $this->assertFalse(PagedataGuard::isCorruptFileValue('textarea', 'file'));
        $this->assertFalse(PagedataGuard::isCorruptFileValue(null, 'image'));
    }

    public function test_cross_type_values_are_not_flagged(): void
    {
        // Only an exact value/type match is the known corruption signature.
        $this->assertFalse(PagedataGuard::isCorruptFileValue('image', 'file'));
        $this->assertFalse(PagedataGuard::isCorruptFileValue('file', 'image'));
    }
}
