1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Test\Parser\FieldParser; |
4
|
|
|
|
5
|
|
|
use Mockery as m; |
6
|
|
|
use Graze\CiffRenderer\Test\AbstractFieldParserTest; |
7
|
|
|
use Graze\CiffRenderer\BarcodeGenerator\BarcodeGeneratorFactory; |
8
|
|
|
use Graze\CiffRenderer\BarcodeGenerator\BarcodeGeneratorInterface; |
9
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserBarcode; |
10
|
|
|
use \SimpleXMLElement; |
11
|
|
|
|
12
|
|
|
class FieldParserBarcodeTest extends AbstractFieldParserTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var BarcodeGeneratorFactory |
16
|
|
|
*/ |
17
|
|
|
private $barcodeGeneratorFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var FieldParserBarcode |
21
|
|
|
*/ |
22
|
|
|
private $parser; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->barcodeGeneratorFactory = m::mock(BarcodeGeneratorFactory::class); |
|
|
|
|
27
|
|
|
parent::setUp(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return SimpleXMLElement |
32
|
|
|
*/ |
33
|
|
|
protected function getXmlField() |
34
|
|
|
{ |
35
|
|
|
return new SimpleXMLElement( |
36
|
|
|
'<Field Name="i am field name"> |
37
|
|
|
<FldType>Barcode</FldType> |
38
|
|
|
<CLSID>{7A4AA4CF-F5CD-11D4-8DAE-0050DAFE8A9F}</CLSID> |
39
|
|
|
<Inverse>1</Inverse> |
40
|
|
|
<X>4200</X> |
41
|
|
|
<Y>250</Y> |
42
|
|
|
<W>3775</W> |
43
|
|
|
<H>450</H> |
44
|
|
|
<Ln>1</Ln> |
45
|
|
|
<CalcData><![CDATA[0501234567890]]></CalcData> |
46
|
|
|
<Data> |
47
|
|
|
<Object> |
48
|
|
|
<DataType>5</DataType> |
49
|
|
|
<Default><![CDATA[30]]></Default> |
50
|
|
|
<SrcField SrcFieldName="merge_field_name"/> |
51
|
|
|
</Object> |
52
|
|
|
</Data> |
53
|
|
|
<Barcode> |
54
|
|
|
<BcH>450</BcH> |
55
|
|
|
<HR> |
56
|
|
|
<HRFont> |
57
|
|
|
<Family>DontCare</Family> |
58
|
|
|
<Pitch>33</Pitch> |
59
|
|
|
</HRFont> |
60
|
|
|
</HR> |
61
|
|
|
<CheckDigit>1</CheckDigit> |
62
|
|
|
<EAN13/> |
63
|
|
|
</Barcode> |
64
|
|
|
<Orientation>90</Orientation> |
65
|
|
|
</Field>' |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return FieldParserBarcode |
71
|
|
|
*/ |
72
|
|
|
protected function getParser() |
73
|
|
|
{ |
74
|
|
|
if (!$this->parser) { |
75
|
|
|
$this->parser = new FieldParserBarcode( |
76
|
|
|
$this->barcodeGeneratorFactory |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->parser; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetFontSize() |
84
|
|
|
{ |
85
|
|
|
$size = 33; |
86
|
|
|
$this->assertEquals($size, $this->getParser()->getFontSize()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGetOrientation() |
90
|
|
|
{ |
91
|
|
|
$orientation = 90; |
92
|
|
|
$this->assertEquals($orientation, $this->getParser()->getOrientation()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testGetText() |
96
|
|
|
{ |
97
|
|
|
$mergedText = 'i am erged text'; |
98
|
|
|
$barcodeText = 'i am barcode text'; |
99
|
|
|
|
100
|
|
|
$barcodeGenerator = m::mock(BarcodeGeneratorInterface::class) |
101
|
|
|
->shouldReceive('generate') |
|
|
|
|
102
|
|
|
->with($mergedText) |
103
|
|
|
->andReturn($barcodeText) |
104
|
|
|
->once() |
105
|
|
|
->getMock(); |
106
|
|
|
|
107
|
|
|
$this->barcodeGeneratorFactory |
108
|
|
|
->shouldReceive('getGenerator') |
|
|
|
|
109
|
|
|
->andReturn($barcodeGenerator) |
110
|
|
|
->once() |
111
|
|
|
->getMock(); |
112
|
|
|
|
113
|
|
|
// barcode is a merge field so text will be fetched from other parsers, mock them |
114
|
|
|
$parserMergeField = m::mock(FieldParserInterface::class) |
|
|
|
|
115
|
|
|
->shouldReceive('getText') |
116
|
|
|
->withNoArgs() |
117
|
|
|
->andReturn($mergedText) |
118
|
|
|
->once() |
119
|
|
|
->getMock(); |
120
|
|
|
|
121
|
|
|
$this->fieldParserRegistry |
122
|
|
|
->shouldReceive('getParser') |
|
|
|
|
123
|
|
|
->with('merge_field_name') |
124
|
|
|
->andReturn($parserMergeField) |
125
|
|
|
->once() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$this->assertEquals($barcodeText, $this->getParser()->getText()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testGetIsInverse() |
132
|
|
|
{ |
133
|
|
|
$isInverse = true; |
134
|
|
|
$this->assertEquals($isInverse, $this->getParser()->getIsInverse()); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..