QRMarkupTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Class QRMarkupTest
  4. *
  5. * @filesource QRMarkupTest.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\QRCode\{QRCode, Output\QRMarkup};
  14. class QRMarkupTest extends QROutputTestAbstract{
  15. protected string $FQCN = QRMarkup::class;
  16. public function types():array{
  17. return [
  18. 'html' => [QRCode::OUTPUT_MARKUP_HTML],
  19. 'svg' => [QRCode::OUTPUT_MARKUP_SVG],
  20. ];
  21. }
  22. /**
  23. * @dataProvider types
  24. */
  25. public function testMarkupOutputFile(string $type):void{
  26. $this->options->outputType = $type;
  27. $this->options->cachefile = $this::cachefile.$type;
  28. $this->setOutputInterface();
  29. $data = $this->outputInterface->dump();
  30. $this::assertSame($data, file_get_contents($this->options->cachefile));
  31. }
  32. /**
  33. * @dataProvider types
  34. */
  35. public function testMarkupOutput(string $type):void{
  36. $this->options->outputType = $type;
  37. $this->setOutputInterface();
  38. $expected = explode($this->options->eol, file_get_contents($this::cachefile.$type));
  39. // cut off the doctype & head
  40. array_shift($expected);
  41. if($type === QRCode::OUTPUT_MARKUP_HTML){
  42. // cut off the </body> tag
  43. array_pop($expected);
  44. }
  45. $expected = implode($this->options->eol, $expected);
  46. $this::assertSame(trim($expected), trim($this->outputInterface->dump()));
  47. }
  48. public function testSetModuleValues():void{
  49. $this->options->moduleValues = [
  50. // data
  51. 1024 => '#4A6000',
  52. 4 => '#ECF9BE',
  53. ];
  54. $this->setOutputInterface();
  55. $data = $this->outputInterface->dump();
  56. $this::assertStringContainsString('#4A6000', $data);
  57. $this::assertStringContainsString('#ECF9BE', $data);
  58. }
  59. }