diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php index 45ba17a7..ea77dc70 100644 --- a/src/PhpWord/Style/AbstractStyle.php +++ b/src/PhpWord/Style/AbstractStyle.php @@ -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; } diff --git a/tests/PhpWord/Tests/Element/AbstractElementTest.php b/tests/PhpWord/Tests/Element/AbstractElementTest.php index 81080232..8dbfb5b3 100644 --- a/tests/PhpWord/Tests/Element/AbstractElementTest.php +++ b/tests/PhpWord/Tests/Element/AbstractElementTest.php @@ -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 */ diff --git a/tests/PhpWord/Tests/Style/AbstractStyleTest.php b/tests/PhpWord/Tests/Style/AbstractStyleTest.php new file mode 100644 index 00000000..a9eace9d --- /dev/null +++ b/tests/PhpWord/Tests/Style/AbstractStyleTest.php @@ -0,0 +1,66 @@ +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); + } +} diff --git a/tests/PhpWord/Tests/Style/ListItemTest.php b/tests/PhpWord/Tests/Style/ListItemTest.php index 0fb67da3..6eef720c 100644 --- a/tests/PhpWord/Tests/Style/ListItemTest.php +++ b/tests/PhpWord/Tests/Style/ListItemTest.php @@ -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()); + } }