diff --git a/Classes/PHPWord/Reader/Abstract.php b/Classes/PHPWord/Reader/Abstract.php index 1e7acb51..18392f8b 100644 --- a/Classes/PHPWord/Reader/Abstract.php +++ b/Classes/PHPWord/Reader/Abstract.php @@ -27,6 +27,8 @@ /** * PHPWord_Reader_Abstract + * + * @codeCoverageIgnore Abstract class */ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader { diff --git a/Classes/PHPWord/Writer/ODText.php b/Classes/PHPWord/Writer/ODText.php index 97e8f29b..6ec25cba 100755 --- a/Classes/PHPWord/Writer/ODText.php +++ b/Classes/PHPWord/Writer/ODText.php @@ -174,6 +174,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); } } + // @codeCoverageIgnoreEnd // Close file if ($objZip->close() === false) { diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/Classes/PHPWord/Writer/ODText/Manifest.php index 266bf24f..c3c28981 100755 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/Classes/PHPWord/Writer/ODText/Manifest.php @@ -101,6 +101,7 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart $objWriter->endElement(); } } + // @codeCoverageIgnoreEnd $objWriter->endElement(); diff --git a/Tests/PHPWord/TemplateTest.php b/Tests/PHPWord/TemplateTest.php index d7e99e55..872ab182 100644 --- a/Tests/PHPWord/TemplateTest.php +++ b/Tests/PHPWord/TemplateTest.php @@ -2,9 +2,10 @@ namespace PHPWord\Tests; use PHPWord_Template; +use PHPWord; /** - * @coversDefaultClass PHPWord_Template + * @coversDefaultClass PHPWord_Template */ final class TemplateTest extends \PHPUnit_Framework_TestCase { @@ -143,4 +144,32 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase */ @$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); + } } diff --git a/Tests/PHPWord/Writer/ODTextTest.php b/Tests/PHPWord/Writer/ODTextTest.php index 6b162c3a..ef92d249 100644 --- a/Tests/PHPWord/Writer/ODTextTest.php +++ b/Tests/PHPWord/Writer/ODTextTest.php @@ -7,7 +7,8 @@ use PHPWord; /** * Class ODTextTest * - * @package PHPWord\Tests + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Writer_ODText * @runTestsInSeparateProcesses */ class ODTextTest extends \PHPUnit_Framework_TestCase @@ -37,10 +38,9 @@ class ODTextTest extends \PHPUnit_Framework_TestCase } /** - * Test construct with null value/without PHPWord - * - * @expectedException Exception - * @expectedExceptionMessage No PHPWord assigned. + * @covers ::getPHPWord + * @expectedException Exception + * @expectedExceptionMessage No PHPWord assigned. */ public function testConstructWithNull() { @@ -49,39 +49,106 @@ class ODTextTest extends \PHPUnit_Framework_TestCase } /** - * Test save() + * @covers ::save */ 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->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->createSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText('Test 1', 'Font'); $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(); $textrun = $section->createTextRun(); $textrun->addText('Test 3'); - $writer = new PHPWord_Writer_ODText($phpWord); - $file = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt') - ); $writer->save($file); + $this->assertTrue(file_exists($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->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); $this->assertTrue($object->getUseDiskCaching()); $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); + } } diff --git a/Tests/PHPWord/Writer/RTFTest.php b/Tests/PHPWord/Writer/RTFTest.php index d232854b..d071def7 100644 --- a/Tests/PHPWord/Writer/RTFTest.php +++ b/Tests/PHPWord/Writer/RTFTest.php @@ -6,13 +6,15 @@ use PHPWord; /** * Class RTFTest - * @package PHPWord\Tests + * + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Writer_RTF * @runTestsInSeparateProcesses */ class RTFTest extends \PHPUnit_Framework_TestCase { /** - * Test construct + * covers ::construct */ public function testConstruct() { @@ -23,10 +25,9 @@ class RTFTest extends \PHPUnit_Framework_TestCase } /** - * Test construct with null value/without PHPWord - * - * @expectedException Exception - * @expectedExceptionMessage No PHPWord assigned. + * covers ::__construct + * @expectedException Exception + * @expectedExceptionMessage No PHPWord assigned. */ public function testConstructWithNull() { @@ -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 :: */ 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->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->createSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText('Test 1', 'Font'); $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(); $textrun = $section->createTextRun(); $textrun->addText('Test 3'); - + $textrun->addTextBreak(); $writer = new PHPWord_Writer_RTF($phpWord); - $file = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf') - ); $writer->save($file); + $this->assertTrue(file_exists($file)); + unlink($file); } } diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/Tests/PHPWord/Writer/Word2007Test.php index ac66af2a..df58d737 100644 --- a/Tests/PHPWord/Writer/Word2007Test.php +++ b/Tests/PHPWord/Writer/Word2007Test.php @@ -8,7 +8,8 @@ use PHPWord\Tests\TestHelperDOCX; /** * Class Word2007Test * - * @package PHPWord\Tests + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Writer_Word2007 * @runTestsInSeparateProcesses */ class Word2007Test extends \PHPUnit_Framework_TestCase @@ -18,6 +19,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase TestHelperDOCX::clear(); } + /** + * covers ::__construct + */ public function testConstruct() { $object = new PHPWord_Writer_Word2007(new PHPWord()); @@ -37,6 +41,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase } } + /** + * @covers ::save + */ public function testSave() { $phpWord = new PHPWord(); @@ -51,9 +58,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase $textrun->addText('Test 3'); $writer = new PHPWord_Writer_Word2007($phpWord); - $file = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx') + $file = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx') ); $writer->save($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() { @@ -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); + } } diff --git a/Tests/_files/templates/clone-row.docx b/Tests/_files/templates/clone-row.docx new file mode 100644 index 00000000..eb944367 Binary files /dev/null and b/Tests/_files/templates/clone-row.docx differ