FIX_EXCEL_SANTIZE_HELPER_IMPROVED
This commit is contained in:
parent
1f1f66cf3a
commit
478e085304
67
tests/unit/ExcelSanitizeHelperTest.php
Normal file
67
tests/unit/ExcelSanitizeHelperTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?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" => "HelloWorld",
|
||||
"withNonPrintable" => "71030034240400000016",
|
||||
"withWhitespace" => " Trim me ",
|
||||
"nonStringValue" => 'Hello
|
||||
World',
|
||||
];
|
||||
$expected = [
|
||||
"validString" => "HelloWorld",
|
||||
"withNonPrintable" => "71030034240400000016",
|
||||
"withWhitespace" => "Trim me",
|
||||
"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));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user