Skip to content

Commit

Permalink
Merge pull request #2 from MichaelPFrey/fix-mfr-2024-11-22
Browse files Browse the repository at this point in the history
add tests for SetGetDefaultFontColor
  • Loading branch information
Collie-IT authored Nov 22, 2024
2 parents d44bd6f + 6c5f33e commit c2afe42
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();

Check failure on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor.

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated

Check warning on line 62 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Creation of dynamic property PhpOffice\PhpWordTests\SettingsTest::$defaultFontColor is deprecated
$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);

Check failure on line 79 in tests/PhpWordTests/SettingsTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property PhpOffice\PhpWordTests\SettingsTest::$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 c2afe42

Please sign in to comment.