UtilTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @filesource UtilTest.php
  4. * @created 08.02.2016
  5. * @author Smiley <smiley@chillerlan.net>
  6. * @copyright 2015 Smiley
  7. * @license MIT
  8. */
  9. namespace chillerlan\QRCodeTest;
  10. use chillerlan\QRCode\QRCode;
  11. use chillerlan\QRCode\Data\QRDataInterface;
  12. use chillerlan\QRCode\Util;
  13. use PHPUnit\Framework\TestCase;
  14. class UtilTest extends TestCase{
  15. /**
  16. * @var \chillerlan\QRCode\Util
  17. */
  18. protected $util;
  19. public function setUp(){
  20. $this->util = new Util;
  21. }
  22. public function testIsNumber(){
  23. $this->assertEquals(true, $this->util->isNumber('1234567890'));
  24. $this->assertEquals(false, $this->util->isNumber('abc'));
  25. }
  26. public function testIsAlphaNum(){
  27. $this->assertEquals(true, $this->util->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
  28. $this->assertEquals(false, $this->util->isAlphaNum('#'));
  29. }
  30. // http://stackoverflow.com/a/24755772
  31. public function testIsKanji(){
  32. $this->assertEquals(true, $this->util->isKanji('茗荷'));
  33. $this->assertEquals(false, $this->util->isKanji(''));
  34. $this->assertEquals(false, $this->util->isKanji('ÃÃÃ')); // non-kanji
  35. $this->assertEquals(false, $this->util->isKanji('荷')); // kanji forced into byte mode due to length
  36. }
  37. // coverage
  38. public function testGetBCHTypeNumber(){
  39. $this->assertEquals(7973, $this->util->getBCHTypeNumber(1));
  40. }
  41. /**
  42. * @expectedException \chillerlan\QRCode\QRCodeException
  43. * @expectedExceptionMessage $typeNumber: 1 / $errorCorrectLevel: 42
  44. */
  45. public function testGetRSBlocksException(){
  46. $this->util->getRSBlocks(1, 42);
  47. }
  48. /**
  49. * @expectedException \chillerlan\QRCode\QRCodeException
  50. * @expectedExceptionMessage Invalid error correct level: 42
  51. */
  52. public function testGetMaxLengthECLevelException(){
  53. $this->util->getMaxLength(QRCode::TYPE_01, QRDataInterface::MODE_BYTE, 42);
  54. }
  55. /**
  56. * @expectedException \chillerlan\QRCode\QRCodeException
  57. * @expectedExceptionMessage Invalid mode: 1337
  58. */
  59. public function testGetMaxLengthModeException(){
  60. $this->util->getMaxLength(QRCode::TYPE_01, 1337, QRCode::ERROR_CORRECT_LEVEL_H);
  61. }
  62. }