QRCodeTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Class QRCodeTest
  4. *
  5. * @filesource QRCodeTest.php
  6. * @created 17.11.2017
  7. * @package chillerlan\QRCodeTest
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest;
  13. use chillerlan\QRCode\QROptions;
  14. use chillerlan\QRCode\QRCode;
  15. class QRCodeTest extends QRTestAbstract{
  16. protected $FQCN = QRCode::class;
  17. /**
  18. * @var \chillerlan\QRCode\QRCode
  19. */
  20. protected $qrcode;
  21. protected function setUp(){
  22. parent::setUp();
  23. $this->qrcode = $this->reflection->newInstance();
  24. }
  25. public function testIsNumber(){
  26. $this->assertTrue($this->qrcode->isNumber('0123456789'));
  27. $this->assertFalse($this->qrcode->isNumber('ABC'));
  28. }
  29. public function testIsAlphaNum(){
  30. $this->assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
  31. $this->assertFalse($this->qrcode->isAlphaNum('abc'));
  32. }
  33. public function testIsKanji(){
  34. $this->assertTrue($this->qrcode->isKanji('茗荷'));
  35. $this->assertFalse($this->qrcode->isKanji('Ã'));
  36. }
  37. // coverage
  38. public function typeDataProvider(){
  39. return [
  40. [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'],
  41. [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'],
  42. [QRCode::OUTPUT_IMAGE_JPG, 'data:image/jpg;base64,'],
  43. [QRCode::OUTPUT_MARKUP_SVG, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'],
  44. [QRCode::OUTPUT_MARKUP_HTML, '<div><span style="background:'],
  45. [QRCode::OUTPUT_STRING_TEXT, '⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕'.PHP_EOL],
  46. [QRCode::OUTPUT_STRING_JSON, '[[18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],'],
  47. ];
  48. }
  49. /**
  50. * @dataProvider typeDataProvider
  51. * @param $type
  52. */
  53. public function testRenderImage($type, $expected){
  54. $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['outputType' => $type])]);
  55. $this->assertContains($expected, $this->qrcode->render('test'));
  56. }
  57. /**
  58. * @expectedException \chillerlan\QRCode\QRCodeException
  59. * @expectedExceptionMessage Invalid error correct level: 42
  60. */
  61. public function testSetOptionsException(){
  62. $this->qrcode->setOptions(new QROptions(['eccLevel' => 42]));
  63. }
  64. /**
  65. * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException
  66. * @expectedExceptionMessage invalid output type
  67. */
  68. public function testInitDataInterfaceException(){
  69. $this->qrcode->setOptions(new QROptions(['outputType' => 'foo']))->render('test');
  70. }
  71. /**
  72. * @expectedException \chillerlan\QRCode\Data\QRCodeDataException
  73. * @expectedExceptionMessage QRCode::getMatrix() No data given.
  74. */
  75. public function testGetMatrixException(){
  76. $this->qrcode->getMatrix('');
  77. }
  78. public function testImageTransparencyBGDefault(){
  79. $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['imageTransparencyBG' => 'foo'])]);
  80. $this->assertSame([255,255,255], $this->getProperty('options')->getValue($this->qrcode)->imageTransparencyBG);
  81. }
  82. }