|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | + * word processing documents. |
| 6 | + * |
| 7 | + * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | + * General Public License version 3 as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * For the full copyright and license information, please read the LICENSE |
| 11 | + * file that was distributed with this source code. For the full list of |
| 12 | + * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | + * |
| 14 | + * @see https://github.com/PHPOffice/PHPWord |
| 15 | + * |
| 16 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | + */ |
| 18 | + |
| 19 | +namespace PhpOffice\PhpWordTests\Writer\Word2007\Element; |
| 20 | + |
| 21 | +use PhpOffice\PhpWord\PhpWord; |
| 22 | +use PhpOffice\PhpWordTests\TestHelperDOCX; |
| 23 | + |
| 24 | +/** |
| 25 | + * Test class for PhpOffice\PhpWord\Writer\Word2007\Element subnamespace. |
| 26 | + */ |
| 27 | +class ImageSvgTest extends \PHPUnit\Framework\TestCase |
| 28 | +{ |
| 29 | + private const CX = '6772275'; |
| 30 | + private const CY = '3648075'; |
| 31 | + |
| 32 | + protected function tearDown(): void |
| 33 | + { |
| 34 | + TestHelperDOCX::clear(); |
| 35 | + } |
| 36 | + |
| 37 | + public function testStyleDimensionsZero(): void |
| 38 | + { |
| 39 | + $phpWord = new PhpWord(); |
| 40 | + $section = $phpWord->addSection(); |
| 41 | + $svg = $section->addImage( |
| 42 | + 'samples/resources/sample.svg' |
| 43 | + ); |
| 44 | + $svg->getStyle()->setWidth(0); |
| 45 | + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); |
| 46 | + $path = '/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:inline/wp:extent'; |
| 47 | + self::assertTrue($doc->elementExists($path)); |
| 48 | + self::assertSame( |
| 49 | + self::CX, |
| 50 | + $doc->getElementAttribute($path, 'cx') |
| 51 | + ); |
| 52 | + self::assertSame( |
| 53 | + self::CY, |
| 54 | + $doc->getElementAttribute($path, 'cy') |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + public function testNoStyle(): void |
| 59 | + { |
| 60 | + $phpWord = new PhpWord(); |
| 61 | + $section = $phpWord->addSection(); |
| 62 | + $svg = $section->addImage( |
| 63 | + 'samples/resources/sample.svg' |
| 64 | + ); |
| 65 | + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); |
| 66 | + $path = '/w:document/w:body/w:p[1]/w:r[1]/w:drawing/wp:inline/wp:extent'; |
| 67 | + self::assertTrue($doc->elementExists($path)); |
| 68 | + self::assertSame( |
| 69 | + self::CX, |
| 70 | + $doc->getElementAttribute($path, 'cx') |
| 71 | + ); |
| 72 | + self::assertSame( |
| 73 | + self::CY, |
| 74 | + $doc->getElementAttribute($path, 'cy') |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments