TextTest::testJsonSerializeWithTextAnchorValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\AVGItem;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem\AVGItem;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem\Text;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\AVGItemType;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\FontStyle;
11
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\FontWeight;
12
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\TextAnchor;
13
use PHPUnit\Framework\TestCase;
14
15
class TextTest extends TestCase
16
{
17
    public function testConstructorWithAllParameters(): void
18
    {
19
        $fill = '#ff0000';
20
        $fillOpacity = 80;
21
        $fillTransform = 'scale(1.2)';
22
        $fontFamily = 'Arial';
23
        $fontSize = 16;
24
        $fontStyle = FontStyle::ITALIC;
25
        $fontWeight = FontWeight::BOLD;
26
        $letterSpacing = 2;
27
        $stroke = '#0000ff';
28
        $strokeOpacity = 90;
29
        $strokeTransform = 'rotate(10)';
30
        $strokeWidth = 1;
31
        $text = 'Hello World';
32
        $textAnchor = TextAnchor::MIDDLE;
33
        $x = 100;
34
        $y = 200;
35
36
        $textItem = new Text(
37
            $fill,
38
            $fillOpacity,
39
            $fillTransform,
40
            $fontFamily,
41
            $fontSize,
42
            $fontStyle,
43
            $fontWeight,
44
            $letterSpacing,
45
            $stroke,
46
            $strokeOpacity,
47
            $strokeTransform,
48
            $strokeWidth,
49
            $text,
50
            $textAnchor,
51
            $x,
52
            $y
53
        );
54
55
        $this->assertSame($fill, $textItem->fill);
56
        $this->assertSame($fillOpacity, $textItem->fillOpacity);
57
        $this->assertSame($fillTransform, $textItem->fillTransform);
58
        $this->assertSame($fontFamily, $textItem->fontFamily);
59
        $this->assertSame($fontSize, $textItem->fontSize);
60
        $this->assertSame($fontStyle, $textItem->fontStyle);
61
        $this->assertSame($fontWeight, $textItem->fontWeight);
62
        $this->assertSame($letterSpacing, $textItem->letterSpacing);
63
        $this->assertSame($stroke, $textItem->stroke);
64
        $this->assertSame($strokeOpacity, $textItem->strokeOpacity);
65
        $this->assertSame($strokeTransform, $textItem->strokeTransform);
66
        $this->assertSame($strokeWidth, $textItem->strokeWidth);
67
        $this->assertSame($text, $textItem->text);
68
        $this->assertSame($textAnchor, $textItem->textAnchor);
69
        $this->assertSame($x, $textItem->x);
70
        $this->assertSame($y, $textItem->y);
71
    }
72
73
    public function testConstructorWithDefaultParameters(): void
74
    {
75
        $textItem = new Text();
76
77
        $this->assertNull($textItem->fill);
78
        $this->assertNull($textItem->fillOpacity);
79
        $this->assertNull($textItem->fillTransform);
80
        $this->assertNull($textItem->fontFamily);
81
        $this->assertNull($textItem->fontSize);
82
        $this->assertNull($textItem->fontStyle);
83
        $this->assertNull($textItem->fontWeight);
84
        $this->assertNull($textItem->letterSpacing);
85
        $this->assertNull($textItem->stroke);
86
        $this->assertNull($textItem->strokeOpacity);
87
        $this->assertNull($textItem->strokeTransform);
88
        $this->assertNull($textItem->strokeWidth);
89
        $this->assertNull($textItem->text);
90
        $this->assertNull($textItem->textAnchor);
91
        $this->assertNull($textItem->x);
92
        $this->assertNull($textItem->y);
93
    }
94
95
    public function testJsonSerializeWithAllProperties(): void
96
    {
97
        $textItem = new Text(
98
            fill: '#green',
99
            fillOpacity: 75,
100
            fillTransform: 'translate(10, 20)',
101
            fontFamily: 'Helvetica',
102
            fontSize: 18,
103
            fontStyle: FontStyle::NORMAL,
104
            fontWeight: FontWeight::W100,
105
            letterSpacing: 1,
106
            stroke: '#purple',
107
            strokeOpacity: 85,
108
            strokeTransform: 'skewY(15)',
109
            strokeWidth: 2,
110
            text: 'Sample Text',
111
            textAnchor: TextAnchor::END,
112
            x: 50,
113
            y: 75
114
        );
115
116
        $result = $textItem->jsonSerialize();
117
118
        $this->assertSame(AVGItemType::TEXT->value, $result['type']);
119
        $this->assertSame('#green', $result['fill']);
120
        $this->assertSame(75, $result['fillOpacity']);
121
        $this->assertSame('translate(10, 20)', $result['fillTransform']);
122
        $this->assertSame('Helvetica', $result['fontFamily']);
123
        $this->assertSame(18, $result['fontSize']);
124
        $this->assertSame(FontStyle::NORMAL->value, $result['fontStyle']);
125
        $this->assertSame(FontWeight::W100->value, $result['fontWeight']);
126
        $this->assertSame(1, $result['letterSpacing']);
127
        $this->assertSame('#purple', $result['stroke']);
128
        $this->assertSame(85, $result['strokeOpacity']);
129
        $this->assertSame('skewY(15)', $result['strokeTransform']);
130
        $this->assertSame(2, $result['strokeWidth']);
131
        $this->assertSame('Sample Text', $result['text']);
132
        $this->assertSame(TextAnchor::END->value, $result['textAnchor']);
133
        $this->assertSame(50, $result['x']);
134
        $this->assertSame(75, $result['y']);
135
    }
136
137
    public function testJsonSerializeWithNullValues(): void
138
    {
139
        $textItem = new Text();
140
        $result = $textItem->jsonSerialize();
141
142
        $this->assertSame(AVGItemType::TEXT->value, $result['type']);
143
        $this->assertArrayNotHasKey('fill', $result);
144
        $this->assertArrayNotHasKey('fillOpacity', $result);
145
        $this->assertArrayNotHasKey('fillTransform', $result);
146
        $this->assertArrayNotHasKey('fontFamily', $result);
147
        $this->assertArrayNotHasKey('fontSize', $result);
148
        $this->assertArrayNotHasKey('fontStyle', $result);
149
        $this->assertArrayNotHasKey('fontWeight', $result);
150
        $this->assertArrayNotHasKey('letterSpacing', $result);
151
        $this->assertArrayNotHasKey('stroke', $result);
152
        $this->assertArrayNotHasKey('strokeOpacity', $result);
153
        $this->assertArrayNotHasKey('strokeTransform', $result);
154
        $this->assertArrayNotHasKey('strokeWidth', $result);
155
        $this->assertArrayNotHasKey('text', $result);
156
        $this->assertArrayNotHasKey('textAnchor', $result);
157
        $this->assertArrayNotHasKey('x', $result);
158
        $this->assertArrayNotHasKey('y', $result);
159
    }
160
161
    public function testJsonSerializeWithFontStyleValues(): void
162
    {
163
        $fontStyles = [FontStyle::NORMAL, FontStyle::ITALIC];
164
165
        foreach ($fontStyles as $fontStyle) {
166
            $textItem = new Text(fontStyle: $fontStyle);
167
            $result = $textItem->jsonSerialize();
168
169
            $this->assertSame($fontStyle->value, $result['fontStyle']);
170
        }
171
    }
172
173
    public function testJsonSerializeWithFontWeightValues(): void
174
    {
175
        $fontWeights = [FontWeight::W100, FontWeight::NORMAL, FontWeight::BOLD];
176
177
        foreach ($fontWeights as $fontWeight) {
178
            $textItem = new Text(fontWeight: $fontWeight);
179
            $result = $textItem->jsonSerialize();
180
181
            $this->assertSame($fontWeight->value, $result['fontWeight']);
182
        }
183
    }
184
185
    public function testJsonSerializeWithTextAnchorValues(): void
186
    {
187
        $textAnchors = [TextAnchor::START, TextAnchor::MIDDLE, TextAnchor::END];
188
189
        foreach ($textAnchors as $textAnchor) {
190
            $textItem = new Text(textAnchor: $textAnchor);
191
            $result = $textItem->jsonSerialize();
192
193
            $this->assertSame($textAnchor->value, $result['textAnchor']);
194
        }
195
    }
196
197
    public function testJsonSerializeWithZeroValues(): void
198
    {
199
        $textItem = new Text(
200
            fillOpacity: 0,
201
            fontSize: 0,
202
            letterSpacing: 0,
203
            strokeOpacity: 0,
204
            strokeWidth: 0,
205
            x: 0,
206
            y: 0
207
        );
208
        $result = $textItem->jsonSerialize();
209
210
        $this->assertSame(0, $result['fillOpacity']);
211
        $this->assertSame(0, $result['fontSize']);
212
        $this->assertSame(0, $result['letterSpacing']);
213
        $this->assertSame(0, $result['strokeOpacity']);
214
        $this->assertSame(0, $result['strokeWidth']);
215
        $this->assertSame(0, $result['x']);
216
        $this->assertSame(0, $result['y']);
217
    }
218
219
    public function testJsonSerializeWithNegativeCoordinates(): void
220
    {
221
        $textItem = new Text(x: -10, y: -20);
222
        $result = $textItem->jsonSerialize();
223
224
        $this->assertSame(-10, $result['x']);
225
        $this->assertSame(-20, $result['y']);
226
    }
227
228
    public function testJsonSerializeWithPartialProperties(): void
229
    {
230
        $textItem = new Text(
231
            fontFamily: 'Times New Roman',
232
            text: 'Partial Text',
233
            textAnchor: TextAnchor::START
234
        );
235
        $result = $textItem->jsonSerialize();
236
237
        $this->assertSame(AVGItemType::TEXT->value, $result['type']);
238
        $this->assertSame('Times New Roman', $result['fontFamily']);
239
        $this->assertSame('Partial Text', $result['text']);
240
        $this->assertSame(TextAnchor::START->value, $result['textAnchor']);
241
        $this->assertArrayNotHasKey('fill', $result);
242
        $this->assertArrayNotHasKey('fontSize', $result);
243
        $this->assertArrayNotHasKey('x', $result);
244
        $this->assertArrayNotHasKey('y', $result);
245
    }
246
247
    public function testTypeConstant(): void
248
    {
249
        $this->assertSame(AVGItemType::TEXT, Text::TYPE);
250
    }
251
252
    public function testExtendsAVGItem(): void
253
    {
254
        $textItem = new Text();
255
256
        $this->assertInstanceOf(AVGItem::class, $textItem);
257
    }
258
259
    public function testImplementsJsonSerializable(): void
260
    {
261
        $textItem = new Text();
262
263
        $this->assertInstanceOf(\JsonSerializable::class, $textItem);
264
    }
265
}
266