Skip to content

Commit 4e24657

Browse files
OlisaevAGOlisaevAG
authored andcommitted
feat: Support for padding in a table cell. Test file
1 parent c02637d commit 4e24657

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPWord
14+
*
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWordTests\Writer\Word2007\Style;
19+
20+
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
21+
use PhpOffice\PhpWord\Shared\Converter;
22+
use PhpOffice\PhpWord\SimpleType\TblWidth;
23+
use PhpOffice\PhpWord\Style\Table;
24+
use PhpOffice\PhpWord\Style\TablePosition;
25+
use PhpOffice\PhpWordTests\TestHelperDOCX;
26+
27+
/**
28+
* Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Table.
29+
*
30+
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Style\Table
31+
*
32+
* @runTestsInSeparateProcesses
33+
*/
34+
class TableCellTest extends \PHPUnit\Framework\TestCase
35+
{
36+
/**
37+
* Executed before each method of the class.
38+
*/
39+
protected function tearDown(): void
40+
{
41+
TestHelperDOCX::clear();
42+
}
43+
44+
/**
45+
* Test write styles.
46+
*/
47+
public function testCellSpacing(): void
48+
{
49+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
50+
$section = $phpWord->addSection();
51+
$table = $section->addTable();
52+
$table->addRow();
53+
54+
$testValTop = Converter::pixelToTwip(10);
55+
$testValRight = Converter::pixelToTwip(11);
56+
$testValBottom = Converter::pixelToTwip(12);
57+
$testValLeft = Converter::pixelToTwip(13);
58+
59+
$cellStyle = [
60+
'paddingTop' => $testValTop,
61+
'paddingRight' => $testValRight,
62+
'paddingBottom' => $testValBottom,
63+
'paddingLeft' => $testValLeft
64+
];
65+
$table->addCell(null, $cellStyle)->addText('Some text');
66+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
67+
68+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:top';
69+
self::assertTrue($doc->elementExists($path));
70+
self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w'));
71+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
72+
73+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:start';
74+
self::assertTrue($doc->elementExists($path));
75+
self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w'));
76+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
77+
78+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:bottom';
79+
self::assertTrue($doc->elementExists($path));
80+
self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w'));
81+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
82+
83+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:end';
84+
self::assertTrue($doc->elementExists($path));
85+
self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w'));
86+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
87+
}
88+
}

0 commit comments

Comments
 (0)