QRMarkupTestAbstract.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Class QRMarkupTestAbstract
  4. *
  5. * @created 24.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Output;
  11. use chillerlan\QRCode\Data\QRMatrix;
  12. /**
  13. * Tests the QRMarkup output module
  14. */
  15. abstract class QRMarkupTestAbstract extends QROutputTestAbstract{
  16. public static function moduleValueProvider():array{
  17. return [
  18. 'invalid: wrong type' => [[], false],
  19. 'valid: hex color (3)' => ['#abc', true],
  20. 'valid: hex color (4)' => ['#abcd', true],
  21. 'valid: hex color (6)' => ['#aabbcc', true],
  22. 'valid: hex color (8)' => ['#aabbccdd', true],
  23. 'invalid: hex color (non-hex)' => ['#aabbcxyz', false],
  24. 'invalid: hex color (too short)' => ['#aa', false],
  25. 'invalid: hex color (5)' => ['#aabbc', false],
  26. 'invalid: hex color (7)' => ['#aabbccd', false],
  27. 'valid: rgb(...%)' => ['rgb(100.0%, 0.0%, 0.0%)', true],
  28. 'valid: rgba(...)' => [' rgba(255, 0, 0, 1.0) ', true],
  29. 'valid: hsl(...)' => ['hsl(120, 60%, 50%)', true],
  30. 'valid: hsla(...)' => ['hsla(120, 255, 191.25, 1.0)', true],
  31. 'invalid: rgba(non-numeric)' => ['rgba(255, 0, whatever, 0, 1.0)', false],
  32. 'invalid: rgba(extra-char)' => ['rgba(255, 0, 0, 1.0);', false],
  33. 'valid: csscolor' => ['purple', true],
  34. 'invalid: c5sc0lor' => ['c5sc0lor', false],
  35. ];
  36. }
  37. /**
  38. * @inheritDoc
  39. */
  40. public function testSetModuleValues():void{
  41. $this->options->outputBase64 = false;
  42. $this->options->drawLightModules = true;
  43. $this->options->moduleValues = [
  44. // data
  45. QRMatrix::M_DATA_DARK => '#4A6000',
  46. QRMatrix::M_DATA => '#ECF9BE',
  47. ];
  48. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  49. $data = $this->outputInterface->dump();
  50. $this::assertStringContainsString('#4A6000', $data);
  51. $this::assertStringContainsString('#ECF9BE', $data);
  52. }
  53. }