2014-03-10 03:20:24 +07:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2014-05-05 23:38:31 +02: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
|
|
|
*
|
2017-11-04 22:44:12 +01: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;
|
2014-03-10 03:20:24 +07:00
|
|
|
|
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;
|
2014-03-10 03:20:24 +07:00
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*
|
2014-03-10 03:20:24 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
|
*/
|
2017-11-09 06:36:47 -02:00
|
|
|
class ImageTest extends \PHPUnit\Framework\TestCase
|
2014-03-10 03:20:24 +07:00
|
|
|
{
|
|
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Test setting style with normal value.
|
2014-03-10 03:20:24 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testSetGetNormal(): void
|
2014-03-10 03:20:24 +07:00
|
|
|
{
|
2014-03-19 11:04:48 +04:00
|
|
|
$object = new Image();
|
2014-03-10 03:20:24 +07:00
|
|
|
|
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
|
|
|
];
|
2014-03-10 03:20:24 +07: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());
|
2014-03-10 03:20:24 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Test setStyleValue method.
|
2014-03-10 03:20:24 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testSetStyleValue(): void
|
2014-03-10 03:20:24 +07:00
|
|
|
{
|
2014-03-19 11:04:48 +04:00
|
|
|
$object = new Image();
|
2014-03-10 03:20:24 +07:00
|
|
|
|
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
|
|
|
];
|
2014-03-10 03:20:24 +07:00
|
|
|
foreach ($properties as $key => $value) {
|
|
|
|
|
$get = "get{$key}";
|
2014-04-06 18:03:03 +07:00
|
|
|
$object->setStyleValue("{$key}", $value);
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertEquals($value, $object->$get());
|
2014-03-10 03:20:24 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Test setWrappingStyle exception.
|
2014-03-10 03:20:24 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testSetWrappingStyleException(): void
|
2014-03-10 03:20:24 +07:00
|
|
|
{
|
2022-09-16 11:45:45 +02:00
|
|
|
$this->expectException(InvalidArgumentException::class);
|
2014-03-19 11:04:48 +04:00
|
|
|
$object = new Image();
|
2014-03-10 03:20:24 +07:00
|
|
|
$object->setWrappingStyle('foo');
|
|
|
|
|
}
|
2014-03-11 21:44:54 +07:00
|
|
|
}
|