Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for SetGetDefaultFontColor #2

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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