From 307f5689d9dd4f32fa54b5ea8a443f2306aca91d Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sat, 8 Mar 2014 01:26:02 +0700 Subject: [PATCH] Add unit tests for Shared/Font and Writer/Word2007/Styles --- Tests/PHPWord/Shared/FontTest.php | 48 +++++++++++++++++ Tests/PHPWord/Writer/Word2007/StylesTest.php | 55 ++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 Tests/PHPWord/Shared/FontTest.php create mode 100644 Tests/PHPWord/Writer/Word2007/StylesTest.php diff --git a/Tests/PHPWord/Shared/FontTest.php b/Tests/PHPWord/Shared/FontTest.php new file mode 100644 index 00000000..09603d5f --- /dev/null +++ b/Tests/PHPWord/Shared/FontTest.php @@ -0,0 +1,48 @@ +assertEquals($original * 16 / 12, $result); + + $result = PHPWord_Shared_Font::inchSizeToPixels($original); + $this->assertEquals($original * 96, $result); + + $result = PHPWord_Shared_Font::centimeterSizeToPixels($original); + $this->assertEquals($original * 37.795275591, $result); + + $result = PHPWord_Shared_Font::centimeterSizeToTwips($original); + $this->assertEquals($original * 565.217, $result); + + $result = PHPWord_Shared_Font::inchSizeToTwips($original); + $this->assertEquals($original * 565.217 * 2.54, $result); + + $result = PHPWord_Shared_Font::pixelSizeToTwips($original); + $this->assertEquals($original * 565.217 / 37.795275591, $result); + + $result = PHPWord_Shared_Font::pointSizeToTwips($original); + $this->assertEquals($original * 20, $result); + } + +} diff --git a/Tests/PHPWord/Writer/Word2007/StylesTest.php b/Tests/PHPWord/Writer/Word2007/StylesTest.php new file mode 100644 index 00000000..42bde30f --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/StylesTest.php @@ -0,0 +1,55 @@ + 'both'); + $baseStyle = array('basedOn' => 'Normal'); + $newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal'); + $PHPWord->setDefaultParagraphStyle($defaultStyle); + $PHPWord->addParagraphStyle('Base Style', $baseStyle); + $PHPWord->addParagraphStyle('New Style', $newStyle); + $doc = TestHelperDOCX::getDocument($PHPWord); + $file = 'word/styles.xml'; + + // Normal style generated? + $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name'; + $element = $doc->getElement($path, $file); + $this->assertEquals('Normal', $element->getAttribute('w:val')); + + // Parent style referenced? + $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn'; + $element = $doc->getElement($path, $file); + $this->assertEquals('Base Style', $element->getAttribute('w:val')); + + // Next paragraph style correct? + $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next'; + $element = $doc->getElement($path, $file); + $this->assertEquals('Normal', $element->getAttribute('w:val')); + } + +}