Skip to content

Commit

Permalink
Word2007 Writer : Fixed StrikeThrough property
Browse files Browse the repository at this point in the history
  • Loading branch information
Noé authored and Progi1984 committed Aug 27, 2024
1 parent 39e806b commit c41921a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changes/1.x/1.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Word2007 Writer : Fix first footnote appearing as separator [#2634](https://github.com/PHPOffice/PHPWord/issues/2634) by [@jacksleight](https://github.com/jacksleight) in [#2635](https://github.com/PHPOffice/PHPWord/pull/2635)
- Template Processor : Fixed images with transparent backgrounds displaying a white background by [@ElwynVdb](https://github.com/ElwynVdb) in [#2638](https://github.com/PHPOffice/PHPWord/pull/2638)
- HTML Writer : Fixed rowspan for tables by [@andomiell](https://github.com/andomiell) in [#2659](https://github.com/PHPOffice/PHPWord/pull/2659)
- Word2007 Writer : Fixed StrikeThrough property by [@noec764](https://github.com/noec764) fixing [#1722](https://github.com/PHPOffice/PHPWord/issues/1722) & [#1693](https://github.com/PHPOffice/PHPWord/issues/1693) in [#2659](https://github.com/PHPOffice/PHPWord/pull/2659)

### Miscellaneous

Expand Down
12 changes: 6 additions & 6 deletions src/PhpWord/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ public function setSubScript($value = true)
/**
* Get strikethrough.
*
* @return bool
* @return bool|null
*/
public function isStrikethrough()
public function isStrikethrough(): ?bool
{
return $this->strikethrough;
}
Expand All @@ -580,17 +580,17 @@ public function isStrikethrough()
*
* @return self
*/
public function setStrikethrough($value = true)
public function setStrikethrough($value = true): self
{
return $this->setPairedVal($this->strikethrough, $this->doubleStrikethrough, $value);
}

/**
* Get double strikethrough.
*
* @return bool
* @return bool|null
*/
public function isDoubleStrikethrough()
public function isDoubleStrikethrough(): ?bool
{
return $this->doubleStrikethrough;
}
Expand All @@ -602,7 +602,7 @@ public function isDoubleStrikethrough()
*
* @return self
*/
public function setDoubleStrikethrough($value = true)
public function setDoubleStrikethrough($value = true): self
{
return $this->setPairedVal($this->doubleStrikethrough, $this->strikethrough, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Writer/Word2007/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private function writeStyle(): void
$xmlWriter->writeElementIf($style->isItalic() !== null, 'w:iCs', 'w:val', $this->writeOnOf($style->isItalic()));

// Strikethrough, double strikethrough
$xmlWriter->writeElementIf($style->isStrikethrough() !== null, 'w:strike', 'w:val', $this->writeOnOf($style->isStrikethrough()));
$xmlWriter->writeElementIf($style->isDoubleStrikethrough() !== null, 'w:dstrike', 'w:val', $this->writeOnOf($style->isDoubleStrikethrough()));
$xmlWriter->writeElementIf($style->isStrikethrough(), 'w:strike', 'w:val', $this->writeOnOf($style->isStrikethrough()));
$xmlWriter->writeElementIf($style->isDoubleStrikethrough(), 'w:dstrike', 'w:val', $this->writeOnOf($style->isDoubleStrikethrough()));

// Small caps, all caps
$xmlWriter->writeElementIf($style->isSmallCaps() !== null, 'w:smallCaps', 'w:val', $this->writeOnOf($style->isSmallCaps()));
Expand Down
36 changes: 36 additions & 0 deletions tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,48 @@ public function testWriteFontStyle(): void
self::assertTrue($doc->elementExists("{$parent}/w:i"));
self::assertEquals($styles['underline'], $doc->getElementAttribute("{$parent}/w:u", 'w:val'));
self::assertTrue($doc->elementExists("{$parent}/w:strike"));
self::assertFalse($doc->elementExists("{$parent}/w:dstrike"));
self::assertEquals('superscript', $doc->getElementAttribute("{$parent}/w:vertAlign", 'w:val'));
self::assertEquals($styles['color'], $doc->getElementAttribute("{$parent}/w:color", 'w:val'));
self::assertEquals($styles['fgColor'], $doc->getElementAttribute("{$parent}/w:highlight", 'w:val'));
self::assertTrue($doc->elementExists("{$parent}/w:smallCaps"));
}

/**
* covers ::_writeTextStyle.
*
* @dataProvider providerFontStyleStrikethrough
*/
public function testWriteFontStyleStrikethrough(
bool $isStrikethrough,
bool $isDoubleStrikethrough,
bool $expectedStrikethrough,
bool $expectedDoubleStrikethrough,
): void

Check failure on line 553 in tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.1.3

syntax error, unexpected ')', expecting variable (T_VARIABLE)
{
$phpWord = new PhpWord();
$styles['strikethrough'] = $isStrikethrough;
$styles['doublestrikethrough'] = $isDoubleStrikethrough;

$section = $phpWord->addSection();
$section->addText('Test', $styles);
$doc = TestHelperDOCX::getDocument($phpWord);

$parent = '/w:document/w:body/w:p/w:r/w:rPr';
self::assertSame($expectedStrikethrough,$doc->elementExists("{$parent}/w:strike"));
self::assertSame($expectedDoubleStrikethrough, $doc->elementExists("{$parent}/w:dstrike"));
}

public static function providerFontStyleStrikethrough(): iterable
{
return [
[true, true, false, true],
[true, false, true, false],
[false, true, false, true],
[false, false, false, false],
];
}

/**
* Tests that if no color is set on a cell a border gets writen with the default color.
*/
Expand Down

0 comments on commit c41921a

Please sign in to comment.