Coveralls Changes
Changes to improve test coverage based on Coveralls report.
This commit is contained in:
parent
46c41c5ac1
commit
d5149b2867
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLWriter;
|
use PhpOffice\Common\XMLWriter;
|
||||||
use PhpOffice\PhpWord\Element\AbstractContainer;
|
use PhpOffice\PhpWord\Element\AbstractContainer;
|
||||||
|
use PhpOffice\PhpWord\Element\Field;
|
||||||
use PhpOffice\PhpWord\Element\Image;
|
use PhpOffice\PhpWord\Element\Image;
|
||||||
use PhpOffice\PhpWord\Element\Table;
|
use PhpOffice\PhpWord\Element\Table;
|
||||||
use PhpOffice\PhpWord\Element\Text;
|
use PhpOffice\PhpWord\Element\Text;
|
||||||
|
|
@ -270,6 +271,8 @@ class Content extends AbstractPart
|
||||||
$this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
|
$this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
|
||||||
} elseif ($element instanceof Text) {
|
} elseif ($element instanceof Text) {
|
||||||
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
||||||
|
} elseif ($element instanceof Field) {
|
||||||
|
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
||||||
} elseif ($element instanceof Image) {
|
} elseif ($element instanceof Image) {
|
||||||
$style = $element->getStyle();
|
$style = $element->getStyle();
|
||||||
$style->setStyleName('fr' . $element->getMediaIndex());
|
$style->setStyleName('fr' . $element->getMediaIndex());
|
||||||
|
|
@ -298,14 +301,18 @@ class Content extends AbstractPart
|
||||||
/**
|
/**
|
||||||
* Get style of individual element
|
* Get style of individual element
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\Element\Text $element
|
* @param \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\Field $element
|
||||||
* @param int $paragraphStyleCount
|
* @param int $paragraphStyleCount
|
||||||
* @param int $fontStyleCount
|
* @param int $fontStyleCount
|
||||||
*/
|
*/
|
||||||
private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount)
|
private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount)
|
||||||
{
|
{
|
||||||
$fontStyle = $element->getFontStyle();
|
$fontStyle = $element->getFontStyle();
|
||||||
$paragraphStyle = $element->getParagraphStyle();
|
if (method_exists($element, 'getParagraphStyle')) {
|
||||||
|
$paragraphStyle = $element->getParagraphStyle();
|
||||||
|
} else {
|
||||||
|
$paragraphStyle = null;
|
||||||
|
}
|
||||||
$phpWord = $this->getParentWriter()->getPhpWord();
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
||||||
|
|
||||||
if ($fontStyle instanceof Font) {
|
if ($fontStyle instanceof Font) {
|
||||||
|
|
@ -332,7 +339,7 @@ class Content extends AbstractPart
|
||||||
} else {
|
} else {
|
||||||
$element->setParagraphStyle($name);
|
$element->setParagraphStyle($name);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($paragraphStyle) {
|
||||||
$paragraphStyleCount++;
|
$paragraphStyleCount++;
|
||||||
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
||||||
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
||||||
|
|
@ -347,7 +354,7 @@ class Content extends AbstractPart
|
||||||
* @param \PhpOffice\PhpWord\Element\TextRun $element
|
* @param \PhpOffice\PhpWord\Element\TextRun $element
|
||||||
* @param int $paragraphStyleCount
|
* @param int $paragraphStyleCount
|
||||||
*/
|
*/
|
||||||
private function getElementStyleTextRun(&$element, &$paragraphStyleCount)
|
private function getElementStyleTextRun($element, &$paragraphStyleCount)
|
||||||
{
|
{
|
||||||
$paragraphStyle = $element->getParagraphStyle();
|
$paragraphStyle = $element->getParagraphStyle();
|
||||||
$phpWord = $this->getParentWriter()->getPhpWord();
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
||||||
|
|
@ -363,7 +370,7 @@ class Content extends AbstractPart
|
||||||
} else {
|
} else {
|
||||||
$element->setParagraphStyle($name);
|
$element->setParagraphStyle($name);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($paragraphStyle) {
|
||||||
$paragraphStyleCount++;
|
$paragraphStyleCount++;
|
||||||
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
||||||
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
||||||
|
|
|
||||||
|
|
@ -135,5 +135,8 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertEquals(120, Converter::cssToPoint('10pc'));
|
$this->assertEquals(120, Converter::cssToPoint('10pc'));
|
||||||
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001);
|
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001);
|
||||||
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001);
|
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001);
|
||||||
|
$this->assertEquals(40, Converter::cssToPixel('30pt'));
|
||||||
|
$this->assertEquals(1.27, Converter::cssToCm('36pt'));
|
||||||
|
$this->assertEquals(127000, Converter::cssToEmu('10pt'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,9 @@ use PhpOffice\PhpWord\Style\Image;
|
||||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Element\Image
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Frame
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Element\Image
|
||||||
* @runTestsInSeparateProcesses
|
|
||||||
*/
|
*/
|
||||||
class ImageTest extends \PHPUnit\Framework\TestCase
|
class ImageTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testUnmatchedElements()
|
public function testUnmatchedElements()
|
||||||
{
|
{
|
||||||
$elements = array('Image', 'Link', 'Table', 'Text', 'Title');
|
$elements = array('Image', 'Link', 'Table', 'Text', 'Title', 'Field');
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element;
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element;
|
||||||
$xmlWriter = new XMLWriter();
|
$xmlWriter = new XMLWriter();
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ use PhpOffice\PhpWord\Writer\ODText;
|
||||||
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart
|
||||||
* @runTestsInSeparateProcesses
|
|
||||||
*/
|
*/
|
||||||
class AbstractPartTest extends \PHPUnit\Framework\TestCase
|
class AbstractPartTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Content
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Content
|
||||||
* @runTestsInSeparateProcesses
|
|
||||||
*/
|
*/
|
||||||
class ContentTest extends \PHPUnit\Framework\TestCase
|
class ContentTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText\Style;
|
namespace PhpOffice\PhpWord\Writer\ODText\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,6 +74,61 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertEquals('This should be dark green (FGCOLOR_DARKGREEN)', $doc->getElement($span)->nodeValue);
|
$this->assertEquals('This should be dark green (FGCOLOR_DARKGREEN)', $doc->getElement($span)->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function providerAllNamedColors()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(Font::FGCOLOR_YELLOW, 'FFFF00'),
|
||||||
|
array(Font::FGCOLOR_LIGHTGREEN, '90EE90'),
|
||||||
|
array(Font::FGCOLOR_CYAN, '00FFFF'),
|
||||||
|
array(Font::FGCOLOR_MAGENTA, 'FF00FF'),
|
||||||
|
array(Font::FGCOLOR_BLUE, '0000FF'),
|
||||||
|
array(Font::FGCOLOR_RED, 'FF0000'),
|
||||||
|
array(Font::FGCOLOR_DARKBLUE, '00008B'),
|
||||||
|
array(Font::FGCOLOR_DARKCYAN, '008B8B'),
|
||||||
|
array(Font::FGCOLOR_DARKGREEN, '006400'),
|
||||||
|
array(Font::FGCOLOR_DARKMAGENTA, '8B008B'),
|
||||||
|
array(Font::FGCOLOR_DARKRED, '8B0000'),
|
||||||
|
array(Font::FGCOLOR_DARKYELLOW, '8B8B00'),
|
||||||
|
array(Font::FGCOLOR_DARKGRAY, 'A9A9A9'),
|
||||||
|
array(Font::FGCOLOR_LIGHTGRAY, 'D3D3D3'),
|
||||||
|
array(Font::FGCOLOR_BLACK, '000000'),
|
||||||
|
array('unknow', 'unknow'),
|
||||||
|
array('unknown', 'unknown'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerAllNamedColors
|
||||||
|
*
|
||||||
|
* @param string $namedColor
|
||||||
|
* @param string $rgbColor
|
||||||
|
*/
|
||||||
|
public function testAllNamedColors($namedColor, $rgbColor)
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addText('This is red (800) in rtf/html, default in docx/odt', array('color' => '800'));
|
||||||
|
$section->addText('This should be cyanish (008787)', array('color' => '008787'));
|
||||||
|
$section->addText($namedColor, array('color' => $namedColor));
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
$s2a = '/office:document-content/office:automatic-styles';
|
||||||
|
$this->assertTrue($doc->elementExists($s2a));
|
||||||
|
$s2t = '/office:document-content/office:body/office:text/text:section';
|
||||||
|
$this->assertTrue($doc->elementExists($s2t));
|
||||||
|
|
||||||
|
$element = "$s2a/style:style[7]";
|
||||||
|
$this->assertTrue($doc->elementExists($element));
|
||||||
|
$style = $doc->getElementAttribute($element, 'style:name');
|
||||||
|
$element .= '/style:text-properties';
|
||||||
|
$this->assertTrue($doc->elementExists($element));
|
||||||
|
$this->assertEquals("#$rgbColor", $doc->getElementAttribute($element, 'fo:color'));
|
||||||
|
$span = "$s2t/text:p[4]/text:span";
|
||||||
|
$this->assertTrue($doc->elementExists($span));
|
||||||
|
$this->assertEquals($style, $doc->getElementAttribute($span, 'text:style-name'));
|
||||||
|
$this->assertEquals($namedColor, $doc->getElement($span)->nodeValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test noproof
|
* Test noproof
|
||||||
*/
|
*/
|
||||||
|
|
@ -128,4 +184,64 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertEquals($style, $doc->getElementAttribute($span, 'text:style-name'));
|
$this->assertEquals($style, $doc->getElementAttribute($span, 'text:style-name'));
|
||||||
$this->assertEquals('Noproof is false', $doc->getElement($span)->nodeValue);
|
$this->assertEquals('Noproof is false', $doc->getElement($span)->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test using object with a name as font style for addText
|
||||||
|
*/
|
||||||
|
public function testNamedStyleAsObject()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$named = $phpWord->addFontStyle('namedobject', array('color' => '008787'));
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addText('Let us see what color we wind up with', $named);
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
$s2t = '/office:document-content/office:body/office:text/text:section';
|
||||||
|
$this->assertTrue($doc->elementExists($s2t));
|
||||||
|
$element = "$s2t/text:p[2]/text:span";
|
||||||
|
$this->assertTrue($doc->elementExists($element));
|
||||||
|
$this->assertEquals('namedobject', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test supplying field font style as array or object or string
|
||||||
|
*/
|
||||||
|
public function testFieldStyles()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addFontStyle('namedstyle', array('color' => '800000'));
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$fld = $textrun->addField('DATE');
|
||||||
|
$fld->setFontStyle('namedstyle');
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$fld = $textrun->addField('DATE');
|
||||||
|
$fld->setFontStyle(array('color' => '008000'));
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$fld = $textrun->addField('DATE');
|
||||||
|
$font = new \PhpOffice\PhpWord\Style\Font();
|
||||||
|
$font->setColor('000080');
|
||||||
|
$fld->setFontStyle($font);
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
$s2a = '/office:document-content/office:automatic-styles';
|
||||||
|
$s2t = '/office:document-content/office:body/office:text/text:section';
|
||||||
|
|
||||||
|
$element = "$s2a/style:style[5]";
|
||||||
|
$this->assertEquals('T1', $doc->getElementAttribute($element, 'style:name'));
|
||||||
|
$this->assertEquals('#008000', $doc->getElementAttribute("$element/style:text-properties", 'fo:color'));
|
||||||
|
$element = "$s2a/style:style[7]";
|
||||||
|
$this->assertEquals('T2', $doc->getElementAttribute($element, 'style:name'));
|
||||||
|
$this->assertEquals('#000080', $doc->getElementAttribute("$element/style:text-properties", 'fo:color'));
|
||||||
|
|
||||||
|
$element = "$s2t/text:p[2]/text:span";
|
||||||
|
$this->assertEquals('namedstyle', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertTrue($doc->elementExists("$element/text:date"));
|
||||||
|
$element = "$s2t/text:p[3]/text:span";
|
||||||
|
$this->assertEquals('T1', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertTrue($doc->elementExists("$element/text:date"));
|
||||||
|
$element = "$s2t/text:p[4]/text:span";
|
||||||
|
$this->assertEquals('T2', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertTrue($doc->elementExists("$element/text:date"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -431,4 +431,35 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
|
||||||
$element = "$s2a/text:p[3]";
|
$element = "$s2a/text:p[3]";
|
||||||
$this->assertEquals('P4', $doc->getElementAttribute($element, 'text:style-name'));
|
$this->assertEquals('P4', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Empty font and paragraph styles
|
||||||
|
*/
|
||||||
|
public function testEmptyFontAndParagraphStyles()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$phpWord->addFontStyle('namedfont', array('name' => 'Courier New', 'size' => 8));
|
||||||
|
$phpWord->addParagraphStyle('namedpar', array('lineHeight' => 1.08));
|
||||||
|
$section->addText('Empty Font Style and Empty Paragraph Style', '', '');
|
||||||
|
$section->addText('Named Font Style and Empty Paragraph Style', 'namedfont', '');
|
||||||
|
$section->addText('Empty Font Style and Named Paragraph Style', '', 'namedpar');
|
||||||
|
$section->addText('Named Font Style and Named Paragraph Style', 'namedfont', 'namedpar');
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
$s2a = '/office:document-content/office:body/office:text/text:section';
|
||||||
|
$element = "$s2a/text:p[2]";
|
||||||
|
$this->assertEquals('Normal', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertEquals(5, $doc->getElementAttribute("$element/text:s", 'text:c'));
|
||||||
|
$this->assertFalse($doc->elementExists("$element/text:span"));
|
||||||
|
$element = "$s2a/text:p[3]";
|
||||||
|
$this->assertEquals('Normal', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertEquals('namedfont', $doc->getElementAttribute("$element/text:span", 'text:style-name'));
|
||||||
|
$element = "$s2a/text:p[4]";
|
||||||
|
$this->assertEquals('P1_namedpar', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertFalse($doc->elementExists("$element/text:span"));
|
||||||
|
$element = "$s2a/text:p[5]";
|
||||||
|
$this->assertEquals('P2_namedpar', $doc->getElementAttribute($element, 'text:style-name'));
|
||||||
|
$this->assertEquals('namedfont', $doc->getElementAttribute("$element/text:span", 'text:style-name'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue