|
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\Parser\FieldParser\FieldParserFixedText; |
|
8
|
|
|
use \SimpleXMLElement; |
|
9
|
|
|
|
|
10
|
|
|
class FieldParserFixedTextTest extends AbstractFieldParserTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var FieldParserFixedText |
|
14
|
|
|
*/ |
|
15
|
|
|
private $parser; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @return SimpleXMLElement |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function getXmlField() |
|
21
|
|
|
{ |
|
22
|
|
|
return new SimpleXMLElement( |
|
23
|
|
|
'<Field Name="i am field name"> |
|
24
|
|
|
<FldType>MergeField</FldType> |
|
25
|
|
|
<X>4200</X> |
|
26
|
|
|
<Y>250</Y> |
|
27
|
|
|
<W>3775</W> |
|
28
|
|
|
<H>450</H> |
|
29
|
|
|
<Ln>1</Ln> |
|
30
|
|
|
<CalcData><![CDATA[8788888]]></CalcData> |
|
31
|
|
|
<Data> |
|
32
|
|
|
<Object> |
|
33
|
|
|
<DataType>5</DataType> |
|
34
|
|
|
<Default><![CDATA[212]]></Default> |
|
35
|
|
|
<SrcField SrcFieldName="i am source name 1"/> |
|
36
|
|
|
</Object> |
|
37
|
|
|
<Object Index="1"> |
|
38
|
|
|
<DataType>5</DataType> |
|
39
|
|
|
<Default><![CDATA[1310]]></Default> |
|
40
|
|
|
<SrcField SrcFieldName="i am source name 2"/> |
|
41
|
|
|
</Object> |
|
42
|
|
|
</Data> |
|
43
|
|
|
<Text> |
|
44
|
|
|
<Font> |
|
45
|
|
|
<Face><![CDATA[i am font face]]></Face> |
|
46
|
|
|
<Pitch>5</Pitch> |
|
47
|
|
|
</Font> |
|
48
|
|
|
</Text> |
|
49
|
|
|
<Orientation>90</Orientation> |
|
50
|
|
|
</Field>' |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return FieldParserFixedText |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getParser() |
|
58
|
|
|
{ |
|
59
|
|
|
if (!$this->parser) { |
|
60
|
|
|
$this->parser = new FieldParserFixedText(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this->parser; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testGetFontSize() |
|
67
|
|
|
{ |
|
68
|
|
|
$expected = 21; // pitch * FieldParserFixedText::FONT_SIZE_MULTIPLIER |
|
69
|
|
|
$this->assertEquals($expected, $this->getParser()->getFontSize()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetFontFace() |
|
73
|
|
|
{ |
|
74
|
|
|
$face = 'i am font face'; |
|
75
|
|
|
$this->assertEquals($face, $this->getParser()->getFontFace()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testGetOrientation() |
|
79
|
|
|
{ |
|
80
|
|
|
$orientation = 90; |
|
81
|
|
|
$this->assertEquals($orientation, $this->getParser()->getOrientation()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testGetText() |
|
85
|
|
|
{ |
|
86
|
|
|
$fieldMergeSource1 = m::mock(FieldParserFixedText::class) |
|
87
|
|
|
->shouldReceive('getText') |
|
|
|
|
|
|
88
|
|
|
->andReturn('i am text 1 ') |
|
89
|
|
|
->once() |
|
90
|
|
|
->getMock(); |
|
91
|
|
|
$fieldMergeSource2 = m::mock(FieldParserFixedText::class) |
|
92
|
|
|
->shouldReceive('getText') |
|
93
|
|
|
->andReturn('and i am text 2') |
|
94
|
|
|
->once() |
|
95
|
|
|
->getMock(); |
|
96
|
|
|
|
|
97
|
|
|
$this->fieldParserRegistry |
|
98
|
|
|
->shouldReceive('getParser') |
|
|
|
|
|
|
99
|
|
|
->with('i am source name 1') |
|
100
|
|
|
->andReturn($fieldMergeSource1) |
|
101
|
|
|
->once() |
|
102
|
|
|
->shouldReceive('getParser') |
|
103
|
|
|
->with('i am source name 2') |
|
104
|
|
|
->andReturn($fieldMergeSource2) |
|
105
|
|
|
->once() |
|
106
|
|
|
->getMock(); |
|
107
|
|
|
|
|
108
|
|
|
$expected = 'i am text 1 and i am text 2'; |
|
109
|
|
|
$this->assertEquals($expected, $this->getParser()->getText()); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: