UtilTest.php 1.8 KB

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