Enhance unit tests
This commit is contained in:
parent
8d2c6ebd16
commit
a218202dbd
|
|
@ -97,6 +97,8 @@ class Section extends Container
|
|||
*
|
||||
* @param mixed $styleFont
|
||||
* @param mixed $styleTOC
|
||||
* @param integer $minDepth
|
||||
* @param integer $maxDepth
|
||||
* @return TOC
|
||||
*/
|
||||
public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
|
||||
|
|
|
|||
|
|
@ -102,10 +102,13 @@ class Image extends Element
|
|||
// Check supported types
|
||||
if ($this->isMemImage) {
|
||||
$supportedTypes = array('image/jpeg', 'image/gif', 'image/png');
|
||||
$imgData = getimagesize($source);
|
||||
$imgData = @getimagesize($source);
|
||||
if (!is_array($imgData)) {
|
||||
throw new InvalidImageException();
|
||||
}
|
||||
$this->imageType = $imgData['mime']; // string
|
||||
if (!in_array($this->imageType, $supportedTypes)) {
|
||||
throw new UnsupportedImageTypeException;
|
||||
throw new UnsupportedImageTypeException();
|
||||
}
|
||||
} else {
|
||||
$supportedTypes = array(
|
||||
|
|
@ -114,17 +117,19 @@ class Image extends Element
|
|||
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
|
||||
);
|
||||
if (!file_exists($source)) {
|
||||
throw new InvalidImageException;
|
||||
throw new InvalidImageException();
|
||||
}
|
||||
$imgData = getimagesize($source);
|
||||
if (function_exists('exif_imagetype')) {
|
||||
$this->imageType = exif_imagetype($source);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
$tmp = getimagesize($source);
|
||||
$this->imageType = $tmp[2];
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (!in_array($this->imageType, $supportedTypes)) {
|
||||
throw new UnsupportedImageTypeException;
|
||||
throw new UnsupportedImageTypeException();
|
||||
}
|
||||
$this->imageType = \image_type_to_mime_type($this->imageType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ class TOC
|
|||
*
|
||||
* @param mixed $styleFont
|
||||
* @param array $styleTOC
|
||||
* @param integer $minDepth
|
||||
* @param integer $maxDepth
|
||||
*/
|
||||
public function __construct($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -229,7 +229,8 @@ class Word2007 extends Writer implements IWriter
|
|||
/**
|
||||
* Add header/footer content
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Container\Section $section
|
||||
* @param \PhpOffice\PhpWord\Container\Section $section
|
||||
* @param mixed $objZip
|
||||
* @param string $elmType
|
||||
* @param integer $rID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -60,9 +60,8 @@ class ContentTypes extends WriterPart
|
|||
* Write content types element
|
||||
*
|
||||
* @param XMLWriter $xmlWriter XML Writer
|
||||
* @param array $parts
|
||||
* @param boolean $isDefault
|
||||
* @param string $partName Part name
|
||||
* @param string $contentType Content type
|
||||
* @throws Exception
|
||||
*/
|
||||
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$iVal = rand(1, 1000);
|
||||
$oFooter->setRelationId($iVal);
|
||||
|
||||
$this->assertEquals($oFooter->getRelationId(), $iVal);
|
||||
$this->assertEquals(Footer::AUTO, $oFooter->getType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,4 +231,16 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$header = new Header(1);
|
||||
$header->addFootnote();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get type
|
||||
*/
|
||||
public function testSetGetType()
|
||||
{
|
||||
$object = new Header(1);
|
||||
$this->assertEquals(Header::AUTO, $object->getType());
|
||||
|
||||
$object->setType('ODD');
|
||||
$this->assertEquals(Header::AUTO, $object->getType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Tests\Container;
|
||||
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\Container\Section;
|
||||
use PhpOffice\PhpWord\Container\Header;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
|
||||
/**
|
||||
|
|
@ -141,4 +143,27 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
$this->assertFalse($object->hasDifferentFirstPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add header has different first page
|
||||
*/
|
||||
public function testHasDifferentFirstPage()
|
||||
{
|
||||
$object = new Section(1);
|
||||
$header = $object->addHeader();
|
||||
$header->setType(Header::FIRST);
|
||||
$this->assertTrue($object->hasDifferentFirstPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add header exception
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMesssage Invalid header/footer type.
|
||||
*/
|
||||
public function testAddHeaderException()
|
||||
{
|
||||
$object = new Section(1);
|
||||
$header = $object->addHeader('ODD');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,4 +192,14 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getImageFunction(), null);
|
||||
$this->assertEquals($oImage->getImageType(), 'image/tiff');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PHP Image
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
|
||||
*/
|
||||
public function testPhpImage()
|
||||
{
|
||||
$object = new Image('test.php');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue