Skip to content

Commit

Permalink
Merge pull request #160 from Bernhard-Krop/code-39-extended
Browse files Browse the repository at this point in the history
Fixing a bug in Code 39 Extended (with or without checksum)
  • Loading branch information
casperbakker authored Jul 1, 2022
2 parents 52f3453 + 85d0feb commit 6476eb0
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 76 deletions.
2 changes: 0 additions & 2 deletions src/Types/TypeCode39.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public function getBarcodeData(string $code): Barcode
throw new InvalidLengthException('You should provide a barcode string.');
}

$code = strtoupper($code);

if ($this->extended) {
// extended mode
$code = $this->encode_code39_ext($code);
Expand Down
14 changes: 11 additions & 3 deletions tests/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ class TypesTest extends TestCase
public function test_generator_can_generate_code_39_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$result = $generator->getBarcode('1234567890abcABC', $generator::TYPE_CODE_39);
$result = $generator->getBarcode('1234567890ABC', $generator::TYPE_CODE_39);

$this->assertStringEqualsFile('tests/verified-files/C39-1234567890abcABC.svg', $result);
$this->assertStringEqualsFile('tests/verified-files/C39-1234567890ABC.svg', $result);
}

public function test_generator_can_generate_code_39_checksum_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$result = $generator->getBarcode('1234567890abcABC', $generator::TYPE_CODE_39_CHECKSUM);
$result = $generator->getBarcode('1234567890ABC', $generator::TYPE_CODE_39_CHECKSUM);

$this->assertGreaterThan(100, strlen($result));
}

public function test_generator_can_generate_code_39_extended_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$result = $generator->getBarcode('1234567890abcABC', $generator::TYPE_CODE_39E);

$this->assertStringEqualsFile('tests/verified-files/C39E-1234567890abcABC.svg', $result);
}

public function test_generator_can_generate_code_39_extended_checksum_barcode()
{
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
Expand Down
5 changes: 3 additions & 2 deletions tests/VerifiedBarcodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
class VerifiedBarcodeTest extends TestCase
{
public static $supportedBarcodes = [
['type' => BarcodeGenerator::TYPE_CODE_39, 'barcodes' => ['1234567890abcABC']],
['type' => BarcodeGenerator::TYPE_CODE_39_CHECKSUM, 'barcodes' => ['1234567890abcABC']],
['type' => BarcodeGenerator::TYPE_CODE_39, 'barcodes' => ['1234567890ABC']],
['type' => BarcodeGenerator::TYPE_CODE_39_CHECKSUM, 'barcodes' => ['1234567890ABC']],
['type' => BarcodeGenerator::TYPE_CODE_39E, 'barcodes' => ['1234567890abcABC']],
['type' => BarcodeGenerator::TYPE_CODE_39E_CHECKSUM, 'barcodes' => ['1234567890abcABC']],
['type' => BarcodeGenerator::TYPE_CODE_93, 'barcodes' => ['1234567890abcABC']],
['type' => BarcodeGenerator::TYPE_STANDARD_2_5, 'barcodes' => ['1234567890']],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 37 additions & 22 deletions tests/verified-files/C39E+-1234567890abcABC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions tests/verified-files/C39E-1234567890abcABC.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6476eb0

Please sign in to comment.