Unit test for AbstractStyle
This commit is contained in:
parent
47956b019c
commit
9bb5655292
|
|
@ -105,13 +105,12 @@ abstract class AbstractStyle
|
|||
/**
|
||||
* Set integer value
|
||||
*
|
||||
* @param integer|null $value
|
||||
* @param mixed $value
|
||||
* @param integer|null $default
|
||||
* @return integer|null
|
||||
*/
|
||||
protected function setIntVal($value, $default = null)
|
||||
{
|
||||
$value = intval($value);
|
||||
if (!is_int($value)) {
|
||||
$value = $default;
|
||||
}
|
||||
|
|
@ -128,7 +127,6 @@ abstract class AbstractStyle
|
|||
*/
|
||||
protected function setFloatVal($value, $default = null)
|
||||
{
|
||||
$value = floatval($value);
|
||||
if (!is_float($value)) {
|
||||
$value = $default;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
namespace PhpOffice\PhpWord\Tests\Element;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Element\Cell
|
||||
* Test class for PhpOffice\PhpWord\Element\AbstractElement
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
|
|
@ -26,6 +26,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase
|
|||
$stub->setElementIndex($ival);
|
||||
$this->assertEquals($stub->getElementIndex(), $ival);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set/get element unique Id
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Tests\Style;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Style\AbstractStyle
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class AbstractStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test set style by array
|
||||
*/
|
||||
public function testSetStyleByArray()
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||
$stub->setStyleByArray(array('index' => 1));
|
||||
|
||||
$this->assertEquals(1, $stub->getIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setBoolVal, setIntVal, setFloatVal, setEnumVal with normal value
|
||||
*/
|
||||
public function testSetValNormal()
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||
|
||||
$this->assertEquals(true, self::callProtectedMethod($stub, 'setBoolVal', array(true, false)));
|
||||
$this->assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', array(12, 200)));
|
||||
$this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array(871.1, 2.1)));
|
||||
$this->assertEquals('a', self::callProtectedMethod($stub, 'setEnumVal', array('a', array('a', 'b'), 'b')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setBoolVal, setIntVal, setFloatVal, setEnumVal with default value
|
||||
*/
|
||||
public function testSetValDefault()
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
|
||||
|
||||
$this->assertEquals(false, self::callProtectedMethod($stub, 'setBoolVal', array('a', false)));
|
||||
$this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200)));
|
||||
$this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1)));
|
||||
$this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to call protected method
|
||||
*/
|
||||
public static function callProtectedMethod($object, $method, array $args = array())
|
||||
{
|
||||
$class = new \ReflectionClass(get_class($object));
|
||||
$method = $class->getMethod($method);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($object, $args);
|
||||
}
|
||||
}
|
||||
|
|
@ -53,4 +53,16 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
|||
$object->setListType($value);
|
||||
$this->assertEquals($value, $object->getListType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set/get numbering style name
|
||||
*/
|
||||
public function testSetGetNumStyle()
|
||||
{
|
||||
$expected = 'List Name';
|
||||
|
||||
$object = new ListItem();
|
||||
$object->setNumStyle($expected);
|
||||
$this->assertEquals($expected, $object->getNumStyle());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue