Add unit tests for Shared/Font and Writer/Word2007/Styles

This commit is contained in:
Ivan Lanin 2014-03-08 01:26:02 +07:00
parent 35c48dc155
commit 307f5689d9
2 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord;
use PHPWord_Shared_Font;
/**
* Class PHPWord_Writer_Shared_FontTest
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class PHPWord_Writer_Shared_FontTest extends \PHPUnit_Framework_TestCase
{
/**
* Test various conversions
*/
public function testConversions()
{
$PHPWord = new PHPWord();
$original = 1;
$result = PHPWord_Shared_Font::fontSizeToPixels($original);
$this->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);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord;
use PHPWord_Writer_Word2007_Styles;
/**
* Class PHPWord_Writer_Word2007_StylesTest
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class PHPWord_Writer_Word2007_StylesTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
*/
public function tearDown()
{
TestHelperDOCX::clear();
}
/**
* Test write styles
*/
public function testWriteStyles()
{
$PHPWord = new PHPWord();
$defaultStyle = array('align' => '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'));
}
}