PHPWord/Tests/PhpWord/Section/MemoryImageTest.php

94 lines
3.7 KiB
PHP
Raw Normal View History

2014-03-09 19:09:22 +01:00
<?php
namespace PhpWord\Tests\Section;
2014-03-09 19:09:22 +01:00
use PhpOffice\PhpWord\Section\MemoryImage;
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
class MemoryImageTest extends \PHPUnit_Framework_TestCase
{
public function testPNG()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'firefox.png')
2014-03-09 15:04:23 -04:00
);
$oMemoryImage = new MemoryImage($src);
2014-03-09 19:09:22 +01:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
2014-03-09 15:04:23 -04:00
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng');
$this->assertEquals($oMemoryImage->getImageExtension(), 'png');
$this->assertEquals($oMemoryImage->getImageType(), 'image/png');
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testGIF()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'mario.gif')
2014-03-09 15:04:23 -04:00
);
$oMemoryImage = new MemoryImage($src);
2014-03-09 19:09:22 +01:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
2014-03-09 15:04:23 -04:00
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif');
$this->assertEquals($oMemoryImage->getImageExtension(), 'gif');
$this->assertEquals($oMemoryImage->getImageType(), 'image/gif');
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testJPG()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
2014-03-09 15:04:23 -04:00
);
$oMemoryImage = new MemoryImage($src);
2014-03-09 19:09:22 +01:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
2014-03-09 15:04:23 -04:00
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg');
$this->assertEquals($oMemoryImage->getImageExtension(), 'jpg');
$this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg');
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testBMP()
{
$oMemoryImage = new MemoryImage(\join(
2014-03-09 15:04:23 -04:00
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'duke_nukem.bmp')
2014-03-09 15:04:23 -04:00
));
2014-03-09 19:09:22 +01:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
2014-03-09 15:04:23 -04:00
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
$this->assertEquals($oMemoryImage->getImageFunction(), null);
$this->assertEquals($oMemoryImage->getImageExtension(), null);
$this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp');
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testStyle()
{
$oMemoryImage = new MemoryImage(\join(
2014-03-09 15:04:23 -04:00
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
2014-03-09 15:04:23 -04:00
), array('width' => 210, 'height' => 210, 'align' => 'center'));
2014-03-09 19:09:22 +01:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
public function testRelationID()
{
$oMemoryImage = new MemoryImage(\join(
2014-03-09 15:04:23 -04:00
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'earth.jpg')
2014-03-09 15:04:23 -04:00
));
2014-03-09 19:09:22 +01:00
2014-03-09 15:04:23 -04:00
$iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal);
}
}