Add unit tests & add array type checks

This commit is contained in:
troosan 2017-12-04 22:30:49 +01:00
parent ca25eba8aa
commit 274f50ce5a
6 changed files with 33 additions and 8 deletions

View File

@ -41,6 +41,9 @@ This is the last version to support PHP 5.3
- Fix incorrect image size between windows and mac - @bskrtich #874 - Fix incorrect image size between windows and mac - @bskrtich #874
- Fix adding HTML table to document - @mogilvie @arivanbastos #324 - Fix adding HTML table to document - @mogilvie @arivanbastos #324
###Deprecated
- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection();
v0.13.0 (31 July 2016) v0.13.0 (31 July 2016)
------------------- -------------------
This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default). This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default).

View File

@ -182,7 +182,7 @@ class Html
{ {
if ('li' != $node->nodeName) { if ('li' != $node->nodeName) {
$cNodes = $node->childNodes; $cNodes = $node->childNodes;
if (count($cNodes) > 0) { if (!empty($cNodes)) {
foreach ($cNodes as $cNode) { foreach ($cNodes as $cNode) {
if ($element instanceof AbstractContainer || $element instanceof Table || $element instanceof Row) { if ($element instanceof AbstractContainer || $element instanceof Table || $element instanceof Row) {
self::parseNode($cNode, $element, $styles, $data); self::parseNode($cNode, $element, $styles, $data);
@ -389,7 +389,7 @@ class Html
private static function parseListItem($node, $element, &$styles, $data) private static function parseListItem($node, $element, &$styles, $data)
{ {
$cNodes = $node->childNodes; $cNodes = $node->childNodes;
if (count($cNodes) > 0) { if (!empty($cNodes)) {
$text = ''; $text = '';
foreach ($cNodes as $cNode) { foreach ($cNodes as $cNode) {
if ($cNode->nodeName == '#text') { if ($cNode->nodeName == '#text') {

View File

@ -140,7 +140,8 @@ class ZipArchive
} else { } else {
$zip = new \PclZip($this->filename); $zip = new \PclZip($this->filename);
$this->tempDir = Settings::getTempDir(); $this->tempDir = Settings::getTempDir();
$this->numFiles = count($zip->listContent()); $zipContent = $zip->listContent();
$this->numFiles = is_array($zipContent) ? count($zipContent) : 0;
} }
$this->zip = $zip; $this->zip = $zip;

View File

@ -48,7 +48,7 @@ class Border extends AbstractStyle
$content = ''; $content = '';
$sides = array('top', 'left', 'right', 'bottom'); $sides = array('top', 'left', 'right', 'bottom');
$sizeCount = count($this->sizes) - 1; $sizeCount = count($this->sizes);
// Page border measure // Page border measure
// 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off

View File

@ -76,7 +76,7 @@ class Settings extends AbstractPart
{ {
if ($settingValue == '') { if ($settingValue == '') {
$xmlWriter->writeElement($settingKey); $xmlWriter->writeElement($settingKey);
} else { } elseif (is_array($settingValue) && !empty($settingValue)) {
$xmlWriter->startElement($settingKey); $xmlWriter->startElement($settingKey);
/** @var array $settingValue Type hint */ /** @var array $settingValue Type hint */
@ -154,7 +154,7 @@ class Settings extends AbstractPart
$this->setDocumentProtection($documentSettings->getDocumentProtection()); $this->setDocumentProtection($documentSettings->getDocumentProtection());
$this->setProofState($documentSettings->getProofState()); $this->setProofState($documentSettings->getProofState());
$this->setZoom($documentSettings->getZoom()); $this->setZoom($documentSettings->getZoom());
$this->getCompatibility(); $this->setCompatibility();
} }
/** /**
@ -216,6 +216,7 @@ class Settings extends AbstractPart
private function setRevisionView(TrackChangesView $trackChangesView = null) private function setRevisionView(TrackChangesView $trackChangesView = null)
{ {
if ($trackChangesView != null) { if ($trackChangesView != null) {
$revisionView = array();
$revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true' : 'false'; $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true' : 'false';
$revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true' : 'false'; $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true' : 'false';
$revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true' : 'false'; $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true' : 'false';
@ -259,7 +260,7 @@ class Settings extends AbstractPart
/** /**
* Get compatibility setting. * Get compatibility setting.
*/ */
private function getCompatibility() private function setCompatibility()
{ {
$compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility(); $compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility();
if ($compatibility->getOoxmlVersion() !== null) { if ($compatibility->getOoxmlVersion() !== null) {

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\RTF; namespace PhpOffice\PhpWord\Writer\RTF;
use PhpOffice\PhpWord\Writer\RTF\Style\Border;
/** /**
* Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace * Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace
*/ */
@ -35,4 +37,22 @@ class StyleTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('', $object->write()); $this->assertEquals('', $object->write());
} }
} }
public function testBorderWithNonRegisteredColors()
{
$border = new Border();
$border->setSizes(array(1, 2, 3, 4));
$border->setColors(array('#FF0000', '#FF0000', '#FF0000', '#FF0000'));
$border->setSizes(array(20, 20, 20, 20));
$content = $border->write();
$expected = '\pgbrdropt32';
$expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 ';
$expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 ';
$expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 ';
$expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 ';
$this->assertEquals($expected, $content);
}
} }