ODText Writer: Additional unit tests
This commit is contained in:
parent
94e1661958
commit
306c354b2c
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText;
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\Element\Image;
|
use PhpOffice\PhpWord\Element\Image;
|
||||||
use PhpOffice\PhpWord\Element\Link;
|
use PhpOffice\PhpWord\Element\Link;
|
||||||
use PhpOffice\PhpWord\Element\ListItem;
|
use PhpOffice\PhpWord\Element\ListItem;
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText;
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText;
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
use PhpOffice\PhpWord\Writer\ODText\Content;
|
||||||
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,8 +29,19 @@ class ContentTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* covers ::writeContent
|
* Test construct with no PhpWord
|
||||||
* covers <private>
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||||
|
* @expectedExceptionMessage No PhpWord assigned.
|
||||||
|
*/
|
||||||
|
public function testConstructNoPhpWord()
|
||||||
|
{
|
||||||
|
$object = new Content();
|
||||||
|
$object->writeContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test write content
|
||||||
*/
|
*/
|
||||||
public function testWriteContent()
|
public function testWriteContent()
|
||||||
{
|
{
|
||||||
@ -38,27 +50,59 @@ class ContentTest extends \PHPUnit_Framework_TestCase
|
|||||||
$expected = 'Expected';
|
$expected = 'Expected';
|
||||||
|
|
||||||
$phpWord = new PhpWord();
|
$phpWord = new PhpWord();
|
||||||
|
|
||||||
$phpWord->setDefaultFontName('Verdana');
|
$phpWord->setDefaultFontName('Verdana');
|
||||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||||
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText($expected);
|
$section->addText($expected);
|
||||||
$section->addText('Test font style', 'Font');
|
$section->addText('Test font style', 'Font');
|
||||||
$section->addText('Test paragraph style', null, 'Paragraph');
|
$section->addText('Test paragraph style', null, 'Paragraph');
|
||||||
$section->addTextBreak();
|
|
||||||
$section->addLink('http://test.com', 'Test link');
|
$section->addLink('http://test.com', 'Test link');
|
||||||
$section->addTitle('Test title', 1);
|
$section->addTitle('Test title', 1);
|
||||||
|
$section->addTextBreak();
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTable();
|
|
||||||
$section->addListItem('Test list item');
|
$section->addListItem('Test list item');
|
||||||
$section->addImage($imageSrc);
|
$section->addImage($imageSrc);
|
||||||
$section->addObject($objectSrc);
|
$section->addObject($objectSrc);
|
||||||
$section->addTOC();
|
$section->addTOC();
|
||||||
|
|
||||||
$textrun = $section->addTextRun();
|
$textrun = $section->addTextRun();
|
||||||
$textrun->addText('Test text run');
|
$textrun->addText('Test text run');
|
||||||
|
|
||||||
|
$table = $section->addTable();
|
||||||
|
$cell = $table->addRow()->addCell();
|
||||||
|
$cell = $table->addRow()->addCell();
|
||||||
|
$cell->addText('Test');
|
||||||
|
$cell->addLink('http://test.com', 'Test link');
|
||||||
|
$cell->addTextBreak();
|
||||||
|
$cell->addListItem('Test list item');
|
||||||
|
$cell->addImage($imageSrc);
|
||||||
|
$cell->addObject($objectSrc);
|
||||||
|
$textrun = $cell->addTextRun();
|
||||||
|
$textrun->addText('Test text run');
|
||||||
|
|
||||||
|
$footer = $section->addFooter();
|
||||||
|
$footer->addPreserveText('{PAGE}');
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
|
||||||
$element = "/office:document-content/office:body/office:text/text:p";
|
$element = "/office:document-content/office:body/office:text/text:p";
|
||||||
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
|
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test no paragraph style
|
||||||
|
*/
|
||||||
|
public function testWriteNoStyle()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||||
|
|
||||||
|
$element = "/office:document-content/office:automatic-styles/style:style";
|
||||||
|
$this->assertTrue($doc->elementExists($element, 'content.xml'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
tests/PhpWord/Tests/Writer/ODText/MetaTest.php
Normal file
32
tests/PhpWord/Tests/Writer/ODText/MetaTest.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Writer\ODText\Meta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Meta
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Meta
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class MetaTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test construct with no PhpWord
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||||
|
* @expectedExceptionMessage No PhpWord assigned.
|
||||||
|
*/
|
||||||
|
public function testConstructNoPhpWord()
|
||||||
|
{
|
||||||
|
$object = new Meta();
|
||||||
|
$object->writeMeta();
|
||||||
|
}
|
||||||
|
}
|
||||||
32
tests/PhpWord/Tests/Writer/ODText/StylesTest.php
Normal file
32
tests/PhpWord/Tests/Writer/ODText/StylesTest.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Writer\ODText\Styles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Styles
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Styles
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class StylesTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test construct with no PhpWord
|
||||||
|
*
|
||||||
|
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||||
|
* @expectedExceptionMessage No PhpWord assigned.
|
||||||
|
*/
|
||||||
|
public function testConstructNoPhpWord()
|
||||||
|
{
|
||||||
|
$object = new Styles();
|
||||||
|
$object->writeStyles();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user