|
10 | 10 |
|
11 | 11 | namespace chillerlan\QRCodeTest\Data; |
12 | 12 |
|
13 | | -use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version}; |
| 13 | +use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, Version}; |
14 | 14 | use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix}; |
15 | 15 | use chillerlan\QRCode\QROptions; |
16 | 16 | use chillerlan\QRCodeTest\QRMaxLengthTrait; |
@@ -68,6 +68,24 @@ abstract public static function stringValidateProvider():array; |
68 | 68 | */ |
69 | 69 | public function testValidateString(string $string, bool $expected):void{ |
70 | 70 | $this::assertSame($expected, $this->dataMode::validateString($string)); |
| 71 | + |
| 72 | + // back out on potentially invalid strings |
| 73 | + if($expected === false){ |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + $dataModeInterface = static::getDataModeInterface($string); |
| 78 | + $bitBuffer = new BitBuffer; |
| 79 | + // check if the validated string encodes without error |
| 80 | + // https://github.com/chillerlan/php-qrcode/pull/313 |
| 81 | + $dataModeInterface->write($bitBuffer, 40); |
| 82 | + $bitBuffer->rewind(); |
| 83 | + // read 4 bits (data mode indicator) |
| 84 | + $bitBuffer->read(4); |
| 85 | + // decode and check against the given string |
| 86 | + $decoded = $dataModeInterface::decodeSegment($bitBuffer, 40); |
| 87 | + |
| 88 | + $this::assertSame($string, $decoded); |
71 | 89 | } |
72 | 90 |
|
73 | 91 | /** |
|
0 commit comments