Skip to content

Commit 01ff294

Browse files
committed
:octocat: DataInterfaceTestAbstract::testValidateString() added an additional test (see #313)
1 parent 9d18219 commit 01ff294

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/Data/DataInterfaceTestAbstract.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace chillerlan\QRCodeTest\Data;
1313

14-
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
14+
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, Version};
1515
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
1616
use chillerlan\QRCode\QROptions;
1717
use chillerlan\QRCodeTest\QRMaxLengthTrait;
@@ -72,6 +72,24 @@ abstract public static function stringValidateProvider():array;
7272
#[DataProvider('stringValidateProvider')]
7373
public function testValidateString(string $string, bool $expected):void{
7474
$this::assertSame($expected, $this->dataMode::validateString($string));
75+
76+
// back out on potentially invalid strings
77+
if($expected === false){
78+
return;
79+
}
80+
81+
$dataModeInterface = static::getDataModeInterface($string);
82+
$bitBuffer = new BitBuffer;
83+
// check if the validated string encodes without error
84+
// https://github.com/chillerlan/php-qrcode/pull/313
85+
$dataModeInterface->write($bitBuffer, 40);
86+
$bitBuffer->rewind();
87+
// read 4 bits (data mode indicator)
88+
$bitBuffer->read(4);
89+
// decode and check against the given string
90+
$decoded = $dataModeInterface::decodeSegment($bitBuffer, 40);
91+
92+
$this::assertSame($string, $decoded);
7593
}
7694

7795
/**

0 commit comments

Comments
 (0)