暂无描述

DocumentTest.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
  18. use PhpOffice\PhpWord\PhpWord;
  19. use PhpOffice\PhpWord\Style\Font;
  20. use PhpOffice\PhpWord\Tests\TestHelperDOCX;
  21. use PhpOffice\PhpWord\Writer\Word2007\Part\Document;
  22. /**
  23. * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Document
  24. *
  25. * @runTestsInSeparateProcesses
  26. */
  27. class DocumentTest extends \PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * Executed before each method of the class
  31. */
  32. public function tearDown()
  33. {
  34. TestHelperDOCX::clear();
  35. }
  36. /**
  37. * Write end section page numbering
  38. */
  39. public function testWriteEndSectionPageNumbering()
  40. {
  41. $phpWord = new PhpWord();
  42. $section = $phpWord->addSection();
  43. $section->addHeader();
  44. $section->addHeader('first');
  45. $style = $section->getStyle();
  46. $style->setLandscape();
  47. $style->setPageNumberingStart(2);
  48. $style->setBorderSize(240);
  49. $style->setBreakType('nextPage');
  50. $doc = TestHelperDOCX::getDocument($phpWord);
  51. $element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
  52. $this->assertEquals(2, $element->getAttribute('w:start'));
  53. }
  54. /**
  55. * Write elements
  56. */
  57. public function testElements()
  58. {
  59. $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
  60. $phpWord = new PhpWord();
  61. $phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true));
  62. $phpWord->addTitleStyle(2, array('color'=>'666666'));
  63. $section = $phpWord->addSection();
  64. $section->addTOC();
  65. $section->addPageBreak();
  66. $section->addText('After page break.');
  67. $section->addTitle('Title 1', 1);
  68. $section->addListItem('List Item 1', 0);
  69. $section->addListItem('List Item 2', 0);
  70. $section->addListItem('List Item 3', 0);
  71. $section = $phpWord->addSection();
  72. $section->addTitle('Title 2', 2);
  73. $section->addObject($objectSrc);
  74. $section->addTextBox(array());
  75. $section->addTextBox(array('wrappingStyle' => 'square', 'positioning' => 'relative',
  76. 'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin',
  77. 'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0'));
  78. $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center'));
  79. $section->addListItemRun()->addText('List item run 1');
  80. $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
  81. $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'SakaEraCalendar'));
  82. $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LastUsedFormat'));
  83. $section->addField('PAGE', array('format'=>'ArabicDash'));
  84. $section->addLine(
  85. array(
  86. 'width' => 10,
  87. 'height' => 10,
  88. 'positioning' => 'absolute',
  89. 'beginArrow' => 'block',
  90. 'endArrow' => 'open',
  91. 'dash' => 'rounddot',
  92. 'weight' => 10
  93. )
  94. );
  95. $doc = TestHelperDOCX::getDocument($phpWord);
  96. // TOC
  97. $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:tabs/w:tab');
  98. $this->assertEquals('right', $element->getAttribute('w:val'));
  99. $this->assertEquals('dot', $element->getAttribute('w:leader'));
  100. $this->assertEquals(9062, $element->getAttribute('w:pos'));
  101. // Page break
  102. $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:br');
  103. $this->assertEquals('page', $element->getAttribute('w:type'));
  104. // Title
  105. $element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:pStyle');
  106. $this->assertEquals('Heading1', $element->getAttribute('w:val'));
  107. // List item
  108. $element = $doc->getElement('/w:document/w:body/w:p[7]/w:pPr/w:numPr/w:numId');
  109. $this->assertEquals(3, $element->getAttribute('w:val'));
  110. // Object
  111. $element = $doc->getElement('/w:document/w:body/w:p[12]/w:r/w:object/o:OLEObject');
  112. $this->assertEquals('Embed', $element->getAttribute('Type'));
  113. }
  114. /**
  115. * Write element with some styles
  116. */
  117. public function testElementStyles()
  118. {
  119. $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
  120. $tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090));
  121. $phpWord = new PhpWord();
  122. $phpWord->addParagraphStyle('pStyle', array(
  123. 'align' => 'center',
  124. 'tabs' => $tabs,
  125. 'shading' => array('fill' => 'FFFF99'),
  126. 'borderSize' => 4,
  127. )); // Style #1
  128. $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true,
  129. 'scale' => 200, 'spacing' => 240, 'kerning' => 10)); // Style #2
  130. $phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3
  131. $phpWord->addTableStyle('tStyle', array('borderSize' => 1));
  132. $fontStyle = new Font('text', array('align' => 'center'));
  133. $section = $phpWord->addSection();
  134. $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5
  135. $section->addObject($objectSrc, array('align' => 'center'));
  136. $section->addTOC($fontStyle);
  137. $section->addTitle('Title 1', 1);
  138. $section->addTOC('fStyle');
  139. $table = $section->addTable('tStyle');
  140. $table->setWidth(100);
  141. $doc = TestHelperDOCX::getDocument($phpWord);
  142. // List item
  143. $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId');
  144. $this->assertEquals(5, $element->getAttribute('w:val'));
  145. // Object
  146. $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject');
  147. $this->assertEquals('Embed', $element->getAttribute('Type'));
  148. // TOC
  149. $element = $doc->getElement('/w:document/w:body/w:p[3]/w:pPr/w:tabs/w:tab');
  150. $this->assertEquals('right', $element->getAttribute('w:val'));
  151. $this->assertEquals('dot', $element->getAttribute('w:leader'));
  152. $this->assertEquals(9062, $element->getAttribute('w:pos'));
  153. }
  154. /**
  155. * Test write text element
  156. */
  157. public function testWriteText()
  158. {
  159. $rStyle = 'rStyle';
  160. $pStyle = 'pStyle';
  161. $phpWord = new PhpWord();
  162. $phpWord->addFontStyle($rStyle, array('bold' => true));
  163. $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
  164. $section = $phpWord->addSection();
  165. $section->addText('Test', $rStyle, $pStyle);
  166. $doc = TestHelperDOCX::getDocument($phpWord);
  167. $element = "/w:document/w:body/w:p/w:r/w:rPr/w:rStyle";
  168. $this->assertEquals($rStyle, $doc->getElementAttribute($element, 'w:val'));
  169. $element = "/w:document/w:body/w:p/w:pPr/w:pStyle";
  170. $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val'));
  171. }
  172. /**
  173. * Test write textrun element
  174. */
  175. public function testWriteTextRun()
  176. {
  177. $pStyle = 'pStyle';
  178. $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120);
  179. $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg";
  180. $phpWord = new PhpWord();
  181. $phpWord->addParagraphStyle($pStyle, $aStyle);
  182. $section = $phpWord->addSection('Test');
  183. $textrun = $section->addTextRun($pStyle);
  184. $textrun->addText('Test');
  185. $textrun->addTextBreak();
  186. $textrun = $section->addTextRun($aStyle);
  187. $textrun->addLink('http://test.com');
  188. $textrun->addImage($imageSrc, array('align' => 'center'));
  189. $textrun->addFootnote();
  190. $doc = TestHelperDOCX::getDocument($phpWord);
  191. $parent = "/w:document/w:body/w:p";
  192. $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']"));
  193. }
  194. /**
  195. * Test write link element
  196. */
  197. public function testWriteLink()
  198. {
  199. $phpWord = new PhpWord();
  200. $section = $phpWord->addSection();
  201. $fontStyleArray = array('bold' => true);
  202. $fontStyleName = 'Font Style';
  203. $paragraphStyleArray = array('align' => 'center');
  204. $paragraphStyleName = 'Paragraph Style';
  205. $expected = 'PhpWord';
  206. $section->addLink('http://github.com/phpoffice/phpword', $expected);
  207. $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray, $paragraphStyleArray);
  208. $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName, $paragraphStyleName);
  209. $doc = TestHelperDOCX::getDocument($phpWord);
  210. $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t');
  211. $this->assertEquals($expected, $element->nodeValue);
  212. }
  213. /**
  214. * Test write preserve text element
  215. */
  216. public function testWritePreserveText()
  217. {
  218. $phpWord = new PhpWord();
  219. $section = $phpWord->addSection();
  220. $footer = $section->addFooter();
  221. $fontStyleArray = array('bold' => true);
  222. $fontStyleName = 'Font';
  223. $paragraphStyleArray = array('align' => 'right');
  224. $paragraphStyleName = 'Paragraph';
  225. $footer->addPreserveText('Page {PAGE}');
  226. $footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray);
  227. $footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName);
  228. $doc = TestHelperDOCX::getDocument($phpWord);
  229. $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml');
  230. $this->assertEquals('PAGE', $preserve->nodeValue);
  231. $this->assertEquals('preserve', $preserve->getAttribute('xml:space'));
  232. }
  233. /**
  234. * Test write text break
  235. */
  236. public function testWriteTextBreak()
  237. {
  238. $fArray = array('size' => 12);
  239. $pArray = array('spacing' => 240);
  240. $fName = 'fStyle';
  241. $pName = 'pStyle';
  242. $phpWord = new PhpWord();
  243. $phpWord->addFontStyle($fName, $fArray);
  244. $phpWord->addParagraphStyle($pName, $pArray);
  245. $section = $phpWord->addSection();
  246. $section->addTextBreak();
  247. $section->addTextBreak(1, $fArray, $pArray);
  248. $section->addTextBreak(1, $fName, $pName);
  249. $doc = TestHelperDOCX::getDocument($phpWord);
  250. $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:rPr/w:rStyle');
  251. $this->assertEquals($fName, $element->getAttribute('w:val'));
  252. $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:pStyle');
  253. $this->assertEquals($pName, $element->getAttribute('w:val'));
  254. }
  255. /**
  256. * covers ::_writeImage
  257. */
  258. public function testWriteImage()
  259. {
  260. $phpWord = new PhpWord();
  261. $styles = array('align' => 'left', 'width' => 40, 'height' => 40, 'marginTop' => -1, 'marginLeft' => -1);
  262. $wraps = array('inline', 'behind', 'infront', 'square', 'tight');
  263. $section = $phpWord->addSection();
  264. foreach ($wraps as $wrap) {
  265. $styles['wrappingStyle'] = $wrap;
  266. $section->addImage(__DIR__ . "/../../../_files/images/earth.jpg", $styles);
  267. }
  268. $archiveFile = realpath(__DIR__ . '/../../../_files/documents/reader.docx');
  269. $imageFile = 'word/media/image1.jpeg';
  270. $source = 'zip://' . $archiveFile . '#' . $imageFile;
  271. $section->addImage($source);
  272. $doc = TestHelperDOCX::getDocument($phpWord);
  273. // behind
  274. $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape');
  275. $style = $element->getAttribute('style');
  276. $this->assertRegExp('/z\-index:\-[0-9]*/', $style);
  277. // square
  278. $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap');
  279. $this->assertEquals('square', $element->getAttribute('type'));
  280. }
  281. /**
  282. * covers ::_writeWatermark
  283. */
  284. public function testWriteWatermark()
  285. {
  286. $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg";
  287. $phpWord = new PhpWord();
  288. $section = $phpWord->addSection();
  289. $header = $section->addHeader();
  290. $header->addWatermark($imageSrc);
  291. $doc = TestHelperDOCX::getDocument($phpWord);
  292. $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference");
  293. $this->assertStringStartsWith("rId", $element->getAttribute('r:id'));
  294. }
  295. /**
  296. * covers ::_writeTitle
  297. */
  298. public function testWriteTitle()
  299. {
  300. $phpWord = new PhpWord();
  301. $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
  302. $phpWord->addSection()->addTitle('Test', 1);
  303. $doc = TestHelperDOCX::getDocument($phpWord);
  304. $element = "/w:document/w:body/w:p/w:pPr/w:pStyle";
  305. $this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val'));
  306. }
  307. /**
  308. * covers ::_writeCheckbox
  309. */
  310. public function testWriteCheckbox()
  311. {
  312. $rStyle = 'rStyle';
  313. $pStyle = 'pStyle';
  314. $phpWord = new PhpWord();
  315. // $phpWord->addFontStyle($rStyle, array('bold' => true));
  316. // $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
  317. $section = $phpWord->addSection();
  318. $section->addCheckBox('Check1', 'Test', $rStyle, $pStyle);
  319. $doc = TestHelperDOCX::getDocument($phpWord);
  320. $element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
  321. $this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
  322. }
  323. /**
  324. * covers ::_writeParagraphStyle
  325. */
  326. public function testWriteParagraphStyle()
  327. {
  328. // Create the doc
  329. $phpWord = new PhpWord();
  330. $section = $phpWord->addSection();
  331. $attributes = array(
  332. 'align' => 'right',
  333. 'widowControl' => false,
  334. 'keepNext' => true,
  335. 'keepLines' => true,
  336. 'pageBreakBefore' => true,
  337. );
  338. foreach ($attributes as $attribute => $value) {
  339. $section->addText('Test', null, array($attribute => $value));
  340. }
  341. $doc = TestHelperDOCX::getDocument($phpWord);
  342. // Test the attributes
  343. $attributeCount = 0;
  344. foreach ($attributes as $key => $value) {
  345. $attributeCount++;
  346. $nodeName = ($key == 'align') ? 'jc' : $key;
  347. $path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}";
  348. if ($key != 'align') {
  349. $value = $value ? 1 : 0;
  350. }
  351. $element = $doc->getElement($path);
  352. $this->assertEquals($value, $element->getAttribute('w:val'));
  353. }
  354. }
  355. /**
  356. * covers ::_writeTextStyle
  357. */
  358. public function testWriteFontStyle()
  359. {
  360. $phpWord = new PhpWord();
  361. $styles['name'] = 'Verdana';
  362. $styles['size'] = 14;
  363. $styles['bold'] = true;
  364. $styles['italic'] = true;
  365. $styles['underline'] = 'dash';
  366. $styles['strikethrough'] = true;
  367. $styles['superScript'] = true;
  368. $styles['color'] = 'FF0000';
  369. $styles['fgColor'] = 'yellow';
  370. $styles['bgColor'] = 'FFFF00';
  371. $styles['hint'] = 'eastAsia';
  372. $styles['smallCaps'] = true;
  373. $section = $phpWord->addSection();
  374. $section->addText('Test', $styles);
  375. $doc = TestHelperDOCX::getDocument($phpWord);
  376. $parent = '/w:document/w:body/w:p/w:r/w:rPr';
  377. $this->assertEquals($styles['name'], $doc->getElementAttribute("{$parent}/w:rFonts", 'w:ascii'));
  378. $this->assertEquals($styles['size'] * 2, $doc->getElementAttribute("{$parent}/w:sz", 'w:val'));
  379. $this->assertTrue($doc->elementExists("{$parent}/w:b"));
  380. $this->assertTrue($doc->elementExists("{$parent}/w:i"));
  381. $this->assertEquals($styles['underline'], $doc->getElementAttribute("{$parent}/w:u", 'w:val'));
  382. $this->assertTrue($doc->elementExists("{$parent}/w:strike"));
  383. $this->assertEquals('superscript', $doc->getElementAttribute("{$parent}/w:vertAlign", 'w:val'));
  384. $this->assertEquals($styles['color'], $doc->getElementAttribute("{$parent}/w:color", 'w:val'));
  385. $this->assertEquals($styles['fgColor'], $doc->getElementAttribute("{$parent}/w:highlight", 'w:val'));
  386. $this->assertTrue($doc->elementExists("{$parent}/w:smallCaps"));
  387. }
  388. /**
  389. * covers ::_writeTableStyle
  390. */
  391. public function testWriteTableStyle()
  392. {
  393. $phpWord = new PhpWord();
  394. $rHeight = 120;
  395. $cWidth = 120;
  396. $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg";
  397. $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
  398. $tStyles["width"] = 50;
  399. $tStyles["cellMarginTop"] = 120;
  400. $tStyles["cellMarginRight"] = 120;
  401. $tStyles["cellMarginBottom"] = 120;
  402. $tStyles["cellMarginLeft"] = 120;
  403. $rStyles["tblHeader"] = true;
  404. $rStyles["cantSplit"] = true;
  405. $cStyles["valign"] = 'top';
  406. $cStyles["textDirection"] = 'btLr';
  407. $cStyles["bgColor"] = 'FF0000';
  408. $cStyles["borderTopSize"] = 120;
  409. $cStyles["borderBottomSize"] = 120;
  410. $cStyles["borderLeftSize"] = 120;
  411. $cStyles["borderRightSize"] = 120;
  412. $cStyles["borderTopColor"] = 'FF0000';
  413. $cStyles["borderBottomColor"] = 'FF0000';
  414. $cStyles["borderLeftColor"] = 'FF0000';
  415. $cStyles["borderRightColor"] = 'FF0000';
  416. $cStyles["vMerge"] = 'restart';
  417. $section = $phpWord->addSection();
  418. $table = $section->addTable($tStyles);
  419. $table->setWidth = 100;
  420. $table->addRow($rHeight, $rStyles);
  421. $cell = $table->addCell($cWidth, $cStyles);
  422. $cell->addText('Test');
  423. $cell->addTextBreak();
  424. $cell->addLink('http://google.com');
  425. $cell->addListItem('Test');
  426. $cell->addImage($imageSrc);
  427. $cell->addObject($objectSrc);
  428. $textrun = $cell->addTextRun();
  429. $textrun->addText('Test');
  430. $doc = TestHelperDOCX::getDocument($phpWord);
  431. $parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar';
  432. // $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w'));
  433. // $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w'));
  434. // $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w'));
  435. // $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w'));
  436. $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr';
  437. $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val'));
  438. $this->assertEquals($rStyles['tblHeader'], $doc->getElementAttribute("{$parent}/w:tblHeader", 'w:val'));
  439. $this->assertEquals($rStyles['cantSplit'], $doc->getElementAttribute("{$parent}/w:cantSplit", 'w:val'));
  440. $parent = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr';
  441. $this->assertEquals($cWidth, $doc->getElementAttribute("{$parent}/w:tcW", 'w:w'));
  442. $this->assertEquals($cStyles['valign'], $doc->getElementAttribute("{$parent}/w:vAlign", 'w:val'));
  443. $this->assertEquals($cStyles['textDirection'], $doc->getElementAttribute("{$parent}/w:textDirection", 'w:val'));
  444. }
  445. /**
  446. * covers ::_writeCellStyle
  447. */
  448. public function testWriteCellStyleCellGridSpan()
  449. {
  450. $phpWord = new PhpWord();
  451. $section = $phpWord->addSection();
  452. $table = $section->addTable();
  453. $table->addRow();
  454. $cell = $table->addCell(200);
  455. $cell->getStyle()->setGridSpan(5);
  456. $table->addRow();
  457. $table->addCell(40);
  458. $table->addCell(40);
  459. $table->addCell(40);
  460. $table->addCell(40);
  461. $table->addCell(40);
  462. $table->addRow();
  463. $cell = $table->addCell(200, array('borderRightColor' => 'FF0000'));
  464. $cell->getStyle()->setGridSpan(5);
  465. $doc = TestHelperDOCX::getDocument($phpWord);
  466. $element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');
  467. $this->assertEquals(5, $element->getAttribute('w:val'));
  468. }
  469. /**
  470. * Test write gutter and line numbering
  471. */
  472. public function testWriteGutterAndLineNumbering()
  473. {
  474. $pageMarginPath = '/w:document/w:body/w:sectPr/w:pgMar';
  475. $lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType';
  476. $phpWord = new PhpWord();
  477. $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
  478. $doc = TestHelperDOCX::getDocument($phpWord);
  479. $this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter'));
  480. $this->assertTrue($doc->elementExists($lineNumberingPath));
  481. }
  482. }