QRMarkupTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 $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->imageBase64 = false;
  39. $this->options->outputType = $type;
  40. $this->setOutputInterface();
  41. $expected = explode($this->options->eol, file_get_contents($this::cachefile.$type));
  42. // cut off the doctype & head
  43. array_shift($expected);
  44. if($type === QRCode::OUTPUT_MARKUP_HTML){
  45. // cut off the </body> tag
  46. array_pop($expected);
  47. }
  48. $expected = implode($this->options->eol, $expected);
  49. $this->assertSame(trim($expected), trim($this->outputInterface->dump()));
  50. }
  51. public function testSetModuleValues(){
  52. $this->options->imageBase64 = false;
  53. $this->options->moduleValues = [
  54. // data
  55. 1024 => '#4A6000',
  56. 4 => '#ECF9BE',
  57. ];
  58. $this->setOutputInterface();
  59. $data = $this->outputInterface->dump();
  60. $this->assertStringContainsString('#4A6000', $data);
  61. $this->assertStringContainsString('#ECF9BE', $data);
  62. }
  63. }