|
11 | 11 |
|
12 | 12 | namespace chillerlan\QRCodeTest\Data; |
13 | 13 |
|
14 | | -use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version}; |
| 14 | +use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, Version}; |
15 | 15 | use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix}; |
16 | 16 | use chillerlan\QRCode\QROptions; |
17 | 17 | use chillerlan\QRCodeTest\QRMaxLengthTrait; |
@@ -72,6 +72,24 @@ abstract public static function stringValidateProvider():array; |
72 | 72 | #[DataProvider('stringValidateProvider')] |
73 | 73 | public function testValidateString(string $string, bool $expected):void{ |
74 | 74 | $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); |
75 | 93 | } |
76 | 94 |
|
77 | 95 | /** |
|
0 commit comments