diff --git a/Tests/PHPWord/Writer/ODTextTest.php b/Tests/PHPWord/Writer/ODTextTest.php new file mode 100644 index 00000000..d2ac2fc2 --- /dev/null +++ b/Tests/PHPWord/Writer/ODTextTest.php @@ -0,0 +1,88 @@ +assertInstanceOf('PHPWord', $object->getPHPWord()); + $this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable()); + + $this->assertEquals('./', $object->getDiskCachingDirectory()); + $writerParts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles'); + foreach ($writerParts as $part) { + $this->assertInstanceOf( + "PHPWord_Writer_ODText_{$part}", + $object->getWriterPart($part) + ); + $this->assertInstanceOf( + "PHPWord_Writer_ODText", + $object->getWriterPart($part)->getParentWriter() + ); + } + } + + /** + * Test construct with null value/without PHPWord + * + * @expectedException Exception + * @expectedExceptionMessage No PHPWord assigned. + */ + public function testConstructWithNull() + { + $object = new PHPWord_Writer_ODText(); + $object->getPHPWord(); + } + + /** + * Test save() + */ + public function testSave() + { + $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->addTextBreak(); + $section->addText('Test 2'); + $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 + */ + public function testSetDiskCaching() + { + $object = new PHPWord_Writer_ODText(); + $object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); + $this->assertTrue($object->getUseDiskCaching()); + $this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory()); + } +} diff --git a/Tests/PHPWord/Writer/RTFTest.php b/Tests/PHPWord/Writer/RTFTest.php new file mode 100644 index 00000000..fc713786 --- /dev/null +++ b/Tests/PHPWord/Writer/RTFTest.php @@ -0,0 +1,63 @@ +assertInstanceOf('PHPWord', $object->getPHPWord()); + $this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable()); + } + + /** + * Test construct with null value/without PHPWord + * + * @expectedException Exception + * @expectedExceptionMessage No PHPWord assigned. + */ + public function testConstructWithNull() + { + $object = new PHPWord_Writer_RTF(); + $object->getPHPWord(); + } + + /** + * Test save() + */ + public function testSave() + { + $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->addTextBreak(); + $section->addText('Test 2'); + $section = $phpWord->createSection(); + $textrun = $section->createTextRun(); + $textrun->addText('Test 3'); + + $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 new file mode 100644 index 00000000..28b0d581 --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007Test.php @@ -0,0 +1,63 @@ +assertInstanceOf( + "PHPWord_Writer_Word2007_{$part}", + $object->getWriterPart($part) + ); + $this->assertInstanceOf( + "PHPWord_Writer_Word2007", + $object->getWriterPart($part)->getParentWriter() + ); + } + } + + /** + * Test save() + */ + public function testSave() + { + $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->addTextBreak(); + $section->addText('Test 2'); + $section = $phpWord->createSection(); + $textrun = $section->createTextRun(); + $textrun->addText('Test 3'); + + $writer = new PHPWord_Writer_Word2007($phpWord); + $file = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx') + ); + $writer->save($file); + $this->assertTrue(file_exists($file)); + unlink($file); + } +}