|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @filesource DataTest.php |
|
5
|
|
|
* @created 08.02.2016 |
|
6
|
|
|
* @author Smiley <[email protected]> |
|
7
|
|
|
* @copyright 2015 Smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace chillerlan\QRCodeTest\Data; |
|
12
|
|
|
|
|
13
|
|
|
use chillerlan\QRCode\BitBuffer; |
|
14
|
|
|
use chillerlan\QRCode\QRConst; |
|
15
|
|
|
use chillerlan\QRCode\Data\AlphaNum; |
|
16
|
|
|
use chillerlan\QRCode\Data\Byte; |
|
17
|
|
|
use chillerlan\QRCode\Data\Kanji; |
|
18
|
|
|
use chillerlan\QRCode\Data\Number; |
|
19
|
|
|
|
|
20
|
|
|
class DataTest extends \PHPUnit_Framework_TestCase{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \chillerlan\QRCode\BitBuffer |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $bitBuffer; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \chillerlan\QRCode\Data\QRDataInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $module; |
|
31
|
|
|
|
|
32
|
|
|
public function bitProvider(){ |
|
33
|
|
|
return [ |
|
34
|
|
|
[QRConst::MODE_NUMBER, Number::class, '123456789'], |
|
35
|
|
|
[QRConst::MODE_NUMBER, Number::class, '1234567890'], |
|
36
|
|
|
[QRConst::MODE_NUMBER, Number::class, '12345678901'], |
|
37
|
|
|
[QRConst::MODE_ALPHANUM, AlphaNum::class, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'], |
|
38
|
|
|
[QRConst::MODE_BYTE, Byte::class, '#\\'], |
|
39
|
|
|
[QRConst::MODE_KANJI, Kanji::class, '茗荷'], |
|
40
|
|
|
]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function setUp(){ |
|
44
|
|
|
$this->bitBuffer = new BitBuffer; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @dataProvider bitProvider |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testMode($mode, $class, $data){ |
|
51
|
|
|
$this->module = new $class($data); |
|
52
|
|
|
$this->assertEquals($mode, $this->module->mode); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @dataProvider bitProvider |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testWrite($mode, $class, $data){ |
|
|
|
|
|
|
59
|
|
|
$this->bitBuffer->clear(); |
|
60
|
|
|
$this->module = new $class($data); |
|
61
|
|
|
$this->module->write($this->bitBuffer); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @expectedException \chillerlan\QRCode\Data\QRCodeDataException |
|
66
|
|
|
* @expectedExceptionMessage illegal char: 92 |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testAlphaNumCharException(){ |
|
69
|
|
|
$this->bitBuffer->clear(); |
|
70
|
|
|
$this->module = new AlphaNum('\\'); |
|
71
|
|
|
$this->module->write($this->bitBuffer); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @expectedException \chillerlan\QRCode\Data\QRCodeDataException |
|
76
|
|
|
* @expectedExceptionMessage illegal char at 7 (50051) |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testKanjiCharExceptionA(){ |
|
79
|
|
|
$this->bitBuffer->clear(); |
|
80
|
|
|
$this->module = new Kanji('茗荷Ã'); |
|
81
|
|
|
$this->module->write($this->bitBuffer); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @expectedException \chillerlan\QRCode\Data\QRCodeDataException |
|
86
|
|
|
* @expectedExceptionMessage illegal char at 7 |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testKanjiCharExceptionB(){ |
|
89
|
|
|
$this->bitBuffer->clear(); |
|
90
|
|
|
$this->module = new Kanji('茗荷\\'); |
|
91
|
|
|
$this->module->write($this->bitBuffer); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @expectedException \chillerlan\QRCode\Data\QRCodeDataException |
|
96
|
|
|
* @expectedExceptionMessage illegal char: 92 |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testNumberCharException(){ |
|
99
|
|
|
$this->bitBuffer->clear(); |
|
100
|
|
|
$this->module = new Number('\\'); |
|
101
|
|
|
$this->module->write($this->bitBuffer); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.