QrCodeHelperTest.php 3.3 KB

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