Update tests
This commit is contained in:
parent
33570f7cd4
commit
415d9b95c4
@ -77,7 +77,7 @@ class SDT extends Text
|
|||||||
public function setType($value)
|
public function setType($value)
|
||||||
{
|
{
|
||||||
$enum = array('comboBox', 'dropDownList', 'date');
|
$enum = array('comboBox', 'dropDownList', 'date');
|
||||||
$this->type = $this->setEnumVal($value, $enum, $this->type);
|
$this->type = $this->setEnumVal($value, $enum, 'comboBox');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,14 +99,10 @@ class PhpWord
|
|||||||
/**
|
/**
|
||||||
* Dynamic function call to reduce static dependency
|
* Dynamic function call to reduce static dependency
|
||||||
*
|
*
|
||||||
* Usage:
|
|
||||||
* - Getting and adding collections (Titles, Footnotes, and Endnotes)
|
|
||||||
* - Adding style
|
|
||||||
*
|
|
||||||
* @param mixed $function
|
* @param mixed $function
|
||||||
* @param mixed $args
|
* @param mixed $args
|
||||||
|
* @throws \BadMethodCallException
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
|
||||||
* @since 0.12.0
|
* @since 0.12.0
|
||||||
*/
|
*/
|
||||||
public function __call($function, $args)
|
public function __call($function, $args)
|
||||||
@ -149,6 +145,9 @@ class PhpWord
|
|||||||
if (in_array($function, $addStyle)) {
|
if (in_array($function, $addStyle)) {
|
||||||
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
|
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exception
|
||||||
|
throw new \BadMethodCallException("Method $function is not defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -19,8 +19,6 @@ namespace PhpOffice\PhpWord\Tests\Element;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Element\AbstractElement
|
* Test class for PhpOffice\PhpWord\Element\AbstractElement
|
||||||
*
|
|
||||||
* @runTestsInSeparateProcesses
|
|
||||||
*/
|
*/
|
||||||
class AbstractElementTest extends \PHPUnit_Framework_TestCase
|
class AbstractElementTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|||||||
69
tests/PhpWord/Tests/Element/SDTTest.php
Normal file
69
tests/PhpWord/Tests/Element/SDTTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?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.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Tests\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Element\SDT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for PhpOffice\PhpWord\Element\SDT
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \PhpOffice\PhpWord\Element\SDT
|
||||||
|
*/
|
||||||
|
class SDTTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create new instance
|
||||||
|
*/
|
||||||
|
public function testConstruct()
|
||||||
|
{
|
||||||
|
$types = array('comboBox', 'dropDownList', 'date');
|
||||||
|
$type = $types[rand(0, 2)];
|
||||||
|
$value = rand(0, 100);
|
||||||
|
$object = new SDT($type);
|
||||||
|
$object->setValue($value);;
|
||||||
|
$object->setListItems($types);;
|
||||||
|
|
||||||
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\SDT', $object);
|
||||||
|
$this->assertEquals($type, $object->getType());
|
||||||
|
$this->assertEquals($types, $object->getListItems());
|
||||||
|
$this->assertEquals($value, $object->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set type exception
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
* @expectedExceptionMessage Invalid style value
|
||||||
|
*/
|
||||||
|
public function testSetTypeException()
|
||||||
|
{
|
||||||
|
$object = new SDT('comboBox');
|
||||||
|
$object->setType('foo');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set type
|
||||||
|
*/
|
||||||
|
public function testSetTypeNull()
|
||||||
|
{
|
||||||
|
$object = new SDT('comboBox');
|
||||||
|
$object->setType(' ');
|
||||||
|
|
||||||
|
$this->assertEquals('comboBox', $object->getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -157,4 +157,16 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertTrue($phpWord->save('test.docx', 'Word2007', true));
|
$this->assertTrue($phpWord->save('test.docx', 'Word2007', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test calling undefined method
|
||||||
|
*
|
||||||
|
* @expectedException \BadMethodCallException
|
||||||
|
* @expectedExceptionMessage is not defined
|
||||||
|
*/
|
||||||
|
public function testCallUndefinedMethod()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->undefinedMethod();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,4 +64,12 @@ class StringTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('\uc0{\u8364}', String::toUnicode('€'));
|
$this->assertEquals('\uc0{\u8364}', String::toUnicode('€'));
|
||||||
$this->assertEquals('\uc0{\u233}', String::toUnicode('é'));
|
$this->assertEquals('\uc0{\u233}', String::toUnicode('é'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test remove underscore prefix
|
||||||
|
*/
|
||||||
|
public function testRemoveUnderscorePrefix()
|
||||||
|
{
|
||||||
|
$this->assertEquals('item', String::removeUnderscorePrefix('_item'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user