Type checks on style writers
This commit is contained in:
parent
9567c6a972
commit
17e2f02817
@ -35,6 +35,9 @@ class Font extends AbstractStyle
|
|||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$style = $this->getStyle();
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$css = array();
|
$css = array();
|
||||||
|
|
||||||
$font = $style->getName();
|
$font = $style->getName();
|
||||||
|
|||||||
@ -32,6 +32,9 @@ class Image extends AbstractStyle
|
|||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$style = $this->getStyle();
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$css = array();
|
$css = array();
|
||||||
|
|
||||||
$css['width'] = $this->getValueIf($style->getWidth(), $style->getWidth() . 'px');
|
$css['width'] = $this->getValueIf($style->getWidth(), $style->getWidth() . 'px');
|
||||||
|
|||||||
@ -34,6 +34,9 @@ class Paragraph extends AbstractStyle
|
|||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$style = $this->getStyle();
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$css = array();
|
$css = array();
|
||||||
|
|
||||||
// Alignment
|
// Alignment
|
||||||
|
|||||||
@ -34,7 +34,8 @@ class Font extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -34,7 +34,8 @@ class Paragraph extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -31,7 +31,8 @@ class Cell extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Cell) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -57,7 +57,8 @@ class Font extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
private function writeStyle()
|
private function writeStyle()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -38,9 +38,11 @@ class Image extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (!is_null($this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
$this->writeStyle();
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
$this->writeStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class Indentation extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -31,7 +31,8 @@ class LineNumbering extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\LineNumbering) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -29,14 +29,14 @@ class MarginBorder extends AbstractStyle
|
|||||||
*
|
*
|
||||||
* @var int[]
|
* @var int[]
|
||||||
*/
|
*/
|
||||||
private $sizes;
|
private $sizes = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colors
|
* Colors
|
||||||
*
|
*
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
private $colors;
|
private $colors = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other attributes
|
* Other attributes
|
||||||
|
|||||||
@ -66,7 +66,8 @@ class Paragraph extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
private function writeStyle()
|
private function writeStyle()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -31,7 +31,8 @@ class Section extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Section) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class Shading extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Shading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class Spacing extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Spacing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class Tab extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -36,7 +36,8 @@ class Table extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (is_null($style = $this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|||||||
@ -31,10 +31,12 @@ class TextBox extends Image
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
if (!is_null($this->getStyle())) {
|
$style = $this->getStyle();
|
||||||
$this->writeStyle();
|
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||||
$this->writeBorder();
|
return;
|
||||||
}
|
}
|
||||||
|
$this->writeStyle();
|
||||||
|
$this->writeBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
39
tests/PhpWord/Tests/Writer/HTML/StyleTest.php
Normal file
39
tests/PhpWord/Tests/Writer/HTML/StyleTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\HTML;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\HTML\Style subnamespace
|
||||||
|
*/
|
||||||
|
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test empty styles
|
||||||
|
*/
|
||||||
|
public function testEmptyStyles()
|
||||||
|
{
|
||||||
|
$styles = array('Font', 'Paragraph', 'Image');
|
||||||
|
foreach ($styles as $style) {
|
||||||
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Style\\' . $style;
|
||||||
|
$object = new $objectClass();
|
||||||
|
|
||||||
|
$this->assertEquals('', $object->write());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
tests/PhpWord/Tests/Writer/ODText/StyleTest.php
Normal file
41
tests/PhpWord/Tests/Writer/ODText/StyleTest.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Style subnamespace
|
||||||
|
*/
|
||||||
|
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test empty styles
|
||||||
|
*/
|
||||||
|
public function testEmptyStyles()
|
||||||
|
{
|
||||||
|
$styles = array('Font', 'Paragraph');
|
||||||
|
foreach ($styles as $style) {
|
||||||
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $style;
|
||||||
|
$xmlWriter = new XMLWriter();
|
||||||
|
$object = new $objectClass($xmlWriter);
|
||||||
|
$object->write();
|
||||||
|
|
||||||
|
$this->assertEquals('', $xmlWriter->getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
tests/PhpWord/Tests/Writer/RTF/StyleTest.php
Normal file
39
tests/PhpWord/Tests/Writer/RTF/StyleTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\RTF;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace
|
||||||
|
*/
|
||||||
|
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test empty styles
|
||||||
|
*/
|
||||||
|
public function testEmptyStyles()
|
||||||
|
{
|
||||||
|
$styles = array('Font', 'Paragraph');
|
||||||
|
foreach ($styles as $style) {
|
||||||
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Style\\' . $style;
|
||||||
|
$object = new $objectClass();
|
||||||
|
|
||||||
|
$this->assertEquals('', $object->write());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/PhpWord/Tests/Writer/Word2007/StyleTest.php
Normal file
44
tests/PhpWord/Tests/Writer/Word2007/StyleTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style subnamespace
|
||||||
|
*/
|
||||||
|
class StyleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test empty styles
|
||||||
|
*/
|
||||||
|
public function testEmptyStyles()
|
||||||
|
{
|
||||||
|
$styles = array(
|
||||||
|
'Cell', 'Font', 'Image', 'Indentation', 'LineNumbering',
|
||||||
|
'Paragraph', 'Section', 'Shading', 'Spacing', 'Tab', 'Table', 'TextBox'
|
||||||
|
);
|
||||||
|
foreach ($styles as $style) {
|
||||||
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\' . $style;
|
||||||
|
$xmlWriter = new XMLWriter();
|
||||||
|
$object = new $objectClass($xmlWriter);
|
||||||
|
$object->write();
|
||||||
|
|
||||||
|
$this->assertEquals('', $xmlWriter->getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user