New unit tests for Writer
This commit is contained in:
parent
28fef5f264
commit
077d87d1bc
@ -33,9 +33,9 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
|
|||||||
/**
|
/**
|
||||||
* Write content file to XML format
|
* Write content file to XML format
|
||||||
*
|
*
|
||||||
* @param PHPWord $pPHPWord
|
* @param PHPWord $pPHPWord
|
||||||
* @return string XML Output
|
* @return string XML Output
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function writeContent(PHPWord $pPHPWord = null)
|
public function writeContent(PHPWord $pPHPWord = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -113,9 +113,10 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
|
|||||||
/**
|
/**
|
||||||
* Get image mime type
|
* Get image mime type
|
||||||
*
|
*
|
||||||
* @param string $pFile Filename
|
* @param string $pFile Filename
|
||||||
* @return string Mime Type
|
* @return string Mime Type
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @codeCoverageIgnore Image is not yet handled by ODText
|
||||||
*/
|
*/
|
||||||
private function _getImageMimeType($pFile = '')
|
private function _getImageMimeType($pFile = '')
|
||||||
{
|
{
|
||||||
|
|||||||
@ -289,4 +289,14 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
|
|||||||
$this->checkContentTypes($element['source']);
|
$this->checkContentTypes($element['source']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get disk caching directory
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDiskCachingDirectory()
|
||||||
|
{
|
||||||
|
return $this->_diskCachingDirectory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
Tests/PHPWord/Writer/ODText/WriterPartTest.php
Normal file
45
Tests/PHPWord/Writer/ODText/WriterPartTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
namespace PHPWord\Tests\Writer\ODText;
|
||||||
|
|
||||||
|
use PHPWord_Writer_ODText_WriterPart;
|
||||||
|
use PHPWord_Writer_ODText;
|
||||||
|
use PHPWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WriterPartTest
|
||||||
|
*
|
||||||
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_ODText_WriterPart
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class WriterPartTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* covers ::setParentWriter
|
||||||
|
* covers ::getParentWriter
|
||||||
|
*/
|
||||||
|
public function testSetGetParentWriter()
|
||||||
|
{
|
||||||
|
$object = $this->getMockForAbstractClass(
|
||||||
|
'PHPWord_Writer_Word2007_WriterPart'
|
||||||
|
);
|
||||||
|
$object->setParentWriter(new PHPWord_Writer_ODText());
|
||||||
|
$this->assertEquals(
|
||||||
|
new PHPWord_Writer_ODText(),
|
||||||
|
$object->getParentWriter()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::getParentWriter
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned.
|
||||||
|
*/
|
||||||
|
public function testSetGetParentWriterNull()
|
||||||
|
{
|
||||||
|
$object = $this->getMockForAbstractClass(
|
||||||
|
'PHPWord_Writer_Word2007_WriterPart'
|
||||||
|
);
|
||||||
|
$object->getParentWriter();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -92,19 +92,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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_ODText($phpWord);
|
|
||||||
$writer->save('php://output');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::save
|
* @covers ::save
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
|
|||||||
@ -35,19 +35,6 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||||||
$object->getPHPWord();
|
$object->getPHPWord();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
* @covers ::save
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
@ -78,13 +65,15 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$fontStyle = array('name' => 'Verdana', 'size' => 11, 'bold' => true, 'italic' => true, 'color' => 'F29101', 'fgColor' => '123456');
|
||||||
|
$paragraphStyle = array('align' => 'center', 'spaceAfter' => 120);
|
||||||
$phpWord = new PHPWord();
|
$phpWord = new PHPWord();
|
||||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
$phpWord->addFontStyle('Font', $fontStyle);
|
||||||
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
$phpWord->addParagraphStyle('Paragraph', $paragraphStyle);
|
||||||
$section = $phpWord->createSection();
|
$section = $phpWord->createSection();
|
||||||
$section->addText('Test 1', 'Font');
|
$section->addText('Test 1', 'Font');
|
||||||
|
$section->addText('Test 2', array('name' => 'Tahoma'), 'Paragraph');
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Test 2', null, 'Paragraph');
|
|
||||||
$section->addLink('http://test.com');
|
$section->addLink('http://test.com');
|
||||||
$section->addTitle('Test', 1);
|
$section->addTitle('Test', 1);
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|||||||
44
Tests/PHPWord/Writer/Word2007/FooterTest.php
Normal file
44
Tests/PHPWord/Writer/Word2007/FooterTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
namespace PHPWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PHPWord_Writer_Word2007_Footer;
|
||||||
|
use PHPWord_Writer_Word2007;
|
||||||
|
use PHPWord_Section_Footer;
|
||||||
|
use PHPWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FooterTest
|
||||||
|
*
|
||||||
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_Word2007_Footer
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class FooterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers ::writeFooter
|
||||||
|
*/
|
||||||
|
public function testWriteFooter()
|
||||||
|
{
|
||||||
|
$imageSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
|
||||||
|
);
|
||||||
|
$container = new PHPWord_Section_Footer(1);
|
||||||
|
$container->addText('');
|
||||||
|
$container->addPreserveText('');
|
||||||
|
$container->addTextBreak();
|
||||||
|
$container->createTextRun();
|
||||||
|
$container->addTable()->addRow()->addCell()->addText('');
|
||||||
|
$container->addImage($imageSrc);
|
||||||
|
|
||||||
|
$writer = new PHPWord_Writer_Word2007();
|
||||||
|
$object = new PHPWord_Writer_Word2007_Footer();
|
||||||
|
$object->setParentWriter($writer);
|
||||||
|
$object->writeFooter($container);
|
||||||
|
$writer->setUseDiskCaching(true);
|
||||||
|
$xml = simplexml_load_string($object->writeFooter($container));
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SimpleXMLElement', $xml);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
Tests/PHPWord/Writer/Word2007/HeaderTest.php
Normal file
46
Tests/PHPWord/Writer/Word2007/HeaderTest.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace PHPWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PHPWord_Writer_Word2007_Header;
|
||||||
|
use PHPWord_Writer_Word2007;
|
||||||
|
use PHPWord_Section_Header;
|
||||||
|
use PHPWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class HeaderTest
|
||||||
|
*
|
||||||
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_Word2007_Header
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers ::writeHeader
|
||||||
|
*/
|
||||||
|
public function testWriteHeader()
|
||||||
|
{
|
||||||
|
$imageSrc = \join(
|
||||||
|
\DIRECTORY_SEPARATOR,
|
||||||
|
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
|
||||||
|
);
|
||||||
|
|
||||||
|
$container = new PHPWord_Section_Header(1);
|
||||||
|
$container->addText('Test');
|
||||||
|
$container->addPreserveText('');
|
||||||
|
$container->addTextBreak();
|
||||||
|
$container->createTextRun();
|
||||||
|
$container->addTable()->addRow()->addCell()->addText('');
|
||||||
|
$container->addImage($imageSrc);
|
||||||
|
$container->addWatermark($imageSrc);
|
||||||
|
|
||||||
|
$writer = new PHPWord_Writer_Word2007();
|
||||||
|
$object = new PHPWord_Writer_Word2007_Header();
|
||||||
|
$object->setParentWriter($writer);
|
||||||
|
$object->writeHeader($container);
|
||||||
|
$writer->setUseDiskCaching(true);
|
||||||
|
$xml = simplexml_load_string($object->writeHeader($container));
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SimpleXMLElement', $xml);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Tests/PHPWord/Writer/Word2007/WriterPartTest.php
Normal file
45
Tests/PHPWord/Writer/Word2007/WriterPartTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
namespace PHPWord\Tests\Writer\Word2007;
|
||||||
|
|
||||||
|
use PHPWord_Writer_Word2007_WriterPart;
|
||||||
|
use PHPWord_Writer_Word2007;
|
||||||
|
use PHPWord\Tests\TestHelperDOCX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WriterPartTest
|
||||||
|
*
|
||||||
|
* @package PHPWord\Tests
|
||||||
|
* @coversDefaultClass PHPWord_Writer_Word2007_WriterPart
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class WriterPartTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* covers ::setParentWriter
|
||||||
|
* covers ::getParentWriter
|
||||||
|
*/
|
||||||
|
public function testSetGetParentWriter()
|
||||||
|
{
|
||||||
|
$object = $this->getMockForAbstractClass(
|
||||||
|
'PHPWord_Writer_Word2007_WriterPart'
|
||||||
|
);
|
||||||
|
$object->setParentWriter(new PHPWord_Writer_Word2007());
|
||||||
|
$this->assertEquals(
|
||||||
|
new PHPWord_Writer_Word2007(),
|
||||||
|
$object->getParentWriter()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* covers ::getParentWriter
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned.
|
||||||
|
*/
|
||||||
|
public function testSetGetParentWriterNull()
|
||||||
|
{
|
||||||
|
$object = $this->getMockForAbstractClass(
|
||||||
|
'PHPWord_Writer_Word2007_WriterPart'
|
||||||
|
);
|
||||||
|
$object->getParentWriter();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -67,6 +67,26 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::save
|
||||||
|
* @expectedException Exception
|
||||||
|
* @expectedExceptionMessage PHPWord object unassigned.
|
||||||
|
*/
|
||||||
|
public function testSaveException()
|
||||||
|
{
|
||||||
|
$writer = new PHPWord_Writer_Word2007();
|
||||||
|
$writer->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getWriterPart
|
||||||
|
*/
|
||||||
|
public function testGetWriterPartNull()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Writer_Word2007();
|
||||||
|
$this->assertNull($object->getWriterPart('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::checkContentTypes
|
* @covers ::checkContentTypes
|
||||||
*/
|
*/
|
||||||
@ -100,13 +120,14 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @covers ::setUseDiskCaching
|
* @covers ::setUseDiskCaching
|
||||||
* @covers ::getUseDiskCaching
|
* @covers ::getUseDiskCaching
|
||||||
|
* @covers ::getDiskCachingDirectory
|
||||||
*/
|
*/
|
||||||
public function testSetGetUseDiskCaching()
|
public function testSetGetUseDiskCaching()
|
||||||
{
|
{
|
||||||
$object = new PHPWord_Writer_Word2007();
|
$object = new PHPWord_Writer_Word2007();
|
||||||
$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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user