Skip to content

Commit 307f568

Browse files
committed
Add unit tests for Shared/Font and Writer/Word2007/Styles
1 parent 35c48dc commit 307f568

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

Tests/PHPWord/Shared/FontTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace PHPWord\Tests;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord;
6+
use PHPWord_Shared_Font;
7+
8+
/**
9+
* Class PHPWord_Writer_Shared_FontTest
10+
*
11+
* @package PHPWord\Tests
12+
* @runTestsInSeparateProcesses
13+
*/
14+
class PHPWord_Writer_Shared_FontTest extends \PHPUnit_Framework_TestCase
15+
{
16+
17+
/**
18+
* Test various conversions
19+
*/
20+
public function testConversions()
21+
{
22+
$PHPWord = new PHPWord();
23+
24+
$original = 1;
25+
26+
$result = PHPWord_Shared_Font::fontSizeToPixels($original);
27+
$this->assertEquals($original * 16 / 12, $result);
28+
29+
$result = PHPWord_Shared_Font::inchSizeToPixels($original);
30+
$this->assertEquals($original * 96, $result);
31+
32+
$result = PHPWord_Shared_Font::centimeterSizeToPixels($original);
33+
$this->assertEquals($original * 37.795275591, $result);
34+
35+
$result = PHPWord_Shared_Font::centimeterSizeToTwips($original);
36+
$this->assertEquals($original * 565.217, $result);
37+
38+
$result = PHPWord_Shared_Font::inchSizeToTwips($original);
39+
$this->assertEquals($original * 565.217 * 2.54, $result);
40+
41+
$result = PHPWord_Shared_Font::pixelSizeToTwips($original);
42+
$this->assertEquals($original * 565.217 / 37.795275591, $result);
43+
44+
$result = PHPWord_Shared_Font::pointSizeToTwips($original);
45+
$this->assertEquals($original * 20, $result);
46+
}
47+
48+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace PHPWord\Tests;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use PHPWord;
6+
use PHPWord_Writer_Word2007_Styles;
7+
8+
/**
9+
* Class PHPWord_Writer_Word2007_StylesTest
10+
* @package PHPWord\Tests
11+
* @runTestsInSeparateProcesses
12+
*/
13+
class PHPWord_Writer_Word2007_StylesTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* Executed before each method of the class
17+
*/
18+
public function tearDown()
19+
{
20+
TestHelperDOCX::clear();
21+
}
22+
23+
/**
24+
* Test write styles
25+
*/
26+
public function testWriteStyles()
27+
{
28+
$PHPWord = new PHPWord();
29+
30+
$defaultStyle = array('align' => 'both');
31+
$baseStyle = array('basedOn' => 'Normal');
32+
$newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal');
33+
$PHPWord->setDefaultParagraphStyle($defaultStyle);
34+
$PHPWord->addParagraphStyle('Base Style', $baseStyle);
35+
$PHPWord->addParagraphStyle('New Style', $newStyle);
36+
$doc = TestHelperDOCX::getDocument($PHPWord);
37+
$file = 'word/styles.xml';
38+
39+
// Normal style generated?
40+
$path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
41+
$element = $doc->getElement($path, $file);
42+
$this->assertEquals('Normal', $element->getAttribute('w:val'));
43+
44+
// Parent style referenced?
45+
$path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
46+
$element = $doc->getElement($path, $file);
47+
$this->assertEquals('Base Style', $element->getAttribute('w:val'));
48+
49+
// Next paragraph style correct?
50+
$path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
51+
$element = $doc->getElement($path, $file);
52+
$this->assertEquals('Normal', $element->getAttribute('w:val'));
53+
}
54+
55+
}

0 commit comments

Comments
 (0)