From d04e600300e4be4be64cce3ce36b92964ec5ccd8 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 15 Mar 2014 14:48:26 +0700 Subject: [PATCH] New unit test for ODText\Content and some test fixes --- Classes/PHPWord/Writer/ODText/Content.php | 25 +- Classes/PHPWord/Writer/RTF.php | 18 +- README.md | 2 +- Tests/PHPWord/DocumentPropertiesTest.php | 246 ++++++++++++-------- Tests/PHPWord/Shared/FileTest.php | 46 ++-- Tests/PHPWord/Shared/StringTest.php | 29 +-- Tests/PHPWord/Writer/ODText/ContentTest.php | 65 ++++++ Tests/PHPWord/Writer/Word2007Test.php | 4 +- Tests/_inc/TestHelperDOCX.php | 4 +- 9 files changed, 279 insertions(+), 160 deletions(-) create mode 100644 Tests/PHPWord/Writer/ODText/ContentTest.php diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php index b788478e..c33635cc 100755 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ b/Classes/PHPWord/Writer/ODText/Content.php @@ -254,24 +254,24 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart } elseif ($element instanceof PHPWord_Section_TextBreak) { $this->_writeTextBreak($objWriter); } elseif ($element instanceof PHPWord_Section_Link) { - $this->writeUnsupportedElement($objWriter, 'link'); + $this->writeUnsupportedElement($objWriter, 'Link'); } elseif ($element instanceof PHPWord_Section_Title) { - $this->writeUnsupportedElement($objWriter, 'title'); + $this->writeUnsupportedElement($objWriter, 'Title'); } elseif ($element instanceof PHPWord_Section_PageBreak) { - $this->writeUnsupportedElement($objWriter, 'page break'); + $this->writeUnsupportedElement($objWriter, 'Page Break'); } elseif ($element instanceof PHPWord_Section_Table) { - $this->writeUnsupportedElement($objWriter, 'table'); + $this->writeUnsupportedElement($objWriter, 'Table'); } elseif ($element instanceof PHPWord_Section_ListItem) { - $this->writeUnsupportedElement($objWriter, 'list item'); + $this->writeUnsupportedElement($objWriter, 'List Item'); } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) { - $this->writeUnsupportedElement($objWriter, 'image'); + $this->writeUnsupportedElement($objWriter, 'Image'); } elseif ($element instanceof PHPWord_Section_Object) { - $this->writeUnsupportedElement($objWriter, 'object'); + $this->writeUnsupportedElement($objWriter, 'Object'); } elseif ($element instanceof PHPWord_TOC) { $this->writeUnsupportedElement($objWriter, 'TOC'); } else { - $this->writeUnsupportedElement($objWriter, 'other'); + $this->writeUnsupportedElement($objWriter, 'Element'); } } @@ -372,18 +372,15 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart $objWriter->endElement(); } + // @codeCoverageIgnoreStart private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) { } - /** - * Dummy function just to make all samples produce ODT - * - * @todo Create the real function - */ private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) { } + // @codeCoverageIgnoreEnd /** * Write unsupported element @@ -394,7 +391,7 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart private function writeUnsupportedElement($objWriter, $element) { $objWriter->startElement('text:p'); - $objWriter->writeRaw("Cannot write content. This version of PHPWord has not supported {$element} element in ODText."); + $objWriter->writeRaw("{$element}"); $objWriter->endElement(); } } diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index 9104c6fe..80889ebe 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -315,24 +315,24 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter } elseif ($element instanceof PHPWord_Section_TextRun) { $sRTFBody .= $this->getDataContentTextRun($element); } elseif ($element instanceof PHPWord_Section_Link) { - $sRTFBody .= $this->getDataContentUnsupportedElement('link'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Link'); } elseif ($element instanceof PHPWord_Section_Title) { - $sRTFBody .= $this->getDataContentUnsupportedElement('title'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Title'); } elseif ($element instanceof PHPWord_Section_PageBreak) { - $sRTFBody .= $this->getDataContentUnsupportedElement('page break'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Page Break'); } elseif ($element instanceof PHPWord_Section_Table) { - $sRTFBody .= $this->getDataContentUnsupportedElement('table'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Table'); } elseif ($element instanceof PHPWord_Section_ListItem) { - $sRTFBody .= $this->getDataContentUnsupportedElement('list item'); + $sRTFBody .= $this->getDataContentUnsupportedElement('List Item'); } elseif ($element instanceof PHPWord_Section_Image || $element instanceof PHPWord_Section_MemoryImage) { - $sRTFBody .= $this->getDataContentUnsupportedElement('image'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Image'); } elseif ($element instanceof PHPWord_Section_Object) { - $sRTFBody .= $this->getDataContentUnsupportedElement('object'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Object'); } elseif ($element instanceof PHPWord_TOC) { $sRTFBody .= $this->getDataContentUnsupportedElement('TOC'); } else { - $sRTFBody .= $this->getDataContentUnsupportedElement('other'); + $sRTFBody .= $this->getDataContentUnsupportedElement('Other'); } } } @@ -468,7 +468,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter { $sRTFText = ''; $sRTFText .= '\pard\nowidctlpar' . PHP_EOL; - $sRTFText .= "Cannot write content. This version of PHPWord has not supported {$element} element in RTF."; + $sRTFText .= "{$element}"; $sRTFText .= '\par' . PHP_EOL; return $sRTFText; diff --git a/README.md b/README.md index 3d90d875..d35603d0 100755 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ We're reorganizing our documentation. Below are some of the most important thing #### Basic usage -The following is a basic example of the PHPWord library. More examples are provided in the (sample folder)[samples/]. +The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). ```php $PHPWord = new PHPWord(); diff --git a/Tests/PHPWord/DocumentPropertiesTest.php b/Tests/PHPWord/DocumentPropertiesTest.php index 421f3269..f98a9907 100644 --- a/Tests/PHPWord/DocumentPropertiesTest.php +++ b/Tests/PHPWord/DocumentPropertiesTest.php @@ -3,167 +3,219 @@ namespace PHPWord\Tests; use PHPWord_DocumentProperties; +/** + * Class DocumentPropertiesTest + * + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_DocumentProperties + * @runTestsInSeparateProcesses + */ class DocumentPropertiesTest extends \PHPUnit_Framework_TestCase { public function testCreator() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setCreator(); - $this->assertEquals('', $oProperties->getCreator()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setCreator(); + $this->assertEquals('', $oProperties->getCreator()); - $oProperties->setCreator('AAA'); - $this->assertEquals('AAA', $oProperties->getCreator()); + $oProperties->setCreator('AAA'); + $this->assertEquals('AAA', $oProperties->getCreator()); } public function testLastModifiedBy() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setLastModifiedBy(); - $this->assertEquals('', $oProperties->getLastModifiedBy()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setLastModifiedBy(); + $this->assertEquals('', $oProperties->getLastModifiedBy()); - $oProperties->setLastModifiedBy('AAA'); - $this->assertEquals('AAA', $oProperties->getLastModifiedBy()); + $oProperties->setLastModifiedBy('AAA'); + $this->assertEquals('AAA', $oProperties->getLastModifiedBy()); } public function testCreated() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setCreated(); - $this->assertEquals(time(), $oProperties->getCreated()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setCreated(); + $this->assertEquals(time(), $oProperties->getCreated()); - $iTime = time() + 3600; - $oProperties->setCreated($iTime); - $this->assertEquals($iTime, $oProperties->getCreated()); + $iTime = time() + 3600; + $oProperties->setCreated($iTime); + $this->assertEquals($iTime, $oProperties->getCreated()); } public function testModified() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setModified(); - $this->assertEquals(time(), $oProperties->getModified()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setModified(); + $this->assertEquals(time(), $oProperties->getModified()); - $iTime = time() + 3600; - $oProperties->setModified($iTime); - $this->assertEquals($iTime, $oProperties->getModified()); + $iTime = time() + 3600; + $oProperties->setModified($iTime); + $this->assertEquals($iTime, $oProperties->getModified()); } public function testTitle() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setTitle(); - $this->assertEquals('', $oProperties->getTitle()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setTitle(); + $this->assertEquals('', $oProperties->getTitle()); - $oProperties->setTitle('AAA'); - $this->assertEquals('AAA', $oProperties->getTitle()); + $oProperties->setTitle('AAA'); + $this->assertEquals('AAA', $oProperties->getTitle()); } public function testDescription() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setDescription(); - $this->assertEquals('', $oProperties->getDescription()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setDescription(); + $this->assertEquals('', $oProperties->getDescription()); - $oProperties->setDescription('AAA'); - $this->assertEquals('AAA', $oProperties->getDescription()); + $oProperties->setDescription('AAA'); + $this->assertEquals('AAA', $oProperties->getDescription()); } public function testSubject() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setSubject(); - $this->assertEquals('', $oProperties->getSubject()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setSubject(); + $this->assertEquals('', $oProperties->getSubject()); - $oProperties->setSubject('AAA'); - $this->assertEquals('AAA', $oProperties->getSubject()); + $oProperties->setSubject('AAA'); + $this->assertEquals('AAA', $oProperties->getSubject()); } public function testKeywords() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setKeywords(); - $this->assertEquals('', $oProperties->getKeywords()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setKeywords(); + $this->assertEquals('', $oProperties->getKeywords()); - $oProperties->setKeywords('AAA'); - $this->assertEquals('AAA', $oProperties->getKeywords()); + $oProperties->setKeywords('AAA'); + $this->assertEquals('AAA', $oProperties->getKeywords()); } public function testCategory() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setCategory(); - $this->assertEquals('', $oProperties->getCategory()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setCategory(); + $this->assertEquals('', $oProperties->getCategory()); - $oProperties->setCategory('AAA'); - $this->assertEquals('AAA', $oProperties->getCategory()); + $oProperties->setCategory('AAA'); + $this->assertEquals('AAA', $oProperties->getCategory()); } public function testCompany() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setCompany(); - $this->assertEquals('', $oProperties->getCompany()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setCompany(); + $this->assertEquals('', $oProperties->getCompany()); - $oProperties->setCompany('AAA'); - $this->assertEquals('AAA', $oProperties->getCompany()); + $oProperties->setCompany('AAA'); + $this->assertEquals('AAA', $oProperties->getCompany()); } public function testManager() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setManager(); - $this->assertEquals('', $oProperties->getManager()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setManager(); + $this->assertEquals('', $oProperties->getManager()); - $oProperties->setManager('AAA'); - $this->assertEquals('AAA', $oProperties->getManager()); + $oProperties->setManager('AAA'); + $this->assertEquals('AAA', $oProperties->getManager()); } public function testCustomProperty() { - $oProperties = new PHPWord_DocumentProperties(); - $oProperties->setCustomProperty('key1', null); - $oProperties->setCustomProperty('key2', true); - $oProperties->setCustomProperty('key3', 3); - $oProperties->setCustomProperty('key4', 4.4); - $oProperties->setCustomProperty('key5', 'value5'); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key1')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, $oProperties->getCustomPropertyType('key2')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, $oProperties->getCustomPropertyType('key3')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, $oProperties->getCustomPropertyType('key4')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key5')); - $this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key1')); - $this->assertEquals(true, $oProperties->getCustomPropertyValue('key2')); - $this->assertEquals(3, $oProperties->getCustomPropertyValue('key3')); - $this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4')); - $this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key6')); - $this->assertEquals(true, $oProperties->isCustomPropertySet('key5')); - $this->assertEquals(false, $oProperties->isCustomPropertySet('key6')); - $this->assertEquals(array('key1', 'key2', 'key3', 'key4', 'key5'), $oProperties->getCustomProperties()); + $oProperties = new PHPWord_DocumentProperties(); + $oProperties->setCustomProperty('key1', null); + $oProperties->setCustomProperty('key2', true); + $oProperties->setCustomProperty('key3', 3); + $oProperties->setCustomProperty('key4', 4.4); + $oProperties->setCustomProperty('key5', 'value5'); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, + $oProperties->getCustomPropertyType('key1') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, + $oProperties->getCustomPropertyType('key2') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, + $oProperties->getCustomPropertyType('key3') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, + $oProperties->getCustomPropertyType('key4') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, + $oProperties->getCustomPropertyType('key5') + ); + $this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); + $this->assertEquals(null, $oProperties->getCustomPropertyValue('key1')); + $this->assertEquals(true, $oProperties->getCustomPropertyValue('key2')); + $this->assertEquals(3, $oProperties->getCustomPropertyValue('key3')); + $this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4')); + $this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5')); + $this->assertEquals(null, $oProperties->getCustomPropertyValue('key6')); + $this->assertEquals(true, $oProperties->isCustomPropertySet('key5')); + $this->assertEquals(false, $oProperties->isCustomPropertySet('key6')); + $this->assertEquals(array( + 'key1', + 'key2', + 'key3', + 'key4', + 'key5' + ), $oProperties->getCustomProperties()); } public function testConvertProperty() { - $this->assertEquals('', PHPWord_DocumentProperties::convertProperty('a', 'empty')); - $this->assertEquals(null, PHPWord_DocumentProperties::convertProperty('a', 'null')); - $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8', 'int')); - $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8.3', 'uint')); - $this->assertEquals(8.3, PHPWord_DocumentProperties::convertProperty('8.3', 'decimal')); - $this->assertEquals('8.3', PHPWord_DocumentProperties::convertProperty('8.3', 'lpstr')); - $this->assertEquals(strtotime('10/11/2013'), PHPWord_DocumentProperties::convertProperty('10/11/2013', 'date')); - $this->assertEquals(true, PHPWord_DocumentProperties::convertProperty('true', 'bool')); - $this->assertEquals(false, PHPWord_DocumentProperties::convertProperty('1', 'bool')); - $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', 'array')); - $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', '')); + $this->assertEquals('', PHPWord_DocumentProperties::convertProperty('a', 'empty')); + $this->assertEquals(null, PHPWord_DocumentProperties::convertProperty('a', 'null')); + $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8', 'int')); + $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8.3', 'uint')); + $this->assertEquals(8.3, PHPWord_DocumentProperties::convertProperty('8.3', 'decimal')); + $this->assertEquals('8.3', PHPWord_DocumentProperties::convertProperty('8.3', 'lpstr')); + $this->assertEquals(strtotime('10/11/2013'), PHPWord_DocumentProperties::convertProperty('10/11/2013', 'date')); + $this->assertEquals(true, PHPWord_DocumentProperties::convertProperty('true', 'bool')); + $this->assertEquals(false, PHPWord_DocumentProperties::convertProperty('1', 'bool')); + $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', 'array')); + $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', '')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, PHPWord_DocumentProperties::convertPropertyType('int')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, PHPWord_DocumentProperties::convertPropertyType('uint')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, PHPWord_DocumentProperties::convertPropertyType('decimal')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, PHPWord_DocumentProperties::convertPropertyType('lpstr')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_DATE, PHPWord_DocumentProperties::convertPropertyType('date')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, PHPWord_DocumentProperties::convertPropertyType('bool')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, PHPWord_DocumentProperties::convertPropertyType('array')); - $this->assertEquals(PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, PHPWord_DocumentProperties::convertPropertyType('')); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, + PHPWord_DocumentProperties::convertPropertyType('int') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, + PHPWord_DocumentProperties::convertPropertyType('uint') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, + PHPWord_DocumentProperties::convertPropertyType('decimal') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, + PHPWord_DocumentProperties::convertPropertyType('lpstr') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_DATE, + PHPWord_DocumentProperties::convertPropertyType('date') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, + PHPWord_DocumentProperties::convertPropertyType('bool') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, + PHPWord_DocumentProperties::convertPropertyType('array') + ); + $this->assertEquals( + PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, + PHPWord_DocumentProperties::convertPropertyType('') + ); } } diff --git a/Tests/PHPWord/Shared/FileTest.php b/Tests/PHPWord/Shared/FileTest.php index 0f4df75e..a5ac348f 100644 --- a/Tests/PHPWord/Shared/FileTest.php +++ b/Tests/PHPWord/Shared/FileTest.php @@ -6,7 +6,8 @@ use PHPWord_Shared_File; /** * Class FileTest * - * @package PHPWord\Tests + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Shared_File * @runTestsInSeparateProcesses */ class FileTest extends \PHPUnit_Framework_TestCase @@ -16,24 +17,26 @@ class FileTest extends \PHPUnit_Framework_TestCase */ public function testFileExists() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates') - ); - chdir($dir); - $this->assertTrue(PHPWord_Shared_File::file_exists('blank.docx')); + $dir = join(DIRECTORY_SEPARATOR, array( + PHPWORD_TESTS_DIR_ROOT, + '_files', + 'templates' + )); + chdir($dir); + $this->assertTrue(PHPWord_Shared_File::file_exists('blank.docx')); } /** * Test file_exists() */ public function testNoFileExists() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates') - ); - chdir($dir); - $this->assertFalse(PHPWord_Shared_File::file_exists('404.docx')); + $dir = join(DIRECTORY_SEPARATOR, array( + PHPWORD_TESTS_DIR_ROOT, + '_files', + 'templates' + )); + chdir($dir); + $this->assertFalse(PHPWord_Shared_File::file_exists('404.docx')); } /** @@ -41,13 +44,14 @@ class FileTest extends \PHPUnit_Framework_TestCase */ public function testRealpath() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates') - ); - chdir($dir); - $file = 'blank.docx'; - $expected = $dir . DIRECTORY_SEPARATOR . $file; - $this->assertEquals($expected, PHPWord_Shared_File::realpath($file)); + $dir = join(DIRECTORY_SEPARATOR, array( + PHPWORD_TESTS_DIR_ROOT, + '_files', + 'templates' + )); + chdir($dir); + $file = 'blank.docx'; + $expected = $dir . DIRECTORY_SEPARATOR . $file; + $this->assertEquals($expected, PHPWord_Shared_File::realpath($file)); } } diff --git a/Tests/PHPWord/Shared/StringTest.php b/Tests/PHPWord/Shared/StringTest.php index e04ebc23..3698e2e0 100644 --- a/Tests/PHPWord/Shared/StringTest.php +++ b/Tests/PHPWord/Shared/StringTest.php @@ -6,27 +6,28 @@ use PHPWord_Shared_String; /** * Class StringTest * - * @package PHPWord\Tests + * @package PHPWord\Tests + * @coversDefaultClass PHPWord_Shared_String * @runTestsInSeparateProcesses */ class StringTest extends \PHPUnit_Framework_TestCase { public function testIsUTF8() { - $this->assertTrue(PHPWord_Shared_String::IsUTF8('')); - $this->assertTrue(PHPWord_Shared_String::IsUTF8('éééé')); - $this->assertFalse(PHPWord_Shared_String::IsUTF8(utf8_decode('éééé'))); + $this->assertTrue(PHPWord_Shared_String::IsUTF8('')); + $this->assertTrue(PHPWord_Shared_String::IsUTF8('éééé')); + $this->assertFalse(PHPWord_Shared_String::IsUTF8(utf8_decode('éééé'))); } - public function testControlCharacterOOXML2PHP() - { - $this->assertEquals('', PHPWord_Shared_String::ControlCharacterOOXML2PHP('')); - $this->assertEquals(chr(0x08), PHPWord_Shared_String::ControlCharacterOOXML2PHP('_x0008_')); - } + public function testControlCharacterOOXML2PHP() + { + $this->assertEquals('', PHPWord_Shared_String::ControlCharacterOOXML2PHP('')); + $this->assertEquals(chr(0x08), PHPWord_Shared_String::ControlCharacterOOXML2PHP('_x0008_')); + } - public function testControlCharacterPHP2OOXML() - { - $this->assertEquals('', PHPWord_Shared_String::ControlCharacterPHP2OOXML('')); - $this->assertEquals('_x0008_', PHPWord_Shared_String::ControlCharacterPHP2OOXML(chr(0x08))); - } + public function testControlCharacterPHP2OOXML() + { + $this->assertEquals('', PHPWord_Shared_String::ControlCharacterPHP2OOXML('')); + $this->assertEquals('_x0008_', PHPWord_Shared_String::ControlCharacterPHP2OOXML(chr(0x08))); + } } diff --git a/Tests/PHPWord/Writer/ODText/ContentTest.php b/Tests/PHPWord/Writer/ODText/ContentTest.php new file mode 100644 index 00000000..63b84d75 --- /dev/null +++ b/Tests/PHPWord/Writer/ODText/ContentTest.php @@ -0,0 +1,65 @@ + + */ + public function testWriteContent() + { + $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') + ); + $expected = 'Expected'; + + $PHPWord = new PHPWord(); + $PHPWord->setDefaultFontName('Verdana'); + $PHPWord->addFontStyle('Font', array('size' => 11)); + $PHPWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $section = $PHPWord->createSection(); + $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->addPageBreak(); + $section->addTable(); + $section->addListItem('Test list item'); + $section->addImage($imageSrc); + $section->addObject($objectSrc); + $section->addTOC(); + $textrun = $section->createTextRun(); + $textrun->addText('Test text run'); + $doc = TestHelperDOCX::getDocument($PHPWord, 'ODText'); + + $element = "/office:document-content/office:body/office:text/text:p"; + $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue); + } +} diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/Tests/PHPWord/Writer/Word2007Test.php index df58d737..95abee83 100644 --- a/Tests/PHPWord/Writer/Word2007Test.php +++ b/Tests/PHPWord/Writer/Word2007Test.php @@ -103,7 +103,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase */ public function testSetGetUseDiskCaching() { - $object = new PHPWord_Writer_Word2007($phpWord); + $object = new PHPWord_Writer_Word2007(); $object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); $this->assertTrue($object->getUseDiskCaching()); @@ -120,7 +120,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase array(\PHPWORD_TESTS_DIR_ROOT, 'foo') ); - $object = new PHPWord_Writer_Word2007($phpWord); + $object = new PHPWord_Writer_Word2007(); $object->setUseDiskCaching(true, $dir); } } diff --git a/Tests/_inc/TestHelperDOCX.php b/Tests/_inc/TestHelperDOCX.php index 5f8e51a3..dec1f077 100644 --- a/Tests/_inc/TestHelperDOCX.php +++ b/Tests/_inc/TestHelperDOCX.php @@ -12,14 +12,14 @@ class TestHelperDOCX * @param \PHPWord $PHPWord * @return \PHPWord\Tests\XmlDocument */ - public static function getDocument(PHPWord $PHPWord) + public static function getDocument(PHPWord $PHPWord, $writer = 'Word2007') { self::$file = tempnam(sys_get_temp_dir(), 'PHPWord'); if (!is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) { mkdir(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); } - $objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); + $objWriter = \PHPWord_IOFactory::createWriter($PHPWord, $writer); $objWriter->save(self::$file); $zip = new \ZipArchive;