forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextBoxTest.php
84 lines (74 loc) · 2.51 KB
/
TextBoxTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace PhpOffice\PhpWordTests\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\TextBox as TextBoxElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
use PhpOffice\PhpWord\Writer\Word2007\Element\TextBox;
use PHPUnit\Framework\TestCase;
class TextBoxTest extends TestCase
{
/**
* @dataProvider textBoxColorProvider
*/
public function testTextBoxGeneratesCorrectXml(
?string $bgColor,
?string $borderColor,
string $expectedFillColorAttribute,
string $expectedBorderColorAttribute
): void {
// Arrange
$xmlWriter = new XMLWriter();
$style = new TextBoxStyle();
if ($bgColor !== null) {
$style->setBgColor($bgColor);
}
if ($borderColor !== null) {
$style->setBorderColor($borderColor);
}
$textBoxElement = new TextBoxElement($style);
$textBox = new TextBox($xmlWriter, $textBoxElement);
// Act
$textBox->write();
$output = $xmlWriter->getData();
// Assert
self::assertStringContainsString($expectedFillColorAttribute, $output, 'Background color should be applied.');
self::assertStringContainsString($expectedBorderColorAttribute, $output, 'Border color should be applied correctly.');
}
/**
* Data provider for testing different combinations of background and border colors.
*/
public static function textBoxColorProvider(): array
{
return [
// Case 1: Background color set, border color set
'With both colors' => [
'#FF0000',
'#000000',
'fillcolor="#FF0000"',
'stroke color="#000000"',
],
// Case 2: Background color set, no border color
'With background only' => [
'#00FF00',
null,
'fillcolor="#00FF00"',
'stroked="f" strokecolor="white"',
],
// Case 3: No background color, border color set
'With border only' => [
null,
'#123456',
'filled="f"',
'stroke color="#123456"',
],
// Case 4: Neither background nor border color set
'Without any colors' => [
null,
null,
'filled="f"',
'stroked="f" strokecolor="white"',
],
];
}
}