PHPWord/Tests/PHPWord/Style/FontTest.php

80 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace PHPWord\Tests\Style;
use PHPUnit_Framework_TestCase;
use PHPWord;
use PHPWord_Style_Font;
/**
* Class FontTest
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class FontTest extends \PHPUnit_Framework_TestCase
{
/**
* Test initiation for style type and paragraph style
*/
public function testInitiation()
{
$object = new PHPWord_Style_Font('text', array('align' => 'both'));
$this->assertEquals('text', $object->getStyleType());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $object->getParagraphStyle());
}
/**
* Test setting style values with null or empty value
*/
public function testSetStyleValueWithNullOrEmpty()
{
$object = new PHPWord_Style_Font();
$attributes = array(
'name' => PHPWord::DEFAULT_FONT_NAME,
'size' => PHPWord::DEFAULT_FONT_SIZE,
'bold' => false,
'italic' => false,
'superScript' => false,
'subScript' => false,
'underline' => PHPWord_Style_Font::UNDERLINE_NONE,
'strikethrough' => false,
'color' => PHPWord::DEFAULT_FONT_COLOR,
'fgColor' => null,
);
foreach ($attributes as $key => $default) {
2014-03-09 21:59:23 +07:00
$get = "get{$key}";
$object->setStyleValue("_$key", null);
2014-03-09 21:59:23 +07:00
$this->assertEquals($default, $object->$get());
$object->setStyleValue("_$key", '');
2014-03-09 21:59:23 +07:00
$this->assertEquals($default, $object->$get());
}
}
/**
* Test setting style values with normal value
*/
public function testSetStyleValueNormal()
{
$object = new PHPWord_Style_Font();
$attributes = array(
'name' => 'Times New Roman',
'size' => 9,
'bold' => true,
'italic' => true,
'superScript' => true,
'subScript' => true,
'underline' => PHPWord_Style_Font::UNDERLINE_HEAVY,
'strikethrough' => true,
'color' => '999999',
'fgColor' => '999999',
);
foreach ($attributes as $key => $value) {
2014-03-09 21:59:23 +07:00
$get = "get{$key}";
$object->setStyleValue("_$key", $value);
2014-03-09 21:59:23 +07:00
$this->assertEquals($value, $object->$get());
}
}
}