<?php
namespace Tests\Unit\Helpers;

use PHPUnit\Framework\TestCase;
use App\Helpers\ExcelSanitizeHelper;

class ExcelSanitizeHelperTest extends TestCase
{
    /**
     * Test sanitizeArrayData with various input scenarios.
     */
    public function testSanitizeArrayData()
    {
        // Test with a flat array
        $input = [
            "validString" => "HelloWorld",
            "withNonPrintable" => "‌71030034240400000016",
            "withWhitespace" => "   Trim me   ",
            "withNonInBetween" => "Santosh\u00a0Badatya",
            "nonStringValue" => 'Hello
World',
        ];
        $expected = [
            "validString" => "HelloWorld",
            "withNonPrintable" => "71030034240400000016",
            "withWhitespace" => "Trim me",
            "withNonInBetween" => "Santosh Badatya",
            "nonStringValue" => 'HelloWorld',
        ];
        $result = ExcelSanitizeHelper::sanitizeArrayData($input);
        // var_dump($input);
        // var_dump($result);
        $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));

        // Test with nested arrays
        $input = [
            "nested" => [
                "validString" => "‌71030034240400000016",
                "withNonPrintable" => "Nested\x01\x02String_x000A_",
            ],
            "withWhitespace" => "   Outer whitespace   ",
        ];var_dump($input);
        $expected = [
            "nested" => [
                "validString" => "71030034240400000016",
                "withNonPrintable" => "NestedString",
            ],
            "withWhitespace" => "Outer whitespace",
        ];
        $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));

        // Test with empty array
        $this->assertSame([], ExcelSanitizeHelper::sanitizeArrayData([]));

        // Test with an array containing only non-string values
        $input = [
            "integer" => 42,
            "float" => 3.14,
            "boolean" => true,
            "null" => null,
        ];
        $this->assertSame($input, ExcelSanitizeHelper::sanitizeArrayData($input));

        // Test with invalid input to ensure graceful handling (edge case)
        $input = ["invalid" => "\x00\x01\x7F_x000D_", "normal" => "Text"];
        $expected = ["invalid" => "", "normal" => "Text"];
        $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));
    }
}
