HtmlTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * BaconQrCode
  4. *
  5. * @link http://github.com/Bacon/BaconQrCode For the canonical source repository
  6. * @copyright 2013 Ben 'DASPRiD' Scholzen
  7. * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
  8. */
  9. namespace BaconQrCode\Encoder;
  10. use BaconQrCode\Common\ErrorCorrectionLevel;
  11. use BaconQrCode\Renderer\Text\Html;
  12. use BaconQrCode\Writer;
  13. use PHPUnit_Framework_TestCase as TestCase;
  14. class HtmlTest extends TestCase
  15. {
  16. /**
  17. * @var Html
  18. */
  19. protected $renderer;
  20. /**
  21. * @var Writer
  22. */
  23. protected $writer;
  24. public function setUp()
  25. {
  26. $this->renderer = new Html();
  27. $this->writer = new Writer($this->renderer);
  28. }
  29. public function testBasicRender()
  30. {
  31. $content = 'foobar';
  32. $expected =
  33. '<pre style="font-family: monospace; line-height: 0.65em; letter-spacing: -1px" class="">' .
  34. " \n" .
  35. " ███████ █████ ███████ \n" .
  36. " █ █ █ █ █ █ \n" .
  37. " █ ███ █ ██ █ ███ █ \n" .
  38. " █ ███ █ ███ █ ███ █ \n" .
  39. " █ ███ █ █ █ █ ███ █ \n" .
  40. " █ █ ██ █ █ \n" .
  41. " ███████ █ █ █ ███████ \n" .
  42. " █████ \n" .
  43. " ██ ██ █ ██ █ █ █ \n" .
  44. " ██ ██ █ █ ██ \n" .
  45. " ████████ █ ██ █ ██ \n" .
  46. " ██ █ █ \n" .
  47. " ██ ███ █ █ █ █ \n" .
  48. " █ ███ █ █ \n" .
  49. " ███████ ██ ██████ \n" .
  50. " █ █ ████ ██ \n" .
  51. " █ ███ █ ██ ██ ██ █ ██ \n" .
  52. " █ ███ █ ██ ██ █ ██ \n" .
  53. " █ ███ █ █ █ ██ ██ \n" .
  54. " █ █ ███ ███ ████ \n" .
  55. " ███████ ████ ██ \n" .
  56. " \n" .
  57. '</pre>'
  58. ;
  59. $qrCode = Encoder::encode(
  60. $content,
  61. new ErrorCorrectionLevel(ErrorCorrectionLevel::L),
  62. Encoder::DEFAULT_BYTE_MODE_ECODING
  63. );
  64. $this->assertEquals($expected, $this->renderer->render($qrCode));
  65. }
  66. public function testSetStyle()
  67. {
  68. $content = 'foobar';
  69. $qrCode = Encoder::encode(
  70. $content,
  71. new ErrorCorrectionLevel(ErrorCorrectionLevel::L),
  72. Encoder::DEFAULT_BYTE_MODE_ECODING
  73. );
  74. $this->renderer->setStyle('bar');
  75. $this->assertEquals('bar', $this->renderer->getStyle());
  76. $this->assertStringMatchesFormat('%astyle="bar"%a', $this->renderer->render($qrCode));
  77. }
  78. public function testSetClass()
  79. {
  80. $content = 'foobar';
  81. $qrCode = Encoder::encode(
  82. $content,
  83. new ErrorCorrectionLevel(ErrorCorrectionLevel::L),
  84. Encoder::DEFAULT_BYTE_MODE_ECODING
  85. );
  86. $this->renderer->setClass('bar');
  87. $this->assertEquals('bar', $this->renderer->getClass());
  88. $this->assertStringMatchesFormat('%aclass="bar"%a', $this->renderer->render($qrCode));
  89. }
  90. }