PHPWord/tests/PhpWord/Style/AbstractStyleTest.php

92 lines
3.3 KiB
PHP
Raw Normal View History

2014-04-12 12:57:51 +07:00
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
2014-04-12 12:57:51 +07:00
*
* @see https://github.com/PHPOffice/PHPWord
2018-03-08 23:52:25 +01:00
* @copyright 2010-2018 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2014-04-12 12:57:51 +07:00
*/
2015-11-15 13:33:05 +04:00
namespace PhpOffice\PhpWord\Style;
2014-04-12 12:57:51 +07:00
/**
* Test class for PhpOffice\PhpWord\Style\AbstractStyle
*
* @runTestsInSeparateProcesses
*/
class AbstractStyleTest extends \PHPUnit\Framework\TestCase
2014-04-12 12:57:51 +07:00
{
/**
* 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->assertTrue(self::callProtectedMethod($stub, 'setBoolVal', array(true, false)));
2014-04-12 12:57:51 +07:00
$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(871.1, self::callProtectedMethod($stub, 'setFloatVal', array('871.1', 2.1)));
2014-04-12 12:57:51 +07:00
$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');
2017-11-22 09:43:35 +01:00
$this->assertNotTrue(self::callProtectedMethod($stub, 'setBoolVal', array('a', false)));
2014-04-12 12:57:51 +07:00
$this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200)));
$this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1)));
2014-05-08 19:25:29 +07:00
$this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array(null, array('a', 'b'), 'b')));
}
/**
* Test setEnumVal exception
*/
public function testSetValEnumException()
{
$this->expectException(\InvalidArgumentException::class);
2014-05-08 19:25:29 +07:00
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle');
2014-04-12 12:57:51 +07:00
$this->assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', array('z', array('a', 'b'), 'b')));
}
/**
* Helper function to call protected method
2014-04-13 23:17:39 +07:00
*
* @param mixed $object
* @param string $method
* @param array $args
2014-04-12 12:57:51 +07:00
*/
public static function callProtectedMethod($object, $method, array $args = array())
{
$class = new \ReflectionClass(get_class($object));
$method = $class->getMethod($method);
$method->setAccessible(true);
2014-04-12 12:57:51 +07:00
return $method->invokeArgs($object, $args);
}
}