forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into wordunimplemented2
- Loading branch information
Showing
5 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
tests/PhpWordTests/Writer/Word2007/Element/TextBoxTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"', | ||
], | ||
]; | ||
} | ||
} |