101 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2014-03-27 23:55:06 +07:00
/**
* 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-03-27 23:55:06 +07:00
*
* @see https://github.com/PHPOffice/PHPWord
2022-09-16 11:45:45 +02:00
*
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2014-03-27 23:55:06 +07:00
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Style;
2022-09-16 11:45:45 +02:00
use InvalidArgumentException;
2015-10-10 19:22:19 +04:00
use PhpOffice\PhpWord\SimpleType\Jc;
2022-09-16 14:09:17 +02:00
use PhpOffice\PhpWord\Style\Image;
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Style\Image.
2014-03-27 23:55:06 +07:00
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Image
2022-09-16 11:45:45 +02:00
*
* @runTestsInSeparateProcesses
*/
class ImageTest extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* Test setting style with normal value.
*/
2022-09-16 11:45:45 +02:00
public function testSetGetNormal(): void
{
$object = new Image();
2022-09-16 11:45:45 +02:00
$properties = [
'width' => 200,
'height' => 200,
'alignment' => Jc::START,
'marginTop' => 240,
'marginLeft' => 240,
'wrappingStyle' => 'inline',
'wrapDistanceLeft' => 10,
'wrapDistanceRight' => 20,
'wrapDistanceTop' => 30,
2018-03-11 13:27:35 +01:00
'wrapDistanceBottom' => 40,
2022-09-16 11:45:45 +02:00
];
foreach ($properties as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
2022-09-16 11:45:45 +02:00
self::assertEquals($value, $object->$get());
}
}
/**
2022-09-16 11:45:45 +02:00
* Test setStyleValue method.
*/
2022-09-16 11:45:45 +02:00
public function testSetStyleValue(): void
{
$object = new Image();
2022-09-16 11:45:45 +02:00
$properties = [
'width' => 200,
'height' => 200,
'alignment' => Jc::START,
'marginTop' => 240,
'marginLeft' => 240,
'position' => 10,
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_IMARGIN,
'wrapDistanceLeft' => 10,
'wrapDistanceRight' => 20,
'wrapDistanceTop' => 30,
2018-03-11 13:27:35 +01:00
'wrapDistanceBottom' => 40,
2022-09-16 11:45:45 +02:00
];
foreach ($properties as $key => $value) {
$get = "get{$key}";
$object->setStyleValue("{$key}", $value);
2022-09-16 11:45:45 +02:00
self::assertEquals($value, $object->$get());
}
}
/**
2022-09-16 11:45:45 +02:00
* Test setWrappingStyle exception.
*/
2022-09-16 11:45:45 +02:00
public function testSetWrappingStyleException(): void
{
2022-09-16 11:45:45 +02:00
$this->expectException(InvalidArgumentException::class);
$object = new Image();
$object->setWrappingStyle('foo');
}
}