StringTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. *
  4. * @filesource StringTest.php
  5. * @created 08.02.2016
  6. * @package chillerlan\QRCodeTest\Output
  7. * @author Smiley <smiley@chillerlan.net>
  8. * @copyright 2015 Smiley
  9. * @license MIT
  10. */
  11. namespace chillerlan\QRCodeTest\Output;
  12. use chillerlan\QRCode\Output\QRString;
  13. use chillerlan\QRCode\Output\QRStringOptions;
  14. use chillerlan\QRCode\QRCode;
  15. class StringTest extends \PHPUnit_Framework_TestCase{
  16. /**
  17. * @var \chillerlan\QRCode\Output\QRStringOptions
  18. */
  19. protected $options;
  20. protected function setUp(){
  21. $this->options = new QRStringOptions;
  22. }
  23. public function testOptionsInstance(){
  24. $this->assertInstanceOf(QRStringOptions::class, $this->options);
  25. $this->assertEquals(QRCode::OUTPUT_STRING_HTML, $this->options->type);
  26. }
  27. public function stringDataProvider(){
  28. return [
  29. [QRCode::OUTPUT_STRING_HTML, true, 'foobar', 'str1.html'],
  30. [QRCode::OUTPUT_STRING_HTML, false, 'foobar', 'str2.html'],
  31. [QRCode::OUTPUT_STRING_HTML, true, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str3.html'],
  32. [QRCode::OUTPUT_STRING_HTML, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str4.html'],
  33. [QRCode::OUTPUT_STRING_JSON, false, 'foobar', 'str1.json'],
  34. [QRCode::OUTPUT_STRING_JSON, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.json'],
  35. [QRCode::OUTPUT_STRING_TEXT, false, 'foobar', 'str1.txt'],
  36. [QRCode::OUTPUT_STRING_TEXT, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.txt'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider stringDataProvider
  41. */
  42. public function testStringOutput($type, $omitEndTag, $data, $expected){
  43. $this->options->type = $type;
  44. $this->options->htmlOmitEndTag = $omitEndTag;
  45. $this->assertEquals(file_get_contents(__DIR__.'/string/'.$expected), (new QRCode($data, new QRString($this->options)))->output());
  46. }
  47. /**
  48. * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException
  49. * @expectedExceptionMessage Invalid string output type!
  50. */
  51. public function testOutputTypeException(){
  52. $this->options->type = 'foo';
  53. new QRString($this->options);
  54. }
  55. /**
  56. * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException
  57. * @expectedExceptionMessage Invalid matrix!
  58. */
  59. public function testSetMatrixException(){
  60. (new QRString)->setMatrix([]);
  61. }
  62. }