QrCodeHelperTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * 2009-07-30 ms
  29. */
  30. public function testSetSize() {
  31. $is = $this->QrCode->setSize(1000);
  32. //pr($this->QrCode->debug());
  33. $this->assertFalse($is);
  34. $is = $this->QrCode->setSize(300);
  35. //pr($this->QrCode->debug());
  36. $this->assertTrue($is);
  37. }
  38. /**
  39. * @return void
  40. * 2009-07-30 ms
  41. */
  42. public function testImages() {
  43. $this->QrCode->reset();
  44. $is = $this->QrCode->image(QR_TEST_STRING);
  45. //echo $is;
  46. $this->assertTrue(!empty($is));
  47. $is = $this->QrCode->image(QR_TEST_STRING_UTF);
  48. //echo $is;
  49. $this->assertTrue(!empty($is));
  50. $is = $this->QrCode->image('');
  51. //echo $is;
  52. $this->assertTrue(!empty($is));
  53. }
  54. /**
  55. * @return void
  56. * 2009-07-30 ms
  57. */
  58. public function testImagesModified() {
  59. $this->QrCode->reset();
  60. $this->QrCode->setLevel('H');
  61. $is = $this->QrCode->image(QR_TEST_STRING);
  62. //echo $is;
  63. $this->assertTrue(!empty($is));
  64. $this->QrCode->reset();
  65. $this->QrCode->setLevel('H', 20);
  66. $is = $this->QrCode->image(QR_TEST_STRING_UTF);
  67. //echo $is;
  68. $this->assertTrue(!empty($is));
  69. $this->QrCode->reset();
  70. $this->QrCode->setSize(300);
  71. $this->QrCode->setLevel('L', 1);
  72. $is = $this->QrCode->image(QR_TEST_STRING);
  73. //echo $is;
  74. //pr($this->QrCode->debug());
  75. $this->assertTrue(!empty($is));
  76. $this->QrCode->reset();
  77. $this->QrCode->setSize(300);
  78. $this->QrCode->setLevel('H', 1);
  79. $is = $this->QrCode->image(QR_TEST_STRING);
  80. //echo $is;
  81. //pr($this->QrCode->debug());
  82. $this->assertTrue(!empty($is));
  83. }
  84. public function testSpecialImages() {
  85. $this->QrCode->reset();
  86. $this->QrCode->setSize(300);
  87. $this->QrCode->setLevel('H');
  88. //echo 'CARD'.BR;
  89. $string = $this->QrCode->formatCard(array(
  90. 'name' => 'Maier,Susanne',
  91. 'tel' => array('0111222123', '012224344'),
  92. 'nickname' => 'sssnick',
  93. 'birthday' => '1999-01-03',
  94. 'address' => 'Bluetenweg 11, 85375, Neufahrn, Deutschland',
  95. 'email' => 'test@test.de',
  96. 'note' => 'someNote;someOtherNote :)',
  97. 'url' => 'http://www.some_url.de'
  98. ));
  99. $is = $this->QrCode->image($string);
  100. //echo $is;
  101. $this->assertTrue(!empty($is));
  102. }
  103. /**
  104. * 2011-07-19 ms
  105. */
  106. public function testBitcoin() {
  107. $this->QrCode->reset();
  108. $this->QrCode->setSize(100);
  109. $this->QrCode->setLevel('H');
  110. //echo 'CARD'.BR;
  111. $string = $this->QrCode->format('bitcoin', '18pnDgDYFMAKsHTA3ZqyAi6t8q9ztaWWXt');
  112. $is = $this->QrCode->image($string);
  113. //echo $is;
  114. $this->assertTrue(!empty($is));
  115. }
  116. /**
  117. * tearDown method
  118. *
  119. * @return void
  120. */
  121. public function tearDown() {
  122. parent::tearDown();
  123. unset($this->QrCode);
  124. }
  125. }