MarkupTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. *
  4. * @filesource MarkupTest.php
  5. * @created 17.12.2016
  6. * @package chillerlan\QRCodeTest\Output
  7. * @author Smiley <smiley@chillerlan.net>
  8. * @copyright 2016 Smiley
  9. * @license MIT
  10. */
  11. namespace chillerlan\QRCodeTest\Output;
  12. use chillerlan\QRCode\Output\QRMarkup;
  13. use chillerlan\QRCode\Output\QRMarkupOptions;
  14. use chillerlan\QRCode\QRCode;
  15. /**
  16. * Class MarkupTest
  17. */
  18. class MarkupTest extends OutputTestAbstract{
  19. protected $outputInterfaceClass = QRMarkup::class;
  20. protected $outputOptionsClass = QRMarkupOptions::class;
  21. public function testOptions(){
  22. $this->assertEquals(QRCode::OUTPUT_MARKUP_SVG, $this->options->type);
  23. }
  24. public function markupDataProvider(){
  25. return [
  26. [QRCode::OUTPUT_MARKUP_HTML, true, 'foobar', 'str1.html'],
  27. [QRCode::OUTPUT_MARKUP_HTML, false, 'foobar', 'str2.html'],
  28. [QRCode::OUTPUT_MARKUP_HTML, true, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str3.html'],
  29. [QRCode::OUTPUT_MARKUP_HTML, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str4.html'],
  30. [QRCode::OUTPUT_MARKUP_SVG , null, 'foobar', 'str1.svg'],
  31. [QRCode::OUTPUT_MARKUP_SVG , null, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.svg'],
  32. ];
  33. }
  34. /**
  35. * @dataProvider markupDataProvider
  36. */
  37. public function testMarkupOutput($type, $omitEndTag, $data, $expected){
  38. $this->options->type = $type;
  39. $this->options->htmlOmitEndTag = $omitEndTag;
  40. $this->options->cssClass = 'test';
  41. $this->assertEquals(file_get_contents(__DIR__.'/markup/'.$expected), (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output());
  42. }
  43. public function markupTestDataProvider(){
  44. return [
  45. [QRCode::OUTPUT_MARKUP_SVG],
  46. [QRCode::OUTPUT_MARKUP_HTML],
  47. ];
  48. }
  49. /**
  50. * @dataProvider markupTestDataProvider
  51. */
  52. public function testSaveToFile(string $type){
  53. $this->options->type = $type;
  54. $this->options->cssClass = 'foo';
  55. $data = (new QRCode('foo', new $this->outputInterfaceClass($this->options)))->output();
  56. $this->options->cachefile = __DIR__.'/markup/save_test.'.$type;
  57. $this->assertTrue((new QRCode('foo', new $this->outputInterfaceClass($this->options)))->output());
  58. $this->assertContains($data, file_get_contents($this->options->cachefile));
  59. }
  60. /**
  61. * @dataProvider markupTestDataProvider
  62. *
  63. * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException
  64. * @expectedExceptionMessage Could not write to cache file
  65. */
  66. public function testSaveToFileException(string $type){
  67. $this->options->type = $type;
  68. $this->options->cachefile = __DIR__.'/foo/bar';
  69. (new QRCode('foo', new $this->outputInterfaceClass($this->options)))->output();
  70. }
  71. }