UtilTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\QRConst;
  12. use chillerlan\QRCode\Util;
  13. use PHPUnit\Framework\TestCase;
  14. class UtilTest extends TestCase{
  15. public function testIsNumber(){
  16. $this->assertEquals(true, Util::isNumber('1234567890'));
  17. $this->assertEquals(false, Util::isNumber('abc'));
  18. }
  19. public function testIsAlphaNum(){
  20. $this->assertEquals(true, Util::isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
  21. $this->assertEquals(false, Util::isAlphaNum('#'));
  22. }
  23. // http://stackoverflow.com/a/24755772
  24. public function testIsKanji(){
  25. $this->assertEquals(true, Util::isKanji('茗荷'));
  26. $this->assertEquals(false, Util::isKanji(''));
  27. $this->assertEquals(false, Util::isKanji('ÃÃÃ')); // non-kanji
  28. $this->assertEquals(false, Util::isKanji('荷')); // kanji forced into byte mode due to length
  29. }
  30. // coverage
  31. public function testGetBCHTypeNumber(){
  32. $this->assertEquals(7973, Util::getBCHTypeNumber(1));
  33. }
  34. /**
  35. * @expectedException \chillerlan\QRCode\QRCodeException
  36. * @expectedExceptionMessage $typeNumber: 1 / $errorCorrectLevel: 42
  37. */
  38. public function testGetRSBlocksException(){
  39. Util::getRSBlocks(1, 42);
  40. }
  41. /**
  42. * @expectedException \chillerlan\QRCode\QRCodeException
  43. * @expectedExceptionMessage Invalid error correct level: 42
  44. */
  45. public static function testGetMaxLengthECLevelException(){
  46. Util::getMaxLength(QRCode::TYPE_01, QRConst::MODE_BYTE, 42);
  47. }
  48. /**
  49. * @expectedException \chillerlan\QRCode\QRCodeException
  50. * @expectedExceptionMessage Invalid mode: 1337
  51. */
  52. public static function testGetMaxLengthModeException(){
  53. Util::getMaxLength(QRCode::TYPE_01, 1337, QRCode::ERROR_CORRECT_LEVEL_H);
  54. }
  55. }