2014-03-15 14:48:26 +07:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* 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.
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-27 23:55:06 +07:00
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part;
|
2014-03-15 14:48:26 +07:00
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-03-23 12:37:31 -04:00
|
|
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
2014-03-15 14:48:26 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-04-30 08:54:38 +07:00
|
|
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
2014-04-30 08:54:38 +07:00
|
|
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Part\Content
|
2014-03-15 14:48:26 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
|
*/
|
|
|
|
|
class ContentTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Executed before each method of the class
|
|
|
|
|
*/
|
|
|
|
|
public function tearDown()
|
|
|
|
|
{
|
|
|
|
|
TestHelperDOCX::clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 03:47:43 +07:00
|
|
|
/**
|
|
|
|
|
* Test write content
|
2014-03-15 14:48:26 +07:00
|
|
|
*/
|
|
|
|
|
public function testWriteContent()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
|
|
|
|
|
$objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
|
2014-03-15 14:48:26 +07:00
|
|
|
$expected = 'Expected';
|
|
|
|
|
|
2014-03-20 16:54:12 +04:00
|
|
|
$phpWord = new PhpWord();
|
2014-04-17 03:47:43 +07:00
|
|
|
|
2014-06-16 07:32:57 +07:00
|
|
|
$docProps = $phpWord->getDocInfo();
|
2014-05-31 17:39:54 +07:00
|
|
|
$docProps->setCustomProperty('Company', 'PHPWord');
|
|
|
|
|
|
2014-03-20 16:54:12 +04:00
|
|
|
$phpWord->setDefaultFontName('Verdana');
|
|
|
|
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
|
|
|
|
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
2014-05-24 11:11:12 +07:00
|
|
|
$phpWord->addTableStyle('tblStyle', array('width' => 100));
|
2014-04-17 03:47:43 +07:00
|
|
|
|
2014-05-24 00:11:06 +07:00
|
|
|
$section = $phpWord->addSection(array('colsNum' => 2));
|
2015-02-06 22:28:31 +04:00
|
|
|
$section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font');
|
|
|
|
|
$section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
|
|
|
|
|
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1);
|
2014-04-17 03:47:43 +07:00
|
|
|
$section->addTextBreak();
|
2014-03-15 14:48:26 +07:00
|
|
|
$section->addPageBreak();
|
2015-02-06 22:28:31 +04:00
|
|
|
$section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
|
2014-05-24 00:11:06 +07:00
|
|
|
$section->addImage($imageSrc, array('width' => 50));
|
2014-03-15 14:48:26 +07:00
|
|
|
$section->addObject($objectSrc);
|
|
|
|
|
$section->addTOC();
|
2014-04-17 03:47:43 +07:00
|
|
|
|
2014-04-02 11:02:56 +07:00
|
|
|
$textrun = $section->addTextRun();
|
2015-02-06 22:28:31 +04:00
|
|
|
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
|
2014-04-17 03:47:43 +07:00
|
|
|
|
2014-05-24 00:11:06 +07:00
|
|
|
$table = $section->addTable(array('width' => 50));
|
2014-04-17 03:47:43 +07:00
|
|
|
$cell = $table->addRow()->addCell();
|
|
|
|
|
$cell = $table->addRow()->addCell();
|
2015-02-06 22:28:31 +04:00
|
|
|
$cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
|
|
|
|
|
$cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
|
2014-04-17 03:47:43 +07:00
|
|
|
$cell->addTextBreak();
|
2015-02-06 22:28:31 +04:00
|
|
|
$cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
|
2014-04-17 03:47:43 +07:00
|
|
|
$cell->addImage($imageSrc);
|
|
|
|
|
$cell->addObject($objectSrc);
|
|
|
|
|
$textrun = $cell->addTextRun();
|
2015-02-06 22:28:31 +04:00
|
|
|
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
|
2014-04-17 03:47:43 +07:00
|
|
|
|
|
|
|
|
$footer = $section->addFooter();
|
2015-02-06 22:28:31 +04:00
|
|
|
$footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'));
|
2014-04-17 03:47:43 +07:00
|
|
|
|
2014-05-24 00:11:06 +07:00
|
|
|
$table = $section->addTable('tblStyle')->addRow()->addCell();
|
|
|
|
|
|
2014-03-20 16:54:12 +04:00
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
2014-03-15 14:48:26 +07:00
|
|
|
|
2015-02-06 22:28:31 +04:00
|
|
|
$element = '/office:document-content/office:body/office:text/text:section/text:p';
|
2014-03-15 14:48:26 +07:00
|
|
|
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
|
|
|
|
|
}
|
2014-04-17 03:47:43 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test no paragraph style
|
|
|
|
|
*/
|
|
|
|
|
public function testWriteNoStyle()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
2015-02-06 22:28:31 +04:00
|
|
|
$element = '/office:document-content/office:automatic-styles/style:style';
|
2014-04-17 03:47:43 +07:00
|
|
|
$this->assertTrue($doc->elementExists($element, 'content.xml'));
|
|
|
|
|
}
|
2014-03-15 14:48:26 +07:00
|
|
|
}
|