107 lines
3.9 KiB
PHP
Raw Normal View History

2018-03-11 13:27:35 +01:00
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
2022-09-16 11:45:45 +02:00
*
2018-03-11 13:27:35 +01:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\Image;
use PhpOffice\PhpWord\TestHelperDOCX;
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font.
2018-03-11 13:27:35 +01:00
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Frame
2022-09-16 11:45:45 +02:00
*
2018-03-11 13:27:35 +01:00
* @runTestsInSeparateProcesses
*/
class ImageTest extends \PHPUnit\Framework\TestCase
{
/**
2022-09-16 11:45:45 +02:00
* Executed before each method of the class.
2018-03-11 13:27:35 +01:00
*/
2022-09-16 11:45:45 +02:00
protected function tearDown(): void
2018-03-11 13:27:35 +01:00
{
TestHelperDOCX::clear();
}
/**
2022-09-16 11:45:45 +02:00
* Test writing image wrapping.
2018-03-11 13:27:35 +01:00
*/
2022-09-16 11:45:45 +02:00
public function testWrapping(): void
2018-03-11 13:27:35 +01:00
{
2022-09-16 11:45:45 +02:00
$styles = [
'wrap' => Image::WRAP_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
];
2018-03-11 13:27:35 +01:00
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addImage(__DIR__ . '/../../../_files/images/earth.jpg', $styles);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p[1]/w:r/w:rPr/w:position';
2022-09-16 11:45:45 +02:00
self::assertFalse($doc->elementExists($path));
$path = '/w:document/w:body/w:p[1]/w:r/w:pict/v:shape';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path . '/w10:wrap'));
self::assertEquals('inline', $doc->getElementAttribute($path . '/w10:wrap', 'type'));
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
$style = $doc->getElement($path)->getAttribute('style');
2022-09-16 11:45:45 +02:00
self::assertNotNull($style);
self::assertStringContainsString('mso-wrap-distance-left:10pt;', $style);
self::assertStringContainsString('mso-wrap-distance-right:20pt;', $style);
self::assertStringContainsString('mso-wrap-distance-top:30pt;', $style);
self::assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style);
}
/**
2022-09-16 11:45:45 +02:00
* Test writing image wrapping.
*/
2022-09-16 11:45:45 +02:00
public function testWrappingWithPosition(): void
{
2022-09-16 11:45:45 +02:00
$styles = [
'wrap' => Image::WRAP_INLINE,
'wrapDistanceLeft' => 10,
'wrapDistanceRight' => 20,
'wrapDistanceTop' => 30,
'wrapDistanceBottom' => 40,
2022-09-16 11:45:45 +02:00
'position' => 10,
];
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addImage(__DIR__ . '/../../../_files/images/earth.jpg', $styles);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p[1]/w:r/w:rPr/w:position';
2022-09-16 11:45:45 +02:00
self::assertEquals('10', $doc->getElement($path)->getAttribute('w:val'));
2018-03-11 13:27:35 +01:00
$path = '/w:document/w:body/w:p[1]/w:r/w:pict/v:shape';
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path . '/w10:wrap'));
self::assertEquals('inline', $doc->getElementAttribute($path . '/w10:wrap', 'type'));
2018-03-11 13:27:35 +01:00
2022-09-16 11:45:45 +02:00
self::assertTrue($doc->elementExists($path));
2018-03-11 13:27:35 +01:00
$style = $doc->getElement($path)->getAttribute('style');
2022-09-16 11:45:45 +02:00
self::assertNotNull($style);
self::assertStringContainsString('mso-wrap-distance-left:10pt;', $style);
self::assertStringContainsString('mso-wrap-distance-right:20pt;', $style);
self::assertStringContainsString('mso-wrap-distance-top:30pt;', $style);
self::assertStringContainsString('mso-wrap-distance-bottom:40pt;', $style);
2018-03-11 13:27:35 +01:00
}
}