ODText Writer: Additional unit tests

This commit is contained in:
Ivan Lanin 2014-04-17 03:47:43 +07:00
parent 94e1661958
commit 306c354b2c
6 changed files with 115 additions and 4 deletions

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Element\ListItem;

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
/**

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/**
@ -28,8 +29,19 @@ class ContentTest extends \PHPUnit_Framework_TestCase
}
/**
* covers ::writeContent
* covers <private>
* Test construct with no PhpWord
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructNoPhpWord()
{
$object = new Content();
$object->writeContent();
}
/**
* Test write content
*/
public function testWriteContent()
{
@ -38,27 +50,59 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$expected = 'Expected';
$phpWord = new PhpWord();
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection();
$section->addText($expected);
$section->addText('Test font style', 'Font');
$section->addText('Test paragraph style', null, 'Paragraph');
$section->addTextBreak();
$section->addLink('http://test.com', 'Test link');
$section->addTitle('Test title', 1);
$section->addTextBreak();
$section->addPageBreak();
$section->addTable();
$section->addListItem('Test list item');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$textrun = $section->addTextRun();
$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');
$element = "/office:document-content/office:body/office:text/text:p";
$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'));
}
}

View 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();
}
}

View 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();
}
}