From 1b5437b675f6ceda4318f19522d47a08f28f95a8 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Tue, 3 Sep 2024 11:58:36 +0900 Subject: [PATCH] Add testing for new added bom utf8 replace --- .../Convert/CoreLibsConvertStringsTest.php | 48 +++++++++++++++++++ 4dev/tests/Convert/data/UTF8.csv | 1 + 4dev/tests/Convert/data/UTF8BOM.csv | 1 + 4dev/tests/Get/CoreLibsGetSystemTest.php | 23 +++++++++ www/admin/class_test.system.php | 4 +- 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 4dev/tests/Convert/data/UTF8.csv create mode 100644 4dev/tests/Convert/data/UTF8BOM.csv diff --git a/4dev/tests/Convert/CoreLibsConvertStringsTest.php b/4dev/tests/Convert/CoreLibsConvertStringsTest.php index 0b2f79a5..c6c92251 100644 --- a/4dev/tests/Convert/CoreLibsConvertStringsTest.php +++ b/4dev/tests/Convert/CoreLibsConvertStringsTest.php @@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase; */ final class CoreLibsConvertStringsTest extends TestCase { + private const DATA_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR; + /** * Undocumented function * @@ -330,6 +332,52 @@ final class CoreLibsConvertStringsTest extends TestCase \CoreLibs\Convert\Strings::stripMultiplePathSlashes($input) ); } + + /** + * Undocumented function + * + * @return array + */ + public function providerStripUTF8BomBytes(): array + { + return [ + "utf8-bom" => [ + "file" => "UTF8BOM.csv", + "expect" => "Asset Type,Epic,File Name\n", + ], + "utf8" => [ + "file" => "UTF8.csv", + "expect" => "Asset Type,Epic,File Name\n", + ], + ]; + } + + /** + * test utf8 bom remove + * + * @covers ::stripUTF8BomBytes + * @dataProvider providerStripUTF8BomBytes + * @testdox stripUTF8BomBytes $file will be $expected [$_dataName] + * + * @param string $file + * @param string $expected + * @return void + */ + public function testStripUTF8BomBytes(string $file, string $expected): void + { + // load sample file + if (!is_file(self::DATA_FOLDER . $file)) { + $this->markTestSkipped('File: ' . $file . ' could not be opened'); + } + $file = file_get_contents(self::DATA_FOLDER . $file); + if ($file === false) { + $this->markTestSkipped('File: ' . $file . ' could not be read'); + } + $this->assertEquals( + $expected, + \CoreLibs\Convert\Strings::stripUTF8BomBytes($file) + ); + } } // __END__ diff --git a/4dev/tests/Convert/data/UTF8.csv b/4dev/tests/Convert/data/UTF8.csv new file mode 100644 index 00000000..e19b2444 --- /dev/null +++ b/4dev/tests/Convert/data/UTF8.csv @@ -0,0 +1 @@ +Asset Type,Epic,File Name diff --git a/4dev/tests/Convert/data/UTF8BOM.csv b/4dev/tests/Convert/data/UTF8BOM.csv new file mode 100644 index 00000000..87ddd559 --- /dev/null +++ b/4dev/tests/Convert/data/UTF8BOM.csv @@ -0,0 +1 @@ +Asset Type,Epic,File Name diff --git a/4dev/tests/Get/CoreLibsGetSystemTest.php b/4dev/tests/Get/CoreLibsGetSystemTest.php index a73e91fc..9017a6d8 100644 --- a/4dev/tests/Get/CoreLibsGetSystemTest.php +++ b/4dev/tests/Get/CoreLibsGetSystemTest.php @@ -216,6 +216,29 @@ final class CoreLibsGetSystemTest extends TestCase ); } } + + /** + * Undocumented function + * + * @covers ::getIpAddresses + * @testdox getIpAddresses check + * + * @return void + */ + public function testGetIpAddresses() + { + // response must have "REMOTE_ADDR" entry, others are optional + // NOTE: we have no IP addresses on command line + $this->assertTrue( + true, + "We do not have REMOTE_ADDR on command line" + ); + // $this->assertContains( + // 'REMOTE_ADDR', + // array_keys(\CoreLibs\Get\System::getIpAddresses()), + // 'failed REMOTE_ADDR assert' + // ); + } } // __END__ diff --git a/www/admin/class_test.system.php b/www/admin/class_test.system.php index 86c0fd3b..f59a68a1 100644 --- a/www/admin/class_test.system.php +++ b/www/admin/class_test.system.php @@ -41,7 +41,7 @@ print "GETPAGENAME(0): " . System::getPageName() . "
"; print "GETPAGENAME(1): " . System::getPageName(System::NO_EXTENSION) . "
"; print "GETPAGENAME(2): " . System::getPageName(System::FULL_PATH) . "
"; print "System::getPageNameArray():
"; -print "GETPAGENAMEARRAY: " . \CoreLibs\Debug\Support::printAr(System::getPageNameArray()) . "
"; +print "GETPAGENAMEARRAY: " . DgS::printAr(System::getPageNameArray()) . "
"; // seting errro codes file upload print "System::fileUploadErrorMessage():
"; print "FILEUPLOADERRORMESSAGE(): " . System::fileUploadErrorMessage(-1) . "
"; @@ -51,4 +51,6 @@ print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): " print "System::checkCLI():
"; print "Are we in an CLI: " . (System::checkCLI() ? 'Yes' : 'No') . "
"; +print "Get Addresses: " . DgS::printAr(System::getIpAddresses()) . "
"; + print "";