|
11 | 11 | namespace chillerlan\QRCodeTest\Data;
|
12 | 12 |
|
13 | 13 | use chillerlan\QRCode\Common\BitBuffer;
|
| 14 | +use chillerlan\QRCode\Common\EccLevel; |
14 | 15 | use chillerlan\QRCode\Common\MaskPattern;
|
| 16 | +use chillerlan\QRCode\Data\Byte; |
15 | 17 | use chillerlan\QRCode\Data\QRData;
|
16 | 18 | use chillerlan\QRCode\Output\QRGdImagePNG;
|
17 | 19 | use chillerlan\QRCode\QRCode;
|
@@ -63,4 +65,28 @@ public function testSetBitBuffer():void{
|
63 | 65 | $this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s');
|
64 | 66 | }
|
65 | 67 |
|
| 68 | + public function testEstimateTotalBitLength():void{ |
| 69 | + |
| 70 | + $options = new QROptions([ |
| 71 | + 'versionMin' => 10, |
| 72 | + 'quietzoneSize' => 2, |
| 73 | + 'eccLevel' => EccLevel::H, |
| 74 | +# 'outputType' => QROutputInterface::CUSTOM, |
| 75 | +# 'outputInterface' => PmaQrCodeSVG::class, |
| 76 | + 'outputBase64' => false, |
| 77 | + 'cssClass' => 'pma-2fa-qrcode', |
| 78 | + 'drawCircularModules' => true, |
| 79 | + ]); |
| 80 | + |
| 81 | + // version 10H has a maximum of 976 bits, which is the exact length of the string below |
| 82 | + // QRData::estimateTotalBitLength() used to substract 4 bits for a hypothetical data mode indicator |
| 83 | + // we're now going the safe route and do not do that anymore... |
| 84 | + $str = 'otpauth://totp/user?secret=P2SXMJFJ7DJGHLVEQYBNH2EYM4FH66CR'. |
| 85 | + '&issuer=phpMyAdmin%20%28%29&digits=6&algorithm=SHA1&period=30'; |
| 86 | + |
| 87 | + $qrData = new QRData($options, [new Byte($str)]); |
| 88 | + |
| 89 | + $this::assertSame(980, $qrData->estimateTotalBitLength()); |
| 90 | + } |
| 91 | + |
66 | 92 | }
|
0 commit comments