Skip to content

Commit

Permalink
add tests for SetGetDefaultFontColor
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPFrey committed Nov 22, 2024
1 parent 61c3375 commit 6c5f33e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/PhpWord/Reader/Word2007/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function read(PhpWord $phpWord): void
if (array_key_exists('size', $fontDefaultStyle)) {
$phpWord->setDefaultFontSize($fontDefaultStyle['size']);
}
if (array_key_exists('color', $fontDefaultStyle)) {
$phpWord->setDefaultFontColor($fontDefaultStyle['color']);
}
if (array_key_exists('lang', $fontDefaultStyle)) {
$phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang']));
}
Expand Down
12 changes: 12 additions & 0 deletions tests/PhpWordTests/PhpWordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public function testSetGetDefaultFontSize(): void
self::assertEquals($fontSize, $phpWord->getDefaultFontSize());
}

/**
* Test set/get default font color.
*/
public function testSetGetDefaultFontColor(): void
{
$phpWord = new PhpWord();
$fontColor = 'FF0000';
self::assertEquals(Settings::DEFAULT_FONT_COLOR, $phpWord->getDefaultFontColor());
$phpWord->setDefaultFontColor($fontColor);
self::assertEquals($fontColor, $phpWord->getDefaultFontColor());
}

/**
* Test set default paragraph style.
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpWordTests/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SettingsTest extends TestCase
protected function setUp(): void
{
$this->compatibility = Settings::hasCompatibility();
$this->defaultFontColor = Settings::getDefaultFontColor();
$this->defaultFontSize = Settings::getDefaultFontSize();
$this->defaultFontName = Settings::getDefaultFontName();
$this->defaultPaper = Settings::getDefaultPaper();
Expand All @@ -75,6 +76,7 @@ protected function setUp(): void
protected function tearDown(): void
{
Settings::setCompatibility($this->compatibility);
Settings::setDefaultFontColor($this->defaultFontColor);
Settings::setDefaultFontSize($this->defaultFontSize);
Settings::setDefaultFontName($this->defaultFontName);
Settings::setDefaultPaper($this->defaultPaper);
Expand Down Expand Up @@ -236,6 +238,20 @@ public function testSetGetDefaultFontSize(): void
self::assertEquals(12.5, Settings::getDefaultFontSize());
}

/**
* Test set/get default font color.
*/
public function testSetGetDefaultFontColor(): void
{
self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor());
self::assertFalse(Settings::setDefaultFontColor(' '));
self::assertEquals(Settings::DEFAULT_FONT_COLOR, Settings::getDefaultFontColor());
self::assertTrue(Settings::setDefaultFontColor('FF0000'));
self::assertEquals('FF0000', Settings::getDefaultFontColor());
self::assertFalse(Settings::setDefaultFontColor(' '));
self::assertEquals('FF0000', Settings::getDefaultFontColor());
}

/**
* Test set/get default paper.
*/
Expand Down

0 comments on commit 6c5f33e

Please sign in to comment.