From 038fdca0ba875edf78ffc2efe5b71bf157bd3ac7 Mon Sep 17 00:00:00 2001 From: Salah Alkhwlani Date: Thu, 14 Oct 2021 17:06:37 +0300 Subject: [PATCH] Support Arabic Base in the last update from ZATCA its should be count the bytes of a string --- README.md | 2 +- composer.json | 3 +++ phpunit.xml | 23 +++++++++++++++++++++++ src/Tag.php | 4 +++- tests/Unit/GenerateQrCodeTest.php | 15 +++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml diff --git a/README.md b/README.md index 691e208..4e30077 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ $generatedString = GenerateQrCode::fromArray([ ])->toTLV(); ``` -## Render A QR Code Image +### Render A QR Code Image You can render the tags as QR code image easily diff --git a/composer.json b/composer.json index b45ba2e..b94d2c4 100644 --- a/composer.json +++ b/composer.json @@ -39,5 +39,8 @@ "psr-4": { "Salla\\ZATCA\\Test\\": "tests/" } + }, + "scripts": { + "test": "phpunit" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..2d39420 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + + tests + + + + + src/ + + + diff --git a/src/Tag.php b/src/Tag.php index ca60acc..056a88d 100644 --- a/src/Tag.php +++ b/src/Tag.php @@ -31,11 +31,13 @@ public function getValue() } /** + * its important to get the number of bytes of a string instated of number of characters + * * @return false|int */ public function getLength() { - return mb_strlen($this->value); + return strlen($this->value); } /** diff --git a/tests/Unit/GenerateQrCodeTest.php b/tests/Unit/GenerateQrCodeTest.php index 0d9cb44..2ab18f0 100644 --- a/tests/Unit/GenerateQrCodeTest.php +++ b/tests/Unit/GenerateQrCodeTest.php @@ -29,6 +29,21 @@ public function shouldGenerateAQrCode() 'AQVTYWxsYQIKMTIzNDU2Nzg5MQMUMjAyMS0wNy0xMlQxNDoyNTowOVoEBjEwMC4wMAUFMTUuMDA=', $generatedString); } + /** @test */ + public function shouldGenerateAQrCodeAsArabic() + { + $generatedString = GenerateQrCode::fromArray([ + new Tag(1, 'سلة'), + new Tag(2, '1234567891'), + new Tag(3, '2021-07-12T14:25:09Z'), + new Tag(4, '100.00'), + new Tag(5, '15.00') + ])->toBase64(); + + $this->assertEquals( + 'AQbYs9mE2KkCCjEyMzQ1Njc4OTEDFDIwMjEtMDctMTJUMTQ6MjU6MDlaBAYxMDAuMDAFBTE1LjAw', $generatedString); + } + /** @test */ public function shouldGenerateAQrCodeFromTagsClasses() {