Unit test for PHPWord\Style
This commit is contained in:
parent
1fbea54b4b
commit
d4d42752d4
|
|
@ -243,7 +243,9 @@ class PHPWord_Section
|
|||
$this->_elementCollection[] = $object;
|
||||
return $object;
|
||||
} else {
|
||||
trigger_error('Source does not exist or unsupported object type.');
|
||||
throw new PHPWord_Exception(
|
||||
'Source does not exist or unsupported object type.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +267,9 @@ class PHPWord_Section
|
|||
$this->_elementCollection[] = $image;
|
||||
return $image;
|
||||
} else {
|
||||
trigger_error('Source does not exist or unsupported image type.');
|
||||
throw new PHPWord_Exception(
|
||||
'Source does not exist or unsupported image type.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +290,9 @@ class PHPWord_Section
|
|||
$this->_elementCollection[] = $memoryImage;
|
||||
return $memoryImage;
|
||||
} else {
|
||||
trigger_error('Unsupported image type.');
|
||||
throw new PHPWord_Exception(
|
||||
'Unsupported image type.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ use PHPUnit_Framework_TestCase;
|
|||
use PHPWord_Section;
|
||||
|
||||
/**
|
||||
* Class TOCTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @covers PHPWord_Section
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class SectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
|
@ -44,4 +48,87 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||
$oSection = new PHPWord_Section(0);
|
||||
$this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section::setSettings
|
||||
*/
|
||||
public function testSetSettings()
|
||||
{
|
||||
$expected = 'landscape';
|
||||
$object = new PHPWord_Section(0);
|
||||
$object->setSettings(array('orientation' => $expected));
|
||||
$this->assertEquals($expected, $object->getSettings()->getOrientation());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section::addText
|
||||
* @covers PHPWord_Section::addLink
|
||||
* @covers PHPWord_Section::addTextBreak
|
||||
* @covers PHPWord_Section::addPageBreak
|
||||
* @covers PHPWord_Section::addTable
|
||||
* @covers PHPWord_Section::addListItem
|
||||
* @covers PHPWord_Section::addObject
|
||||
* @covers PHPWord_Section::addImage
|
||||
* @covers PHPWord_Section::addMemoryImage
|
||||
* @covers PHPWord_Section::addTOC
|
||||
* @covers PHPWord_Section::addTitle
|
||||
* @covers PHPWord_Section::createTextRun
|
||||
* @covers PHPWord_Section::createFootnote
|
||||
*/
|
||||
public function testAddElements()
|
||||
{
|
||||
$objectSource = join(
|
||||
DIRECTORY_SEPARATOR,
|
||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
|
||||
);
|
||||
$imageSource = join(
|
||||
DIRECTORY_SEPARATOR,
|
||||
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
|
||||
);
|
||||
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
|
||||
|
||||
$section = new PHPWord_Section(0);
|
||||
$section->addText(utf8_decode('ä'));
|
||||
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
|
||||
$section->addTextBreak();
|
||||
$section->addPageBreak();
|
||||
$section->addTable();
|
||||
$section->addListItem(utf8_decode('ä'));
|
||||
$section->addObject($objectSource);
|
||||
$section->addImage($imageSource);
|
||||
$section->addMemoryImage($imageUrl);
|
||||
$section->addTOC();
|
||||
$section->addTitle(utf8_decode('ä'), 1);
|
||||
$section->createTextRun();
|
||||
$section->createFootnote();
|
||||
|
||||
$elementCollection = $section->getElements();
|
||||
$elementType = 'Link';
|
||||
$objectType = "PHPWord_Section_{$elementType}";
|
||||
$this->assertInstanceOf($objectType, $elementCollection[1]);
|
||||
// $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
|
||||
// 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC',
|
||||
// 'Title', 'TextRun');
|
||||
// $i = 0;
|
||||
// foreach ($elementTypes as $elementType) {
|
||||
// $objectType = "PHPWord_Section_{$elementType}";
|
||||
// $this->assertInstanceOf($objectType, $elementCollection[$i]);
|
||||
// $i++;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPWord_Section::createHeader
|
||||
* @covers PHPWord_Section::createFooter
|
||||
*/
|
||||
public function testCreateHeaderFooter()
|
||||
{
|
||||
$object = new PHPWord_Section(0);
|
||||
$elements = array('Header', 'Footer');
|
||||
foreach ($elements as $element) {
|
||||
$objectType = "PHPWord_Section_{$element}";
|
||||
$method = "create{$element}";
|
||||
$this->assertInstanceOf($objectType, $object->$method());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use PHPWord_Style_TOC;
|
|||
* Class TOCTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @covers PHPWord_Style_TOC
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class TOCTest extends \PHPUnit_Framework_TestCase
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Style;
|
||||
|
||||
/**
|
||||
* Class StyleTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @covers PHPWord_Style
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class StyleTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers PHPWord_Style::addParagraphStyle
|
||||
* @covers PHPWord_Style::addFontStyle
|
||||
* @covers PHPWord_Style::addLinkStyle
|
||||
* @covers PHPWord_Style::addTitleStyle
|
||||
*/
|
||||
public function testStyles()
|
||||
{
|
||||
$paragraph = array('align' => 'center');
|
||||
$font = array('italic' => true);
|
||||
$table = array('bgColor' => 'CCCCCC');
|
||||
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
|
||||
'Link' => 'Font', 'Table' => 'TableFull',
|
||||
'Heading_1' => 'Font', 'Normal' => 'Paragraph');
|
||||
$elementCount = 6;
|
||||
PHPWord_Style::addParagraphStyle('Paragraph', $paragraph);
|
||||
PHPWord_Style::addFontStyle('Font', $font);
|
||||
PHPWord_Style::addLinkStyle('Link', $font);
|
||||
PHPWord_Style::addTableStyle('Table', $table);
|
||||
PHPWord_Style::addTitleStyle(1, $font);
|
||||
PHPWord_Style::setDefaultParagraphStyle($paragraph);
|
||||
|
||||
$this->assertEquals($elementCount, count(PHPWord_Style::getStyles()));
|
||||
foreach ($styles as $name => $style) {
|
||||
$expected = "PHPWord_Style_{$style}";
|
||||
$this->assertInstanceOf($expected, PHPWord_Style::getStyle($name));
|
||||
}
|
||||
$this->assertNull(PHPWord_Style::getStyle('Unknown'));
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,11 @@ use PHPWord_TOC;
|
|||
use PHPWord_Style_TOC;
|
||||
|
||||
/**
|
||||
* @covers PHPWord_TOC
|
||||
* Class TOCTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @covers PHPWord_TOC
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class TOCTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
|
@ -46,7 +50,7 @@ class TOCTest extends PHPUnit_Framework_TestCase
|
|||
// Prepare variables
|
||||
$titleCount = 3;
|
||||
$anchor = '_Toc' . (252634154 + $titleCount);
|
||||
$bookmark = $titleCount - 1; // zero based
|
||||
$bookmark = $titleCount - 1;
|
||||
$titles = array(
|
||||
'Heading 1' => 1,
|
||||
'Heading 2' => 2,
|
||||
|
|
|
|||
|
|
@ -66,23 +66,28 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testCheckContentTypes()
|
||||
{
|
||||
$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',
|
||||
);
|
||||
$phpWord = new PHPWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
|
||||
foreach ($images as $source => $target) {
|
||||
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}");
|
||||
}
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$mediaPath = $doc->getPath() . "/word/media";
|
||||
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg", $mediaPath . "/section_image1.jpg");
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg", $mediaPath . "/section_image2.jpg");
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif", $mediaPath . "/section_image3.gif");
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png", $mediaPath . "/section_image4.png");
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp", $mediaPath . "/section_image5.bmp");
|
||||
$this->assertFileEquals(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif", $mediaPath . "/section_image6.tif");
|
||||
foreach ($images as $source => $target) {
|
||||
$this->assertFileEquals(
|
||||
PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}",
|
||||
$mediaPath . "/section_image{$target}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,11 @@ use PHPWord_Section;
|
|||
use PHPWord_Style;
|
||||
|
||||
/**
|
||||
* @covers PHPWord
|
||||
* Class PHPWordTest
|
||||
*
|
||||
* @package PHPWord\Tests
|
||||
* @covers PHPWord
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class PHPWordTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue