Skip to content

Commit bcdb83c

Browse files
committed
:octocat: DataInterfaceTestAbstract::testValidateString() added an additional test (see #313)
(cherry picked from commit 01ff294)
1 parent e5145b1 commit bcdb83c

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
@@ -10,7 +10,7 @@
1010

1111
namespace chillerlan\QRCodeTest\Data;
1212

13-
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
13+
use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, Version};
1414
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
1515
use chillerlan\QRCode\QROptions;
1616
use chillerlan\QRCodeTest\QRMaxLengthTrait;
@@ -68,6 +68,24 @@ abstract public static function stringValidateProvider():array;
6868
*/
6969
public function testValidateString(string $string, bool $expected):void{
7070
$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);
7189
}
7290

7391
/**

0 commit comments

Comments
 (0)