QrCodeHelperTest.php 3.3 KB

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