Skip to content

Commit 274f50c

Browse files
committed
Add unit tests & add array type checks
1 parent ca25eba commit 274f50c

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This is the last version to support PHP 5.3
2626
### Fixed
2727
- Loosen dependency to Zend
2828
- Images are not being printed when generating PDF - @hubertinio #1074 #431
29-
- Fixed some PHP 7 warnings - @ likeuntomurphy #927
29+
- Fixed some PHP 7 warnings - @likeuntomurphy #927
3030
- Fixed Word 97 reader - @alsofronie @Benpxpx @mario-rivera #912 #920 #892
3131
- Fixed image loading over https - @troosan #988
3232
- Impossibility to set different even and odd page headers - @troosan #981
@@ -41,6 +41,9 @@ This is the last version to support PHP 5.3
4141
- Fix incorrect image size between windows and mac - @bskrtich #874
4242
- Fix adding HTML table to document - @mogilvie @arivanbastos #324
4343

44+
###Deprecated
45+
- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection();
46+
4447
v0.13.0 (31 July 2016)
4548
-------------------
4649
This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default).

src/PhpWord/Shared/Html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static function parseChildNodes($node, $element, $styles, $data)
182182
{
183183
if ('li' != $node->nodeName) {
184184
$cNodes = $node->childNodes;
185-
if (count($cNodes) > 0) {
185+
if (!empty($cNodes)) {
186186
foreach ($cNodes as $cNode) {
187187
if ($element instanceof AbstractContainer || $element instanceof Table || $element instanceof Row) {
188188
self::parseNode($cNode, $element, $styles, $data);
@@ -389,7 +389,7 @@ private static function parseList(&$styles, &$data, $argument1)
389389
private static function parseListItem($node, $element, &$styles, $data)
390390
{
391391
$cNodes = $node->childNodes;
392-
if (count($cNodes) > 0) {
392+
if (!empty($cNodes)) {
393393
$text = '';
394394
foreach ($cNodes as $cNode) {
395395
if ($cNode->nodeName == '#text') {

src/PhpWord/Shared/ZipArchive.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public function open($filename, $flags = null)
140140
} else {
141141
$zip = new \PclZip($this->filename);
142142
$this->tempDir = Settings::getTempDir();
143-
$this->numFiles = count($zip->listContent());
143+
$zipContent = $zip->listContent();
144+
$this->numFiles = is_array($zipContent) ? count($zipContent) : 0;
144145
}
145146
$this->zip = $zip;
146147

src/PhpWord/Writer/RTF/Style/Border.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function write()
4848
$content = '';
4949

5050
$sides = array('top', 'left', 'right', 'bottom');
51-
$sizeCount = count($this->sizes) - 1;
51+
$sizeCount = count($this->sizes);
5252

5353
// Page border measure
5454
// 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off

src/PhpWord/Writer/Word2007/Part/Settings.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function writeSetting($xmlWriter, $settingKey, $settingValue)
7676
{
7777
if ($settingValue == '') {
7878
$xmlWriter->writeElement($settingKey);
79-
} else {
79+
} elseif (is_array($settingValue) && !empty($settingValue)) {
8080
$xmlWriter->startElement($settingKey);
8181

8282
/** @var array $settingValue Type hint */
@@ -154,7 +154,7 @@ private function getSettings()
154154
$this->setDocumentProtection($documentSettings->getDocumentProtection());
155155
$this->setProofState($documentSettings->getProofState());
156156
$this->setZoom($documentSettings->getZoom());
157-
$this->getCompatibility();
157+
$this->setCompatibility();
158158
}
159159

160160
/**
@@ -216,6 +216,7 @@ private function setProofState(ProofState $proofState = null)
216216
private function setRevisionView(TrackChangesView $trackChangesView = null)
217217
{
218218
if ($trackChangesView != null) {
219+
$revisionView = array();
219220
$revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true' : 'false';
220221
$revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true' : 'false';
221222
$revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true' : 'false';
@@ -259,7 +260,7 @@ private function setZoom($zoom = null)
259260
/**
260261
* Get compatibility setting.
261262
*/
262-
private function getCompatibility()
263+
private function setCompatibility()
263264
{
264265
$compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility();
265266
if ($compatibility->getOoxmlVersion() !== null) {

tests/PhpWord/Writer/RTF/StyleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Writer\RTF;
1919

20+
use PhpOffice\PhpWord\Writer\RTF\Style\Border;
21+
2022
/**
2123
* Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace
2224
*/
@@ -35,4 +37,22 @@ public function testEmptyStyles()
3537
$this->assertEquals('', $object->write());
3638
}
3739
}
40+
41+
public function testBorderWithNonRegisteredColors()
42+
{
43+
$border = new Border();
44+
$border->setSizes(array(1, 2, 3, 4));
45+
$border->setColors(array('#FF0000', '#FF0000', '#FF0000', '#FF0000'));
46+
$border->setSizes(array(20, 20, 20, 20));
47+
48+
$content = $border->write();
49+
50+
$expected = '\pgbrdropt32';
51+
$expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 ';
52+
$expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 ';
53+
$expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 ';
54+
$expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 ';
55+
56+
$this->assertEquals($expected, $content);
57+
}
3858
}

0 commit comments

Comments
 (0)