Skip to content

Commit

Permalink
Support Arabic
Browse files Browse the repository at this point in the history
Base in the last update from ZATCA its should be count the bytes of a string
  • Loading branch information
Salah Alkhwlani committed Oct 14, 2021
1 parent 63f53f6 commit 038fdca
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
"psr-4": {
"Salla\\ZATCA\\Test\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
}
}
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">

<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 3 additions & 1 deletion src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/GenerateQrCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 038fdca

Please sign in to comment.