QRMarkupTest.php 1.7 KB

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