Merge pull request #131 from ivanlanin/develop
More unit tests for Template and Writer
This commit is contained in:
commit
db1ce96233
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPWord_Reader_Abstract
|
* PHPWord_Reader_Abstract
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore Abstract class
|
||||||
*/
|
*/
|
||||||
abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
|
abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
|
||||||
{
|
{
|
||||||
|
|||||||
@ -174,6 +174,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
|
|||||||
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
|
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
if ($objZip->close() === false) {
|
if ($objZip->close() === false) {
|
||||||
|
|||||||
@ -101,6 +101,7 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
|
|||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
namespace PHPWord\Tests;
|
namespace PHPWord\Tests;
|
||||||
|
|
||||||
use PHPWord_Template;
|
use PHPWord_Template;
|
||||||
|
use PHPWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass PHPWord_Template
|
* @coversDefaultClass PHPWord_Template
|
||||||
@ -143,4 +144,32 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
@$template->applyXslStyleSheet($xslDOMDocument);
|
@$template->applyXslStyleSheet($xslDOMDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setValue
|
||||||
|
* @covers ::getVariables
|
||||||
|
* @covers ::cloneRow
|
||||||
|
* @covers ::saveAs
|
||||||
|
*/
|
||||||
|
public function testCloneRow()
|
||||||
|
{
|
||||||
|
$template = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx')
|
||||||
|
);
|
||||||
|
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
|
||||||
|
$docName = 'clone-test-result.docx';
|
||||||
|
|
||||||
|
$PHPWord = new PHPWord();
|
||||||
|
$document = $PHPWord->loadTemplate($template);
|
||||||
|
$actualVar = $document->getVariables();
|
||||||
|
$document->cloneRow('userId', 1);
|
||||||
|
$document->setValue('userId#1', 'Test');
|
||||||
|
$document->saveAs($docName);
|
||||||
|
$docFound = file_exists($docName);
|
||||||
|
unlink($docName);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedVar, $actualVar);
|
||||||
|
$this->assertTrue($docFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use PHPWord;
|
|||||||
* Class ODTextTest
|
* Class ODTextTest
|
||||||
*
|
*
|
||||||
* @package PHPWord\Tests
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_ODText
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class ODTextTest extends \PHPUnit_Framework_TestCase
|
class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||||
@ -37,8 +38,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test construct with null value/without PHPWord
|
* @covers ::getPHPWord
|
||||||
*
|
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionMessage No PHPWord assigned.
|
* @expectedExceptionMessage No PHPWord assigned.
|
||||||
*/
|
*/
|
||||||
@ -49,39 +49,106 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test save()
|
* @covers ::save
|
||||||
*/
|
*/
|
||||||
public function testSave()
|
public function testSave()
|
||||||
{
|
{
|
||||||
|
$imageSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
|
||||||
|
);
|
||||||
|
$objectSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
||||||
|
);
|
||||||
|
$file = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt')
|
||||||
|
);
|
||||||
|
|
||||||
$phpWord = new PHPWord();
|
$phpWord = new PHPWord();
|
||||||
$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->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addText('Test 1', 'Font', 'Paragraph');
|
$section->addText('Test 1', 'Font');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Test 2');
|
$section->addText('Test 2', null, 'Paragraph');
|
||||||
|
$section->addLink('http://test.com');
|
||||||
|
$section->addTitle('Test', 1);
|
||||||
|
$section->addPageBreak();
|
||||||
|
$section->addTable();
|
||||||
|
$section->addListItem('Test');
|
||||||
|
$section->addImage($imageSrc);
|
||||||
|
$section->addObject($objectSrc);
|
||||||
|
$section->addTOC();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$textrun = $section->createTextRun();
|
$textrun = $section->createTextRun();
|
||||||
$textrun->addText('Test 3');
|
$textrun->addText('Test 3');
|
||||||
|
|
||||||
$writer = new PHPWord_Writer_ODText($phpWord);
|
$writer = new PHPWord_Writer_ODText($phpWord);
|
||||||
$file = join(
|
|
||||||
DIRECTORY_SEPARATOR,
|
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt')
|
|
||||||
);
|
|
||||||
$writer->save($file);
|
$writer->save($file);
|
||||||
|
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
|
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test disk caching parameters
|
* @covers ::save
|
||||||
|
* @todo Haven't got any method to test this
|
||||||
*/
|
*/
|
||||||
public function testSetDiskCaching()
|
public function testSavePhpOutput()
|
||||||
|
{
|
||||||
|
$phpWord = new PHPWord();
|
||||||
|
$section = $phpWord->createSection();
|
||||||
|
$section->addText('Test');
|
||||||
|
$writer = new PHPWord_Writer_ODText($phpWord);
|
||||||
|
$writer->save('php://output');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::save
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage PHPWord object unassigned.
|
||||||
|
*/
|
||||||
|
public function testSaveException()
|
||||||
|
{
|
||||||
|
$writer = new PHPWord_Writer_ODText();
|
||||||
|
$writer->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getWriterPart
|
||||||
|
*/
|
||||||
|
public function testGetWriterPartNull()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Writer_ODText();
|
||||||
|
$this->assertNull($object->getWriterPart('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setUseDiskCaching
|
||||||
|
* @covers ::getUseDiskCaching
|
||||||
|
*/
|
||||||
|
public function testSetGetUseDiskCaching()
|
||||||
{
|
{
|
||||||
$object = new PHPWord_Writer_ODText();
|
$object = new PHPWord_Writer_ODText();
|
||||||
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
|
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
|
||||||
$this->assertTrue($object->getUseDiskCaching());
|
$this->assertTrue($object->getUseDiskCaching());
|
||||||
$this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory());
|
$this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setUseDiskCaching
|
||||||
|
* @expectedException Exception
|
||||||
|
*/
|
||||||
|
public function testSetUseDiskCachingException()
|
||||||
|
{
|
||||||
|
$dir = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, 'foo')
|
||||||
|
);
|
||||||
|
|
||||||
|
$object = new PHPWord_Writer_ODText($phpWord);
|
||||||
|
$object->setUseDiskCaching(true, $dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,13 +6,15 @@ use PHPWord;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RTFTest
|
* Class RTFTest
|
||||||
|
*
|
||||||
* @package PHPWord\Tests
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_RTF
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class RTFTest extends \PHPUnit_Framework_TestCase
|
class RTFTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test construct
|
* covers ::construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -23,8 +25,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test construct with null value/without PHPWord
|
* covers ::__construct
|
||||||
*
|
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionMessage No PHPWord assigned.
|
* @expectedExceptionMessage No PHPWord assigned.
|
||||||
*/
|
*/
|
||||||
@ -35,28 +36,72 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test save()
|
* @covers ::save
|
||||||
|
* @todo Haven't got any method to test this
|
||||||
|
*/
|
||||||
|
public function testSavePhpOutput()
|
||||||
|
{
|
||||||
|
$phpWord = new PHPWord();
|
||||||
|
$section = $phpWord->createSection();
|
||||||
|
$section->addText('Test');
|
||||||
|
$writer = new PHPWord_Writer_RTF($phpWord);
|
||||||
|
$writer->save('php://output');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::save
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage PHPWord object unassigned.
|
||||||
|
*/
|
||||||
|
public function testSaveException()
|
||||||
|
{
|
||||||
|
$writer = new PHPWord_Writer_RTF();
|
||||||
|
$writer->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::save
|
||||||
|
* @covers ::<private>
|
||||||
*/
|
*/
|
||||||
public function testSave()
|
public function testSave()
|
||||||
{
|
{
|
||||||
|
$imageSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
|
||||||
|
);
|
||||||
|
$objectSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
||||||
|
);
|
||||||
|
$file = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
|
||||||
|
);
|
||||||
|
|
||||||
$phpWord = new PHPWord();
|
$phpWord = new PHPWord();
|
||||||
$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->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addText('Test 1', 'Font', 'Paragraph');
|
$section->addText('Test 1', 'Font');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Test 2');
|
$section->addText('Test 2', null, 'Paragraph');
|
||||||
|
$section->addLink('http://test.com');
|
||||||
|
$section->addTitle('Test', 1);
|
||||||
|
$section->addPageBreak();
|
||||||
|
$section->addTable();
|
||||||
|
$section->addListItem('Test');
|
||||||
|
$section->addImage($imageSrc);
|
||||||
|
$section->addObject($objectSrc);
|
||||||
|
$section->addTOC();
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$textrun = $section->createTextRun();
|
$textrun = $section->createTextRun();
|
||||||
$textrun->addText('Test 3');
|
$textrun->addText('Test 3');
|
||||||
|
$textrun->addTextBreak();
|
||||||
$writer = new PHPWord_Writer_RTF($phpWord);
|
$writer = new PHPWord_Writer_RTF($phpWord);
|
||||||
$file = join(
|
|
||||||
DIRECTORY_SEPARATOR,
|
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
|
|
||||||
);
|
|
||||||
$writer->save($file);
|
$writer->save($file);
|
||||||
|
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
|
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use PHPWord\Tests\TestHelperDOCX;
|
|||||||
* Class Word2007Test
|
* Class Word2007Test
|
||||||
*
|
*
|
||||||
* @package PHPWord\Tests
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_Word2007
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
*/
|
*/
|
||||||
class Word2007Test extends \PHPUnit_Framework_TestCase
|
class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||||
@ -18,6 +19,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
TestHelperDOCX::clear();
|
TestHelperDOCX::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::__construct
|
||||||
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$object = new PHPWord_Writer_Word2007(new PHPWord());
|
$object = new PHPWord_Writer_Word2007(new PHPWord());
|
||||||
@ -37,6 +41,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::save
|
||||||
|
*/
|
||||||
public function testSave()
|
public function testSave()
|
||||||
{
|
{
|
||||||
$phpWord = new PHPWord();
|
$phpWord = new PHPWord();
|
||||||
@ -51,9 +58,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
$textrun->addText('Test 3');
|
$textrun->addText('Test 3');
|
||||||
|
|
||||||
$writer = new PHPWord_Writer_Word2007($phpWord);
|
$writer = new PHPWord_Writer_Word2007($phpWord);
|
||||||
$file = join(
|
$file = \join(
|
||||||
DIRECTORY_SEPARATOR,
|
\DIRECTORY_SEPARATOR,
|
||||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx')
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx')
|
||||||
);
|
);
|
||||||
$writer->save($file);
|
$writer->save($file);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
@ -61,7 +68,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers PHPWord_Writer_Word2007::checkContentTypes
|
* @covers ::checkContentTypes
|
||||||
*/
|
*/
|
||||||
public function testCheckContentTypes()
|
public function testCheckContentTypes()
|
||||||
{
|
{
|
||||||
@ -89,4 +96,31 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setUseDiskCaching
|
||||||
|
* @covers ::getUseDiskCaching
|
||||||
|
*/
|
||||||
|
public function testSetGetUseDiskCaching()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Writer_Word2007($phpWord);
|
||||||
|
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
|
||||||
|
|
||||||
|
$this->assertTrue($object->getUseDiskCaching());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::setUseDiskCaching
|
||||||
|
* @expectedException Exception
|
||||||
|
*/
|
||||||
|
public function testSetUseDiskCachingException()
|
||||||
|
{
|
||||||
|
$dir = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, 'foo')
|
||||||
|
);
|
||||||
|
|
||||||
|
$object = new PHPWord_Writer_Word2007($phpWord);
|
||||||
|
$object->setUseDiskCaching(true, $dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Tests/_files/templates/clone-row.docx
Normal file
BIN
Tests/_files/templates/clone-row.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user