Skip to content

Commit 7a42431

Browse files
committed
Unit tests enhancement
1 parent 2d178a6 commit 7a42431

27 files changed

+379
-187
lines changed

license.md renamed to LICENSE.md

File renamed without changes.

src/PhpWord/DocumentProperties.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,14 @@ public function getCustomPropertyType($propertyName)
436436
*/
437437
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
438438
{
439-
if (($propertyType === null) || (!in_array($propertyType, array(
439+
$propertyTypes = array(
440440
self::PROPERTY_TYPE_INTEGER,
441441
self::PROPERTY_TYPE_FLOAT,
442442
self::PROPERTY_TYPE_STRING,
443443
self::PROPERTY_TYPE_DATE,
444444
self::PROPERTY_TYPE_BOOLEAN
445-
)))) {
445+
);
446+
if (($propertyType === null) || (!in_array($propertyType, $propertyTypes))) {
446447
if ($propertyValue === null) {
447448
$propertyType = self::PROPERTY_TYPE_STRING;
448449
} elseif (is_float($propertyValue)) {

src/PhpWord/Footnote.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ class Footnote
3131
/**
3232
* Add new Footnote Element
3333
*
34-
* @param string $linkSrc
35-
* @param string $linkName
36-
*
37-
* @return mixed
34+
* @return int Reference ID
3835
*/
3936
public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
4037
{
@@ -70,7 +67,7 @@ public static function countFootnoteElements()
7067
*
7168
* @param string $linkSrc
7269
*
73-
* @return mixed
70+
* @return int Reference ID
7471
*/
7572
public static function addFootnoteLinkElement($linkSrc)
7673
{

src/PhpWord/Media.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ public static function addSectionMediaElement($src, $type, Image $image = null)
6969
$file = null;
7070
if ($type === 'image') {
7171
$cImg++;
72+
$isMemImage = false;
7273
if (!is_null($image)) {
7374
$isMemImage = $image->getIsMemImage();
7475
$extension = $image->getImageExtension();
75-
} else {
76-
$isMemImage = false;
7776
}
7877
if ($isMemImage) {
7978
$media['isMemImage'] = true;
@@ -181,11 +180,10 @@ public static function addHeaderMediaElement($headerCount, $src, Image $image =
181180
$rID = $cImg + 1;
182181
$cImg++;
183182
$media = array();
183+
$isMemImage = false;
184184
if (!is_null($image)) {
185185
$isMemImage = $image->getIsMemImage();
186186
$extension = $image->getImageExtension();
187-
} else {
188-
$isMemImage = false;
189187
}
190188
if ($isMemImage) {
191189
$media['isMemImage'] = true;
@@ -244,11 +242,10 @@ public static function addFooterMediaElement($footerCount, $src, Image $image =
244242
$cImg = self::countFooterMediaElements($key);
245243
$rID = $cImg + 1;
246244
$cImg++;
245+
$isMemImage = false;
247246
if (!is_null($image)) {
248247
$isMemImage = $image->getIsMemImage();
249248
$extension = $image->getImageExtension();
250-
} else {
251-
$isMemImage = false;
252249
}
253250
if ($isMemImage) {
254251
$media['isMemImage'] = true;

src/PhpWord/Section.php

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace PhpOffice\PhpWord;
1111

12-
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
1312
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
1413
use PhpOffice\PhpWord\Section\Footer;
1514
use PhpOffice\PhpWord\Section\Image;
@@ -211,72 +210,61 @@ public function addListItem($text, $depth = 0, $styleFont = null, $styleList = n
211210
/**
212211
* Add a OLE-Object Element
213212
*
213+
* All exceptions should be handled by PhpOffice\PhpWord\Section\Object
214+
*
214215
* @param string $src
215216
* @param mixed $style
216217
* @return \PhpOffice\PhpWord\Section\Object
217-
* @throws \PhpOffice\PhpWord\Exceptions\InvalidObjectException
218218
*/
219219
public function addObject($src, $style = null)
220220
{
221221
$object = new Object($src, $style);
222-
223222
if (!is_null($object->getSource())) {
224223
$inf = pathinfo($src);
225224
$ext = $inf['extension'];
226225
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
227226
$ext = substr($ext, 0, -1);
228227
}
229-
230-
$iconSrc = __DIR__ . '/_staticDocParts/';
231-
if (!\file_exists($iconSrc . '_' . $ext . '.png')) {
232-
$iconSrc = $iconSrc . '_default.png';
233-
} else {
234-
$iconSrc .= '_' . $ext . '.png';
235-
}
236-
237-
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image', new Image($iconSrc));
228+
$icon = __DIR__ . "/_staticDocParts/_{$ext}.png";
229+
$rIDimg = Media::addSectionMediaElement($icon, 'image', new Image($icon));
238230
$data = Media::addSectionMediaElement($src, 'oleObject');
239231
$rID = $data[0];
240232
$objectId = $data[1];
241-
242233
$object->setRelationId($rID);
243234
$object->setObjectId($objectId);
244235
$object->setImageRelationId($rIDimg);
245-
246236
$this->_elementCollection[] = $object;
247237
return $object;
248238
} else {
249-
throw new InvalidObjectException;
239+
throw new InvalidObjectException();
250240
}
251241
}
252242

253243
/**
254-
* Add a Image Element
244+
* Add image element
245+
*
246+
* All exceptions should be handled by PhpOffice\PhpWord\Section\Image
255247
*
256248
* @param string $src
257249
* @param mixed $style
258250
* @return \PhpOffice\PhpWord\Section\Image
259-
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
260251
*/
261252
public function addImage($src, $style = null)
262253
{
263254
$image = new Image($src, $style);
264-
if (!is_null($image->getSource())) {
265-
$rID = Media::addSectionMediaElement($src, 'image', $image);
266-
$image->setRelationId($rID);
267-
$this->_elementCollection[] = $image;
268-
return $image;
269-
} else {
270-
throw new InvalidImageException;
271-
}
255+
$rID = Media::addSectionMediaElement($src, 'image', $image);
256+
$image->setRelationId($rID);
257+
$this->_elementCollection[] = $image;
258+
return $image;
272259
}
273260

274261
/**
275-
* Add a by PHP created Image Element
262+
* Add memory image element
276263
*
277-
* @param string $link
278-
* @param mixed $style
279264
* @deprecated
265+
*
266+
* @param string $src
267+
* @param mixed $style
280268
*/
281269
public function addMemoryImage($src, $style = null)
282270
{

src/PhpWord/Section/Footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function addImage($src, $style = null)
131131
/**
132132
* Add a by PHP created Image Element
133133
*
134-
* @param string $link
134+
* @param string $src
135135
* @param mixed $style
136136
* @deprecated
137137
*/

src/PhpWord/Section/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function addImage($src, $style = null)
160160
/**
161161
* Add a by PHP created Image Element
162162
*
163-
* @param string $link
163+
* @param string $src
164164
* @param mixed $style
165165
* @deprecated
166166
*/

src/PhpWord/Section/Object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Object
5858
*/
5959
public function __construct($src, $style = null)
6060
{
61-
$_supportedObjectTypes = array('xls', 'doc', 'ppt');
61+
$_supportedObjectTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
6262
$inf = pathinfo($src);
6363

6464
if (\file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {

src/PhpWord/Section/Table/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function addImage($src, $style = null)
205205
/**
206206
* Add a by PHP created Image Element
207207
*
208-
* @param string $link
208+
* @param string $src
209209
* @param mixed $style
210210
* @deprecated
211211
*/

src/PhpWord/Shared/XMLWriter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
use PhpOffice\PhpWord\Settings;
1313

14+
// @codeCoverageIgnoreStart
1415
if (!defined('DATE_W3C')) {
1516
define('DATE_W3C', 'Y-m-d\TH:i:sP');
1617
}
18+
// @codeCoverageIgnoreEnd
1719

1820
/**
1921
* XMLWriter wrapper

0 commit comments

Comments
 (0)