QRCodeTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /*
  26. public function optionsDataProvider(){
  27. return [
  28. [QROptions::class],
  29. # [],
  30. ];
  31. }
  32. public function testInstance($options){
  33. $q = $this->reflection->newInstanceArgs([new $options]);
  34. $this->assertInstanceOf($this->FQCN, $q);
  35. # print_r($q->render('test'));
  36. }
  37. */
  38. public function testIsNumber(){
  39. $this->assertTrue($this->qrcode->isNumber('0123456789'));
  40. $this->assertFalse($this->qrcode->isNumber('ABC'));
  41. }
  42. public function testIsAlphaNum(){
  43. $this->assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
  44. $this->assertFalse($this->qrcode->isAlphaNum('abc'));
  45. }
  46. public function testIsKanji(){
  47. $this->assertTrue($this->qrcode->isKanji('茗荷'));
  48. $this->assertFalse($this->qrcode->isKanji('Ã'));
  49. }
  50. // coverage
  51. public function typeDataProvider(){
  52. return [
  53. [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'],
  54. [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'],
  55. [QRCode::OUTPUT_IMAGE_JPG, 'data:image/jpg;base64,'],
  56. [QRCode::OUTPUT_MARKUP_SVG, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'],
  57. [QRCode::OUTPUT_MARKUP_HTML, '<div><span style="background:'],
  58. [QRCode::OUTPUT_STRING_TEXT, '⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕'.PHP_EOL],
  59. [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],'],
  60. ];
  61. }
  62. /**
  63. * @dataProvider typeDataProvider
  64. * @param $type
  65. */
  66. public function testRenderImage($type, $expected){
  67. $this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['outputType' => $type])]);
  68. $this->assertContains($expected, $this->qrcode->render('test'));
  69. }
  70. /**
  71. * @expectedException \chillerlan\QRCode\QRCodeException
  72. * @expectedExceptionMessage Invalid error correct level: 42
  73. */
  74. public function testSetOptionsException(){
  75. $this->qrcode->setOptions(new QROptions(['eccLevel' => 42]));
  76. }
  77. /**
  78. * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException
  79. * @expectedExceptionMessage invalid output type
  80. */
  81. public function testInitDataInterfaceException(){
  82. $this->qrcode->setOptions(new QROptions(['outputType' => 'foo']))->render('test');
  83. }
  84. }