From 589e603277e01793742888349f9bba9445d147c6 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 12 Mar 2014 00:12:55 +0700 Subject: [PATCH] Unit test for Reader and additional methods for DocumentProperties, adapted from PHPExcel --- Classes/PHPWord/DocumentProperties.php | 279 ++++++++++++++++++++++++- Classes/PHPWord/Reader/Word2007.php | 21 +- Classes/PHPWord/Writer/RTF.php | 2 +- Tests/PHPWord/Reader/Word2007.php | 69 ++++++ Tests/_files/documents/reader.docx | Bin 0 -> 14208 bytes Tests/_inc/TestHelperDOCX.php | 67 +----- Tests/_inc/XmlDocument.php | 66 ++++++ Tests/bootstrap.php | 1 + 8 files changed, 417 insertions(+), 88 deletions(-) create mode 100644 Tests/PHPWord/Reader/Word2007.php create mode 100644 Tests/_files/documents/reader.docx create mode 100644 Tests/_inc/XmlDocument.php diff --git a/Classes/PHPWord/DocumentProperties.php b/Classes/PHPWord/DocumentProperties.php index 7c2aec24..3fc097b4 100755 --- a/Classes/PHPWord/DocumentProperties.php +++ b/Classes/PHPWord/DocumentProperties.php @@ -30,6 +30,13 @@ */ class PHPWord_DocumentProperties { + /** Constants */ + const PROPERTY_TYPE_BOOLEAN = 'b'; + const PROPERTY_TYPE_INTEGER = 'i'; + const PROPERTY_TYPE_FLOAT = 'f'; + const PROPERTY_TYPE_DATE = 'd'; + const PROPERTY_TYPE_STRING = 's'; + const PROPERTY_TYPE_UNKNOWN = 'u'; /** * Creator @@ -101,21 +108,36 @@ class PHPWord_DocumentProperties */ private $_company; + /** + * Manager + * + * @var string + */ + private $_manager; + + /** + * Custom Properties + * + * @var string + */ + private $_customProperties = array(); + /** * Create new PHPWord_DocumentProperties */ public function __construct() { - $this->_creator = ''; + $this->_creator = ''; $this->_lastModifiedBy = $this->_creator; - $this->_created = time(); - $this->_modified = time(); - $this->_title = ''; - $this->_subject = ''; - $this->_description = ''; - $this->_keywords = ''; - $this->_category = ''; - $this->_company = ''; + $this->_created = time(); + $this->_modified = time(); + $this->_title = ''; + $this->_subject = ''; + $this->_description = ''; + $this->_keywords = ''; + $this->_category = ''; + $this->_company = ''; + $this->_manager = ''; } /** @@ -343,4 +365,243 @@ class PHPWord_DocumentProperties $this->_company = $pValue; return $this; } + + /** + * Get Manager + * + * @return string + */ + public function getManager() + { + return $this->_manager; + } + + /** + * Set Manager + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setManager($pValue = '') + { + $this->_manager = $pValue; + return $this; + } + + /** + * Get a List of Custom Property Names + * + * @return array of string + */ + public function getCustomProperties() + { + return array_keys($this->_customProperties); + } + + /** + * Check if a Custom Property is defined + * + * @param string $propertyName + * @return boolean + */ + public function isCustomPropertySet($propertyName) + { + return isset($this->_customProperties[$propertyName]); + } + + /** + * Get a Custom Property Value + * + * @param string $propertyName + * @return string + */ + public function getCustomPropertyValue($propertyName) + { + if (isset($this->_customProperties[$propertyName])) { + return $this->_customProperties[$propertyName]['value']; + } + + } + + /** + * Get a Custom Property Type + * + * @param string $propertyName + * @return string + */ + public function getCustomPropertyType($propertyName) + { + if (isset($this->_customProperties[$propertyName])) { + return $this->_customProperties[$propertyName]['type']; + } + + } + + /** + * Set a Custom Property + * + * @param string $propertyName + * @param mixed $propertyValue + * @param string $propertyType + * 'i': Integer + * 'f': Floating Point + * 's': String + * 'd': Date/Time + * 'b': Boolean + * @return PHPExcel_DocumentProperties + */ + public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null) + { + if (($propertyType === null) || (!in_array($propertyType, array( + self::PROPERTY_TYPE_INTEGER, + self::PROPERTY_TYPE_FLOAT, + self::PROPERTY_TYPE_STRING, + self::PROPERTY_TYPE_DATE, + self::PROPERTY_TYPE_BOOLEAN + )))) { + if ($propertyValue === null) { + $propertyType = self::PROPERTY_TYPE_STRING; + } elseif (is_float($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_FLOAT; + } elseif (is_int($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_INTEGER; + } elseif (is_bool($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_BOOLEAN; + } else { + $propertyType = self::PROPERTY_TYPE_STRING; + } + } + + $this->_customProperties[$propertyName] = array( + 'value' => $propertyValue, + 'type' => $propertyType + ); + return $this; + } + + /** + * Convert document propery based on type + * + * @param mixed $propertyValue + * @param string $propertyType + * @return mixed + */ + public static function convertProperty($propertyValue, $propertyType) + { + switch ($propertyType) { + case 'empty': // Empty + return ''; + break; + case 'null': // Null + return null; + break; + case 'i1': // 1-Byte Signed Integer + case 'i2': // 2-Byte Signed Integer + case 'i4': // 4-Byte Signed Integer + case 'i8': // 8-Byte Signed Integer + case 'int': // Integer + return (int) $propertyValue; + break; + case 'ui1': // 1-Byte Unsigned Integer + case 'ui2': // 2-Byte Unsigned Integer + case 'ui4': // 4-Byte Unsigned Integer + case 'ui8': // 8-Byte Unsigned Integer + case 'uint': // Unsigned Integer + return abs((int) $propertyValue); + break; + case 'r4': // 4-Byte Real Number + case 'r8': // 8-Byte Real Number + case 'decimal': // Decimal + return (float) $propertyValue; + break; + case 'lpstr': // LPSTR + case 'lpwstr': // LPWSTR + case 'bstr': // Basic String + return $propertyValue; + break; + case 'date': // Date and Time + case 'filetime': // File Time + return strtotime($propertyValue); + break; + case 'bool': // Boolean + return ($propertyValue == 'true') ? true : false; + break; + case 'cy': // Currency + case 'error': // Error Status Code + case 'vector': // Vector + case 'array': // Array + case 'blob': // Binary Blob + case 'oblob': // Binary Blob Object + case 'stream': // Binary Stream + case 'ostream': // Binary Stream Object + case 'storage': // Binary Storage + case 'ostorage': // Binary Storage Object + case 'vstream': // Binary Versioned Stream + case 'clsid': // Class ID + case 'cf': // Clipboard Data + return $propertyValue; + break; + } + + return $propertyValue; + } + + /** + * Convert document property type + * + * @param string $propertyType + * @return mixed + */ + public static function convertPropertyType($propertyType) + { + switch ($propertyType) { + case 'i1': // 1-Byte Signed Integer + case 'i2': // 2-Byte Signed Integer + case 'i4': // 4-Byte Signed Integer + case 'i8': // 8-Byte Signed Integer + case 'int': // Integer + case 'ui1': // 1-Byte Unsigned Integer + case 'ui2': // 2-Byte Unsigned Integer + case 'ui4': // 4-Byte Unsigned Integer + case 'ui8': // 8-Byte Unsigned Integer + case 'uint': // Unsigned Integer + return self::PROPERTY_TYPE_INTEGER; + break; + case 'r4': // 4-Byte Real Number + case 'r8': // 8-Byte Real Number + case 'decimal': // Decimal + return self::PROPERTY_TYPE_FLOAT; + break; + case 'empty': // Empty + case 'null': // Null + case 'lpstr': // LPSTR + case 'lpwstr': // LPWSTR + case 'bstr': // Basic String + return self::PROPERTY_TYPE_STRING; + break; + case 'date': // Date and Time + case 'filetime': // File Time + return self::PROPERTY_TYPE_DATE; + break; + case 'bool': // Boolean + return self::PROPERTY_TYPE_BOOLEAN; + break; + case 'cy': // Currency + case 'error': // Error Status Code + case 'vector': // Vector + case 'array': // Array + case 'blob': // Binary Blob + case 'oblob': // Binary Blob Object + case 'stream': // Binary Stream + case 'ostream': // Binary Stream Object + case 'storage': // Binary Storage + case 'ostorage': // Binary Storage Object + case 'vstream': // Binary Versioned Stream + case 'clsid': // Class ID + case 'cf': // Clipboard Data + return self::PROPERTY_TYPE_UNKNOWN; + break; + } + return self::PROPERTY_TYPE_UNKNOWN; + } } diff --git a/Classes/PHPWord/Reader/Word2007.php b/Classes/PHPWord/Reader/Word2007.php index ebe5ef9c..c1886e42 100644 --- a/Classes/PHPWord/Reader/Word2007.php +++ b/Classes/PHPWord/Reader/Word2007.php @@ -38,7 +38,6 @@ if (!defined('PHPWORD_BASE_PATH')) { class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord_Reader_IReader { - /** * Create a new PHPWord_Reader_Word2007 instance */ @@ -57,8 +56,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements // Check if file exists if (!file_exists($pFilename)) { throw new PHPWord_Exception( - "Could not open " . $pFilename . - " for reading! File does not exist." + "Could not open {$pFilename} for reading! File does not exist." ); } @@ -123,16 +121,13 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements * Loads PHPWord from file * * @param string $pFilename - * @return PHPWord + * @return PHPWord|null */ public function load($pFilename) { - // Check if file exists - if (!file_exists($pFilename)) { - throw new PHPWord_Exception( - "Could not open " . $pFilename . - " for reading! File does not exist." - ); + // Check if file exists and can be read + if (!$this->canRead($pFilename)) { + return; } // Initialisations @@ -211,7 +206,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements foreach ($xmlDoc->body->children() as $elm) { $elmName = $elm->getName(); if ($elmName == 'p') { // Paragraph/section - // Create new section if section section found + // Create new section if section setting found if ($elm->pPr->sectPr) { $section->setSettings($this->loadSectionSettings($elm->pPr)); $section = $word->createSection(); @@ -262,8 +257,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements } unset($pStyle); unset($fStyle); - $hasParagraphStyle = $elm->pPr && ($elm->pPr != ''); - $hasFontStyle = $elm->rPr && ($elm->rPr != ''); + $hasParagraphStyle = isset($elm->pPr); + $hasFontStyle = isset($elm->rPr); $styleName = (string)$elm->name['val']; if ($hasParagraphStyle) { $pStyle = $this->loadParagraphStyle($elm); diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index c730c9c3..66ec7383 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -411,7 +411,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter if ($this->_lastParagraphStyle != '' || $styleFont) { $sRTFText .= ' '; } - $sRTFText .= $text->getDataContentText(); + $sRTFText .= $text->getText(); if ($styleFont) { $sRTFText .= '\cf0'; diff --git a/Tests/PHPWord/Reader/Word2007.php b/Tests/PHPWord/Reader/Word2007.php new file mode 100644 index 00000000..cbd500ff --- /dev/null +++ b/Tests/PHPWord/Reader/Word2007.php @@ -0,0 +1,69 @@ +assertTrue($object->canRead($file)); + } + + /** + * Test canRead() failure + * + * @expectedException Exception + */ + public function testCanReadFailed() + { + $dir = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents') + ); + $object = new PHPWord_Reader_Word2007; + $file = $dir . DIRECTORY_SEPARATOR . 'foo.docx'; + $this->assertFalse($object->canRead($file)); + $object = PHPWord_IOFactory::load($file); + } + + /** + * Test load document + */ + public function testLoad() + { + $dir = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents') + ); + $file = $dir . DIRECTORY_SEPARATOR . 'reader.docx'; + $object = PHPWord_IOFactory::load($file); + $this->assertInstanceOf('PHPWord', $object); + } +} diff --git a/Tests/_files/documents/reader.docx b/Tests/_files/documents/reader.docx new file mode 100644 index 0000000000000000000000000000000000000000..e2ceeb646e699713e15fb13b7f0da74be49688ee GIT binary patch literal 14208 zcmeHO1y>!(wmwLZ0Kwe}!QBZK+}+*X4-niXxChtZ9^5s!6Wrb19p0I_ckay1o%jC0 zyM5N`)!kL!?&>=Gt6jDCE;&gENHhQx00sa65CgtB*6G-R0RR(k002|~47jGCt&O9x zjiauTtDUifHl2&L711|HaEdGdIH>-AkN?L#P!m67)5U-!eEanQF{WPGVDDQo6?hnL z0I03u})#{hC0M6YEt8m zEUyyys%Wz9B(P4ijHtz|#@k!>BUHc?L@W{|*o5I_)5tmBP%ErMa1<-?YWOEwXL4+bQtHTUdOBFCuhT(~@;(L6LDb&sb{5lfwL*&FjE zGFx5bChR2^IYQQy`+L&tYZFuVn@~pVQ&L@w52kzZv%R&keABmKxT7e(ljH7RVow>* zrJcO$yt)Y}5c5U@x`CmRvCcy4D#5uQYogy0j&G;;io(SwR-%JV!PQWx7`xJLjKS+f zFwLt-64XEVRl5kX)_P+;;MiOi_BNsjI{lk8l|xpby2z4n4*{yB((B!uJt9u zFn5Skyy3kg&b2*Sz!@bL%->h@NM9Wf08FHm#3V-mX!qY;>Ks1hUXaxfMA{3laG#}eDI%yi;YYGmwLHY9!iv$;)X}lZ z7`Kp-oVxZE`o^I!&iJJ^-smG9i!pDOBz;7b{|-y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aS2y&p=wID&f8vSW|MB_%a?bq<{&&;-ClmmXr~k{V|1i|Q l!vB59{44y9@vrcI4WM$8Z$LT<03d*VA|N#close(); } - return new Xml_Document(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); + return new XmlDocument(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); } public static function clear() @@ -60,65 +59,3 @@ class TestHelperDOCX rmdir($dir); } } - -class Xml_Document -{ - /** @var string $path */ - private $path; - - /** @var \DOMDocument $dom */ - private $dom; - - /** @var \DOMXpath $xpath */ - private $xpath; - - /** @var string $file */ - private $file; - - /** - * @param string $path - */ - public function __construct($path) - { - $this->path = realpath($path); - } - - /** - * @param string $file - * @return \DOMDocument - */ - public function getFileDom($file = 'word/document.xml') - { - if (null !== $this->dom && $file === $this->file) { - return $this->dom; - } - - $this->xpath = null; - $this->file = $file; - - $file = $this->path . '/' . $file; - $this->dom = new DOMDocument(); - $this->dom->load($file); - return $this->dom; - } - - /** - * @param string $path - * @param string $file - * @return \DOMElement - */ - public function getElement($path, $file = 'word/document.xml') - { - if ($this->dom === null || $file !== $this->file) { - $this->getFileDom($file); - } - - if (null === $this->xpath) { - $this->xpath = new \DOMXpath($this->dom); - - } - - $elements = $this->xpath->query($path); - return $elements->item(0); - } -} diff --git a/Tests/_inc/XmlDocument.php b/Tests/_inc/XmlDocument.php new file mode 100644 index 00000000..2ec27a3b --- /dev/null +++ b/Tests/_inc/XmlDocument.php @@ -0,0 +1,66 @@ +path = realpath($path); + } + + /** + * @param string $file + * @return \DOMDocument + */ + public function getFileDom($file = 'word/document.xml') + { + if (null !== $this->dom && $file === $this->file) { + return $this->dom; + } + + $this->xpath = null; + $this->file = $file; + + $file = $this->path . '/' . $file; + $this->dom = new DOMDocument(); + $this->dom->load($file); + return $this->dom; + } + + /** + * @param string $path + * @param string $file + * @return \DOMElement + */ + public function getElement($path, $file = 'word/document.xml') + { + if ($this->dom === null || $file !== $this->file) { + $this->getFileDom($file); + } + + if (null === $this->xpath) { + $this->xpath = new \DOMXpath($this->dom); + + } + + $elements = $this->xpath->query($path); + return $elements->item(0); + } +} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 916d3503..1066a0d4 100755 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -12,3 +12,4 @@ require_once __DIR__ . '/../Classes/PHPWord/Autoloader.php'; PHPWord_Autoloader::Register(); require_once __DIR__ . '/_inc/TestHelperDOCX.php'; +require_once __DIR__ . '/_inc/XmlDocument.php';