Writer unit test enhancements
This commit is contained in:
parent
255af437f2
commit
c91d6b61c9
|
|
@ -438,7 +438,7 @@ class RTF implements IWriter
|
|||
if ($styleFont->getBold()) {
|
||||
$sRTFText .= '\b';
|
||||
}
|
||||
if ($styleFont->getBold()) {
|
||||
if ($styleFont->getItalic()) {
|
||||
$sRTFText .= '\i';
|
||||
}
|
||||
if ($styleFont->getSize()) {
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ use PhpOffice\PhpWord\Writer\ODText;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\ODText
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -43,9 +42,10 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPhpWord
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
* Construct with null
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
*/
|
||||
public function testConstructWithNull()
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
|
|
@ -89,7 +89,8 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save php output
|
||||
*
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
|
|
@ -102,8 +103,9 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
|
|
@ -113,7 +115,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getWriterPart
|
||||
* Get writer part return null value
|
||||
*/
|
||||
public function testGetWriterPartNull()
|
||||
{
|
||||
|
|
@ -122,8 +124,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @covers ::getUseDiskCaching
|
||||
* Set/get use disk caching
|
||||
*/
|
||||
public function testSetGetUseDiskCaching()
|
||||
{
|
||||
|
|
@ -134,7 +135,8 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* Use disk caching exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testSetUseDiskCachingException()
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ use PhpOffice\PhpWord\Writer\RTF;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\RTF
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\RTF
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class RTFTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* covers ::construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -31,8 +30,9 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* covers ::__construct
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Construct with null
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
*/
|
||||
public function testConstructWithNull()
|
||||
|
|
@ -42,32 +42,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
$writer = new RTF($phpWord);
|
||||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new RTF();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @covers ::<private>
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
|
|
@ -76,12 +51,12 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
$file = __DIR__ . "/../_files/temp.rtf";
|
||||
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
|
||||
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test 1', 'Font');
|
||||
$section->addText('Test 1', 'Font', 'Paragraph');
|
||||
$section->addTextBreak();
|
||||
$section->addText('Test 2', null, 'Paragraph');
|
||||
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
|
||||
$section->addLink('http://test.com');
|
||||
$section->addTitle('Test', 1);
|
||||
$section->addPageBreak();
|
||||
|
|
@ -101,4 +76,30 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
$writer = new RTF($phpWord);
|
||||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new RTF();
|
||||
$writer->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$textrun->addTextBreak();
|
||||
$textrun = $section->createTextRun($aStyle);
|
||||
$textrun->addLink('http://test.com');
|
||||
$textrun->addImage($imageSrc);
|
||||
$textrun->addImage($imageSrc, array('align' => 'top'));
|
||||
$textrun->createFootnote();
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$parent = "/w:document/w:body/w:p";
|
||||
|
|
@ -80,12 +81,14 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$fontStyleArray = array('bold' => true);
|
||||
$fontStyleName = 'Test';
|
||||
$fontStyleName = 'Font Style';
|
||||
$paragraphStyleArray = array('align' => 'center');
|
||||
$paragraphStyleName = 'Paragraph Style';
|
||||
|
||||
$expected = 'PhpWord';
|
||||
$section->addLink('http://github.com/phpoffice/phpword', $expected);
|
||||
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray);
|
||||
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName);
|
||||
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray, $paragraphStyleArray);
|
||||
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName, $paragraphStyleName);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t');
|
||||
|
|
@ -230,6 +233,10 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$tWidth = 120;
|
||||
$rHeight = 120;
|
||||
$cWidth = 120;
|
||||
$imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
|
||||
$objectSrc = __DIR__ . "/../../_files/documents/sheet.xls";
|
||||
|
||||
$tStyles["width"] = 50;
|
||||
$tStyles["cellMarginTop"] = 120;
|
||||
$tStyles["cellMarginRight"] = 120;
|
||||
$tStyles["cellMarginBottom"] = 120;
|
||||
|
|
@ -247,6 +254,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$cStyles["borderBottomColor"] = 'FF0000';
|
||||
$cStyles["borderLeftColor"] = 'FF0000';
|
||||
$cStyles["borderRightColor"] = 'FF0000';
|
||||
$cStyles["vMerge"] = 'restart';
|
||||
|
||||
$section = $phpWord->createSection();
|
||||
$table = $section->addTable($tStyles);
|
||||
|
|
@ -257,6 +265,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$cell->addTextBreak();
|
||||
$cell->addLink('http://google.com');
|
||||
$cell->addListItem('Test');
|
||||
$cell->addImage($imageSrc);
|
||||
$cell->addObject($objectSrc);
|
||||
$textrun = $cell->createTextRun();
|
||||
$textrun->addText('Test');
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Document
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Document
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||
|
|
@ -27,6 +26,9 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write end section page numbering
|
||||
*/
|
||||
public function testWriteEndSectionPageNumbering()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
|
|
@ -40,11 +42,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* covers ::_writeTOC
|
||||
* covers ::_writePageBreak
|
||||
* covers ::_writeListItem
|
||||
* covers ::_writeTitle
|
||||
* covers ::_writeObject
|
||||
* Write elements
|
||||
*/
|
||||
public function testElements()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,18 +15,20 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tear down after each test
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* covers ::__construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -57,10 +59,12 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
$localImage = __DIR__ . '/../_files/images/earth.jpg';
|
||||
$remoteImage = 'http://php.net//images/logos/php-med-trans-light.gif';
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
||||
|
|
@ -71,16 +75,55 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
$section = $phpWord->createSection();
|
||||
$textrun = $section->createTextRun();
|
||||
$textrun->addText('Test 3');
|
||||
$footnote = $textrun->createFootnote();
|
||||
$footnote->addLink('http://test.com');
|
||||
$header = $section->createHeader();
|
||||
$header->addImage($localImage);
|
||||
$footer = $section->createFooter();
|
||||
$footer->addImage($remoteImage);
|
||||
|
||||
$writer = new Word2007($phpWord);
|
||||
$file = __DIR__ . "/../_files/temp.docx";
|
||||
$writer->save($file);
|
||||
$this->assertTrue(\file_exists($file));
|
||||
|
||||
$this->assertTrue(file_exists($file));
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkContentTypes
|
||||
* Save using disk caching
|
||||
*/
|
||||
public function testSaveUseDiskCaching()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
|
||||
$writer = new Word2007($phpWord);
|
||||
$writer->setUseDiskCaching(true);
|
||||
$file = __DIR__ . "/../_files/temp.docx";
|
||||
$writer->save($file);
|
||||
|
||||
$this->assertTrue(file_exists($file));
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new Word2007();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check content types
|
||||
*/
|
||||
public function testCheckContentTypes()
|
||||
{
|
||||
|
|
@ -110,20 +153,33 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @covers ::getUseDiskCaching
|
||||
* Get writer part return null value
|
||||
*/
|
||||
public function testGetWriterPartNull()
|
||||
{
|
||||
$object = new Word2007();
|
||||
$this->assertNull($object->getWriterPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get use disk caching
|
||||
*/
|
||||
public function testSetGetUseDiskCaching()
|
||||
{
|
||||
$object = new Word2007();
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$object = new Word2007($phpWord);
|
||||
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
|
||||
$writer = new Word2007($phpWord);
|
||||
$writer->save('php://output');
|
||||
|
||||
$this->assertTrue($object->getUseDiskCaching());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Use disk caching exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testSetUseDiskCachingException()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue