2014-03-12 13:32:49 +07:00
|
|
|
<?php
|
2014-03-23 11:59:22 -04:00
|
|
|
namespace PhpOffice\PhpWord\Tests\Writer;
|
2014-03-12 13:32:49 +07:00
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-03-19 11:04:48 +04:00
|
|
|
use PhpOffice\PhpWord\Writer\Word2007;
|
2014-03-23 12:37:31 -04:00
|
|
|
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
2014-03-12 13:32:49 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-23 10:32:08 +04:00
|
|
|
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007
|
2014-03-12 13:32:49 +07:00
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
|
*/
|
|
|
|
|
class Word2007Test extends \PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
2014-03-12 10:09:42 -04:00
|
|
|
public function tearDown()
|
|
|
|
|
{
|
|
|
|
|
TestHelperDOCX::clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 13:25:42 +07:00
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* covers ::__construct
|
2014-03-15 13:25:42 +07:00
|
|
|
*/
|
2014-03-12 13:32:49 +07:00
|
|
|
public function testConstruct()
|
|
|
|
|
{
|
2014-03-20 16:54:12 +04:00
|
|
|
$object = new Word2007(new PhpWord());
|
2014-03-12 13:32:49 +07:00
|
|
|
|
2014-03-19 11:04:48 +04:00
|
|
|
$writerParts = array(
|
|
|
|
|
'ContentTypes',
|
|
|
|
|
'Rels',
|
|
|
|
|
'DocProps',
|
|
|
|
|
'DocumentRels',
|
|
|
|
|
'Document',
|
|
|
|
|
'Styles',
|
|
|
|
|
'Header',
|
|
|
|
|
'Footer',
|
|
|
|
|
'Footnotes',
|
|
|
|
|
'FootnotesRels',
|
|
|
|
|
);
|
2014-03-12 13:32:49 +07:00
|
|
|
foreach ($writerParts as $part) {
|
|
|
|
|
$this->assertInstanceOf(
|
2014-03-19 11:04:48 +04:00
|
|
|
"PhpOffice\\PhpWord\\Writer\\Word2007\\{$part}",
|
2014-03-12 13:32:49 +07:00
|
|
|
$object->getWriterPart($part)
|
|
|
|
|
);
|
|
|
|
|
$this->assertInstanceOf(
|
2014-03-19 11:04:48 +04:00
|
|
|
'PhpOffice\\PhpWord\\Writer\\Word2007',
|
2014-03-12 13:32:49 +07:00
|
|
|
$object->getWriterPart($part)->getParentWriter()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 13:25:42 +07:00
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::save
|
2014-03-15 13:25:42 +07:00
|
|
|
*/
|
2014-03-12 13:32:49 +07:00
|
|
|
public function testSave()
|
|
|
|
|
{
|
2014-03-20 16:54:12 +04:00
|
|
|
$phpWord = new PhpWord();
|
2014-03-12 13:32:49 +07:00
|
|
|
$phpWord->addFontStyle('Font', array('size' => 11));
|
|
|
|
|
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
|
|
|
|
$section = $phpWord->createSection();
|
|
|
|
|
$section->addText('Test 1', 'Font', 'Paragraph');
|
|
|
|
|
$section->addTextBreak();
|
|
|
|
|
$section->addText('Test 2');
|
|
|
|
|
$section = $phpWord->createSection();
|
|
|
|
|
$textrun = $section->createTextRun();
|
|
|
|
|
$textrun->addText('Test 3');
|
|
|
|
|
|
2014-03-19 11:04:48 +04:00
|
|
|
$writer = new Word2007($phpWord);
|
2014-03-23 12:37:31 -04:00
|
|
|
$file = __DIR__ . "/../_files/temp.docx";
|
2014-03-12 13:32:49 +07:00
|
|
|
$writer->save($file);
|
2014-03-24 00:26:10 +07:00
|
|
|
$this->assertTrue(\file_exists($file));
|
2014-03-12 13:32:49 +07:00
|
|
|
unlink($file);
|
|
|
|
|
}
|
2014-03-12 10:09:42 -04:00
|
|
|
|
2014-03-16 07:40:02 +07:00
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::checkContentTypes
|
2014-03-12 10:09:42 -04:00
|
|
|
*/
|
|
|
|
|
public function testCheckContentTypes()
|
|
|
|
|
{
|
2014-03-13 01:58:00 +07:00
|
|
|
$images = array(
|
|
|
|
|
'mars_noext_jpg' => '1.jpg',
|
|
|
|
|
'mars.jpg' => '2.jpg',
|
|
|
|
|
'mario.gif' => '3.gif',
|
|
|
|
|
'firefox.png' => '4.png',
|
|
|
|
|
'duke_nukem.bmp' => '5.bmp',
|
|
|
|
|
'angela_merkel.tif' => '6.tif',
|
|
|
|
|
);
|
2014-03-20 16:54:12 +04:00
|
|
|
$phpWord = new PhpWord();
|
2014-03-12 10:09:42 -04:00
|
|
|
$section = $phpWord->createSection();
|
2014-03-13 01:58:00 +07:00
|
|
|
foreach ($images as $source => $target) {
|
2014-03-23 12:37:31 -04:00
|
|
|
$section->addImage(__DIR__ . "/../_files/images/{$source}");
|
2014-03-13 01:58:00 +07:00
|
|
|
}
|
2014-03-12 10:09:42 -04:00
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
|
|
|
|
$mediaPath = $doc->getPath() . "/word/media";
|
|
|
|
|
|
2014-03-13 01:58:00 +07:00
|
|
|
foreach ($images as $source => $target) {
|
|
|
|
|
$this->assertFileEquals(
|
2014-03-23 12:37:31 -04:00
|
|
|
__DIR__ . "/../_files/images/{$source}",
|
2014-03-13 01:58:00 +07:00
|
|
|
$mediaPath . "/section_image{$target}"
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-03-12 10:09:42 -04:00
|
|
|
}
|
2014-03-15 13:25:42 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setUseDiskCaching
|
|
|
|
|
* @covers ::getUseDiskCaching
|
2014-03-15 13:25:42 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetGetUseDiskCaching()
|
|
|
|
|
{
|
2014-03-19 11:04:48 +04:00
|
|
|
$object = new Word2007();
|
2014-03-22 10:06:08 +04:00
|
|
|
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
|
2014-03-15 13:25:42 +07:00
|
|
|
|
|
|
|
|
$this->assertTrue($object->getUseDiskCaching());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-19 11:04:48 +04:00
|
|
|
* @covers ::setUseDiskCaching
|
2014-03-23 10:32:08 +04:00
|
|
|
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
2014-03-15 13:25:42 +07:00
|
|
|
*/
|
|
|
|
|
public function testSetUseDiskCachingException()
|
|
|
|
|
{
|
|
|
|
|
$dir = \join(
|
|
|
|
|
\DIRECTORY_SEPARATOR,
|
2014-03-22 10:06:08 +04:00
|
|
|
array(\PHPWORD_TESTS_BASE_DIR, 'foo')
|
2014-03-15 13:25:42 +07:00
|
|
|
);
|
|
|
|
|
|
2014-03-19 11:04:48 +04:00
|
|
|
$object = new Word2007();
|
2014-03-15 13:25:42 +07:00
|
|
|
$object->setUseDiskCaching(true, $dir);
|
|
|
|
|
}
|
2014-03-13 01:58:00 +07:00
|
|
|
}
|