QRStringTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Class QRStringTest
  4. *
  5. * @filesource QRStringTest.php
  6. * @created 24.12.2017
  7. * @package chillerlan\QRCodeTest\Output
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Output;
  13. use chillerlan\QRCodeExamples\MyCustomOutput;
  14. use chillerlan\QRCode\{Common\EccLevel, QRCode, QROptions};
  15. use chillerlan\QRCode\Output\{QROutputInterface, QRString};
  16. /**
  17. * Tests the QRString output module
  18. */
  19. class QRStringTest extends QROutputTestAbstract{
  20. /**
  21. * @inheritDoc
  22. * @internal
  23. */
  24. protected function getOutputInterface(QROptions $options):QROutputInterface{
  25. return new QRString($options, $this->matrix);
  26. }
  27. /**
  28. * @inheritDoc
  29. * @internal
  30. */
  31. public function types():array{
  32. return [
  33. 'json' => [QRCode::OUTPUT_STRING_JSON],
  34. 'text' => [QRCode::OUTPUT_STRING_TEXT],
  35. ];
  36. }
  37. /**
  38. * @inheritDoc
  39. */
  40. public function testSetModuleValues():void{
  41. $this->options->moduleValues = [
  42. // data
  43. 1024 => 'A',
  44. 4 => 'B',
  45. ];
  46. $this->outputInterface = $this->getOutputInterface($this->options);
  47. $data = $this->outputInterface->dump();
  48. $this::assertStringContainsString('A', $data);
  49. $this::assertStringContainsString('B', $data);
  50. }
  51. /**
  52. * covers the custom output functionality via an example
  53. */
  54. public function testCustomOutput():void{
  55. $this->options->version = 5;
  56. $this->options->eccLevel = EccLevel::L;
  57. $this->options->outputType = QRCode::OUTPUT_CUSTOM;
  58. $this->options->outputInterface = MyCustomOutput::class;
  59. $this::assertSame(
  60. file_get_contents(__DIR__.'/samples/custom'),
  61. (new QRCode($this->options))->render('test')
  62. );
  63. }
  64. }