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