ImageTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. *
  4. * @filesource ImageTest.php
  5. * @created 08.02.2016
  6. * @package chillerlan\QRCodeTest\Output
  7. * @author Smiley <smiley@chillerlan.net>
  8. * @copyright 2015 Smiley
  9. * @license MIT
  10. */
  11. namespace chillerlan\QRCodeTest\Output;
  12. use chillerlan\QRCode\Output\QRImage;
  13. use chillerlan\QRCode\Output\QRImageOptions;
  14. use chillerlan\QRCode\QRCode;
  15. class ImageTest extends OutputTestAbstract{
  16. protected $outputInterfaceClass = QRImage::class;
  17. protected $outputOptionsClass = QRImageOptions::class;
  18. public function testOptions(){
  19. $this->assertEquals(QRCode::OUTPUT_IMAGE_PNG, $this->options->type);
  20. $this->assertEquals(true, $this->options->base64);
  21. }
  22. public function imageDataProvider(){
  23. return [
  24. [QRCode::OUTPUT_IMAGE_PNG, 'foobar', 'img1.png.uri'],
  25. [QRCode::OUTPUT_IMAGE_GIF, 'foobar', 'img1.gif.uri'],
  26. [QRCode::OUTPUT_IMAGE_JPG, 'foobar', 'img1.jpg.uri'],
  27. [QRCode::OUTPUT_IMAGE_PNG, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.png.uri'],
  28. [QRCode::OUTPUT_IMAGE_GIF, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.gif.uri'],
  29. [QRCode::OUTPUT_IMAGE_JPG, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.jpg.uri'],
  30. ];
  31. }
  32. /**
  33. * @dataProvider imageDataProvider
  34. */
  35. public function testImageOutput($type, $data, $expected){
  36. $this->options->type = $type;
  37. $output = (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output();
  38. // jpeg test is causing trouble
  39. if($type === QRCode::OUTPUT_IMAGE_JPG){
  40. $this->markTestSkipped('jpeg test skipped');
  41. }
  42. else{
  43. $this->assertEquals(file_get_contents(__DIR__.'/image/'.$expected), $output);
  44. }
  45. }
  46. }