Completed
Branch master (4d68bf)
by John
02:46
created

FieldParserFixedTextTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 7
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
     * @return SimpleXMLElement
14
     */
15
    private function getXmlField()
16
    {
17
        return new SimpleXMLElement(
18
            '<Field Name="i am field name">
19
                <FldType>MergeField</FldType>
20
                <X>4200</X>
21
                <Y>250</Y>
22
                <W>3775</W>
23
                <H>450</H>
24
                <Ln>1</Ln>
25
                <CalcData><![CDATA[8788888]]></CalcData>
26
                <Data>
27
                    <Object>
28
                        <DataType>5</DataType>
29
                        <Default><![CDATA[212]]></Default>
30
                        <SrcField SrcFieldName="i am source name 1"/>
31
                    </Object>
32
                    <Object Index="1">
33
                        <DataType>5</DataType>
34
                        <Default><![CDATA[1310]]></Default>
35
                        <SrcField SrcFieldName="i am source name 2"/>
36
                    </Object>
37
                </Data>
38
                <Text>
39
                    <Font>
40
                        <Face><![CDATA[i am font face]]></Face>
41
                        <Pitch>5</Pitch>
42
                    </Font>
43
                </Text>
44
                <Orientation>90</Orientation>
45
            </Field>'
46
        );
47
    }
48
49
    /**
50
     * @return FieldParserFixedText
51
     */
52
    protected function getParser()
53
    {
54
        if (!$this->parser) {
55
            $this->parser = new FieldParserFixedText(
56
                $this->fieldParserRegistry,
57
                $this->xmlHeader,
58
                $this->getXmlField(),
59
                $this->scale
60
            );
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