QrCodeHelperTest.php 3.3 KB

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