PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php

https://github.com/cyrillkalita/PHPWord
PHP | 110 lines | 64 code | 16 blank | 30 comment | 0 complexity | 94d6306c1c6ff6358f20286f7fec8912 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  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\ODText\Part;
  18. use PhpOffice\PhpWord\PhpWord;
  19. use PhpOffice\PhpWord\Tests\TestHelperDOCX;
  20. use PhpOffice\PhpWord\Writer\ODText\Part\Content;
  21. /**
  22. * Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content
  23. *
  24. * @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Content
  25. * @runTestsInSeparateProcesses
  26. */
  27. class ContentTest 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. * Test write content
  38. */
  39. public function testWriteContent()
  40. {
  41. $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png";
  42. $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
  43. $expected = 'Expected';
  44. $phpWord = new PhpWord();
  45. $docProps = $phpWord->getDocumentProperties();
  46. $docProps->setCustomProperty('Company', 'PHPWord');
  47. $phpWord->setDefaultFontName('Verdana');
  48. $phpWord->addFontStyle('Font', array('size' => 11));
  49. $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
  50. $phpWord->addTableStyle('tblStyle', array('width' => 100));
  51. $section = $phpWord->addSection(array('colsNum' => 2));
  52. $section->addText($expected);
  53. $section->addText('Test font style', 'Font');
  54. $section->addText('Test paragraph style', null, 'Paragraph');
  55. $section->addLink('http://test.com', 'Test link');
  56. $section->addTitle('Test title', 1);
  57. $section->addTextBreak();
  58. $section->addPageBreak();
  59. $section->addListItem('Test list item');
  60. $section->addImage($imageSrc, array('width' => 50));
  61. $section->addObject($objectSrc);
  62. $section->addTOC();
  63. $textrun = $section->addTextRun();
  64. $textrun->addText('Test text run');
  65. $table = $section->addTable(array('width' => 50));
  66. $cell = $table->addRow()->addCell();
  67. $cell = $table->addRow()->addCell();
  68. $cell->addText('Test');
  69. $cell->addLink('http://test.com', 'Test link');
  70. $cell->addTextBreak();
  71. $cell->addListItem('Test list item');
  72. $cell->addImage($imageSrc);
  73. $cell->addObject($objectSrc);
  74. $textrun = $cell->addTextRun();
  75. $textrun->addText('Test text run');
  76. $footer = $section->addFooter();
  77. $footer->addPreserveText('{PAGE}');
  78. $table = $section->addTable('tblStyle')->addRow()->addCell();
  79. $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
  80. $element = "/office:document-content/office:body/office:text/text:section/text:p";
  81. $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
  82. }
  83. /**
  84. * Test no paragraph style
  85. */
  86. public function testWriteNoStyle()
  87. {
  88. $phpWord = new PhpWord();
  89. $phpWord->addFontStyle('Font', array('size' => 11));
  90. $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
  91. $element = "/office:document-content/office:automatic-styles/style:style";
  92. $this->assertTrue($doc->elementExists($element, 'content.xml'));
  93. }
  94. }