QrCodeHelperTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
  3. define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
  4. }
  5. define('QR_TEST_STRING', 'Some Text to Translate');
  6. define('QR_TEST_STRING_UTF', 'Some äöü Test String with $ and @ etc');
  7. App::uses('HtmlHelper', 'View/Helper');
  8. App::uses('QrCodeHelper', 'Tools.View/Helper');
  9. App::uses('View', 'View');
  10. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  11. /**
  12. * QrCode Test Case
  13. *
  14. */
  15. class QrCodeHelperTest extends MyCakeTestCase {
  16. /**
  17. * SetUp method
  18. *
  19. * @return void
  20. */
  21. public function setUp() {
  22. parent::setUp();
  23. $this->QrCode = new QrCodeHelper(new View(null));
  24. $this->QrCode->Html = new HtmlHelper(new View(null));
  25. }
  26. /**
  27. * @return void
  28. */
  29. public function testSetSize() {
  30. $is = $this->QrCode->setSize(1000);
  31. //pr($this->QrCode->debug());
  32. $this->assertFalse($is);
  33. $is = $this->QrCode->setSize(300);
  34. //pr($this->QrCode->debug());
  35. $this->assertTrue($is);
  36. }
  37. /**
  38. * @return void
  39. */
  40. public function testImages() {
  41. $this->QrCode->reset();
  42. $is = $this->QrCode->image(QR_TEST_STRING);
  43. //echo $is;
  44. $this->assertTrue(!empty($is));
  45. $is = $this->QrCode->image(QR_TEST_STRING_UTF);
  46. //echo $is;
  47. $this->assertTrue(!empty($is));
  48. $is = $this->QrCode->image('');
  49. //echo $is;
  50. $this->assertTrue(!empty($is));
  51. }
  52. /**
  53. * @return void
  54. */
  55. public function testImagesModified() {
  56. $this->QrCode->reset();
  57. $this->QrCode->setLevel('H');
  58. $is = $this->QrCode->image(QR_TEST_STRING);
  59. //echo $is;
  60. $this->assertTrue(!empty($is));
  61. $this->QrCode->reset();
  62. $this->QrCode->setLevel('H', 20);
  63. $is = $this->QrCode->image(QR_TEST_STRING_UTF);
  64. //echo $is;
  65. $this->assertTrue(!empty($is));
  66. $this->QrCode->reset();
  67. $this->QrCode->setSize(300);
  68. $this->QrCode->setLevel('L', 1);
  69. $is = $this->QrCode->image(QR_TEST_STRING);
  70. //echo $is;
  71. //pr($this->QrCode->debug());
  72. $this->assertTrue(!empty($is));
  73. $this->QrCode->reset();
  74. $this->QrCode->setSize(300);
  75. $this->QrCode->setLevel('H', 1);
  76. $is = $this->QrCode->image(QR_TEST_STRING);
  77. //echo $is;
  78. //pr($this->QrCode->debug());
  79. $this->assertTrue(!empty($is));
  80. }
  81. public function testSpecialImages() {
  82. $this->QrCode->reset();
  83. $this->QrCode->setSize(300);
  84. $this->QrCode->setLevel('H');
  85. //echo 'CARD'.BR;
  86. $string = $this->QrCode->formatCard(array(
  87. 'name' => 'Maier,Susanne',
  88. 'tel' => array('0111222123', '012224344'),
  89. 'nickname' => 'sssnick',
  90. 'birthday' => '1999-01-03',
  91. 'address' => 'Bluetenweg 11, 85375, Neufahrn, Deutschland',
  92. 'email' => 'test@test.de',
  93. 'note' => 'someNote;someOtherNote :)',
  94. 'url' => 'http://www.some_url.de'
  95. ));
  96. $is = $this->QrCode->image($string);
  97. //echo $is;
  98. $this->assertTrue(!empty($is));
  99. }
  100. /**
  101. */
  102. public function testBitcoin() {
  103. $this->QrCode->reset();
  104. $this->QrCode->setSize(100);
  105. $this->QrCode->setLevel('H');
  106. //echo 'CARD'.BR;
  107. $string = $this->QrCode->format('bitcoin', '18pnDgDYFMAKsHTA3ZqyAi6t8q9ztaWWXt');
  108. $is = $this->QrCode->image($string);
  109. //echo $is;
  110. $this->assertTrue(!empty($is));
  111. }
  112. /**
  113. * TearDown method
  114. *
  115. * @return void
  116. */
  117. public function tearDown() {
  118. parent::tearDown();
  119. unset($this->QrCode);
  120. }
  121. }