|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace TestsDependency; |
| 4 | + |
| 5 | +use BaconQrCode\Renderer\Image\ImagickImageBackEnd; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; |
| 8 | +use RobThree\Auth\TwoFactorAuth; |
| 9 | +use RobThree\Auth\Providers\Qr\HandlesDataUri; |
| 10 | + |
| 11 | +class BaconQRCodeTest extends TestCase |
| 12 | +{ |
| 13 | + use HandlesDataUri; |
| 14 | + |
| 15 | + public function testDependency() |
| 16 | + { |
| 17 | + // php < 7.1 will install an older Bacon QR Code |
| 18 | + if (! class_exists(ImagickImageBackEnd::class)) { |
| 19 | + $this->expectException(\RuntimeException::class); |
| 20 | + |
| 21 | + $qr = new BaconQrCodeProvider(1, '#000', '#FFF', 'svg'); |
| 22 | + } else { |
| 23 | + $qr = new BaconQrCodeProvider(1, '#000', '#FFF', 'svg'); |
| 24 | + |
| 25 | + $tfa = new TwoFactorAuth('Test&Issuer', 6, 30, 'sha1', $qr); |
| 26 | + |
| 27 | + $data = $this->DecodeDataUri($tfa->getQRCodeImageAsDataUri('Test&Label', 'VMR466AB62ZBOKHE')); |
| 28 | + $this->assertEquals('image/svg+xml', $data['mimetype']); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public function testBadTextColour() |
| 33 | + { |
| 34 | + $this->expectException(\RuntimeException::class); |
| 35 | + |
| 36 | + new BaconQrCodeProvider(1, 'not-a-colour', '#FFF'); |
| 37 | + } |
| 38 | + |
| 39 | + public function testBadBackgroundColour() |
| 40 | + { |
| 41 | + $this->expectException(\RuntimeException::class); |
| 42 | + |
| 43 | + new BaconQrCodeProvider(1, '#000', 'not-a-colour'); |
| 44 | + } |
| 45 | + |
| 46 | + public function testBadTextColourHexRef() |
| 47 | + { |
| 48 | + $this->expectException(\RuntimeException::class); |
| 49 | + |
| 50 | + new BaconQrCodeProvider(1, '#AAAA', '#FFF'); |
| 51 | + } |
| 52 | + |
| 53 | + public function testBadBackgroundColourHexRef() |
| 54 | + { |
| 55 | + $this->expectException(\RuntimeException::class); |
| 56 | + |
| 57 | + new BaconQrCodeProvider(1, '#000', '#AAAA'); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | +} |
0 commit comments