Merge branch 'develop' into #160-refactoring

This commit is contained in:
Ivan Lanin 2014-03-25 09:45:12 +07:00
commit 92a76d0c0c
85 changed files with 272 additions and 10 deletions

View File

@ -38,7 +38,7 @@ before_script:
script:
## PHP_CodeSniffer
- phpcs --standard=PSR2 -n src/
- phpcs --standard=PSR2 -n test/
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose src/
## PHP Mess Detector

View File

@ -1,7 +1,10 @@
# ![PHPWord](https://raw.github.com/PHPOffice/PHPWord/develop/docs/images/phpword.png "PHPWord")
# ![PHPWord](https://raw.githubusercontent.com/PHPOffice/PHPWord/develop/docs/images/phpword.svg "PHPWord")
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.png?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.svg?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).

50
docs/images/phpword.svg Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.2" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 280.016 60" xml:space="preserve" width="280" height="60">
<g id="Calque_1">
<g>
<path fill="#333333" d="M92.934,34.02h-2.996v12.265h-4.4V14.452c3.23-0.141,6.507-0.234,8.895-0.234
c6.835,0,11.188,3.417,11.188,8.941C105.62,30.181,100.002,34.02,92.934,34.02z M93.729,17.869h-3.792v12.593h3.417
c4.167,0,7.724-2.341,7.724-6.647C101.079,20.397,98.458,17.869,93.729,17.869z"/>
<path fill="#333333" d="M133.102,46.285V31.726h-17.228v14.559h-4.4V14.452h4.4V27.84h17.228V14.452h4.354v31.833H133.102z"/>
<path fill="#333333" d="M154.265,34.02h-2.996v12.265h-4.4V14.452c3.23-0.141,6.507-0.234,8.895-0.234
c6.835,0,11.188,3.417,11.188,8.941C166.951,30.181,161.333,34.02,154.265,34.02z M155.061,17.869h-3.792v12.593h3.417
c4.167,0,7.725-2.341,7.725-6.647C162.41,20.397,159.789,17.869,155.061,17.869z"/>
<path fill="#333333" d="M203.14,46.566h-3.558l-7.35-20.505c-0.608-1.732-1.311-5.243-1.311-5.243s-0.655,3.417-1.312,5.243
l-7.303,20.505h-3.511l-10.159-32.115h4.916l6.46,21.628c0.469,1.592,1.077,5.103,1.077,5.103s0.608-3.558,1.123-5.103
l7.304-21.628h3.37l7.443,21.535c0.562,1.638,1.218,5.103,1.218,5.103s0.468-3.417,0.936-5.056l6.414-21.581h4.4L203.14,46.566z"
/>
<path fill="#333333" d="M225.661,46.753c-6.46,0-10.673-5.196-10.673-11.891c0-7.115,4.588-12.452,11.609-12.452
c6.461,0,10.674,5.243,10.674,11.891C237.271,41.417,232.684,46.753,225.661,46.753z M226.083,25.874
c-4.214,0-6.882,3.839-6.882,8.474c0,4.775,2.668,8.988,6.976,8.988c4.166,0,6.882-3.839,6.882-8.52
C233.059,30.087,230.483,25.874,226.083,25.874z"/>
<path fill="#333333" d="M254.501,27.606c-1.171-0.608-2.622-1.03-4.026-1.03c-1.498,0-2.949,0.702-3.745,1.685v18.023h-4.166
V23.159l3.979-0.421l-0.14,3.371h0.14c1.171-2.153,3.23-3.698,5.618-3.698c1.17,0,2.153,0.281,3.043,0.749L254.501,27.606z"/>
<path fill="#333333" d="M279.782,46.238c-0.655,0.188-1.686,0.375-2.669,0.375c-1.919,0-3.137-1.171-3.558-2.95h-0.234
c-1.731,1.919-3.886,3.089-6.741,3.089c-5.945,0-9.784-4.962-9.784-11.656c0-7.35,4.635-12.546,11.798-12.546
c1.498,0,3.511,0.468,4.541,0.937V9.724h4.166V40.34c0,1.826,0.796,2.809,2.715,2.949L279.782,46.238z M273.135,27.513
c-1.171-0.936-3.23-1.545-5.197-1.545c-4.072,0-6.928,3.651-6.928,8.38c0,5.43,2.668,8.941,6.788,8.941
c2.247,0,3.792-0.796,5.337-2.106V27.513z"/>
</g>
</g>
<g id="Calque_2">
<rect fill="#00188F" width="59.875" height="60"/>
</g>
<g id="Calque_3">
<polygon fill="#FFFFFF" points="42.546,19.5 38.804,34.058 34.211,19.5 32.75,19.5 29.547,19.5 28.085,19.5 23.493,34.058
19.75,19.5 12.797,19.5 19.456,40.862 26.659,40.862 31.148,27.016 35.638,40.862 42.841,40.862 49.5,19.5 "/>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,6 +1,6 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./test/bootstrap.php"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
@ -10,7 +10,7 @@
syntaxCheck="false">
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./test/PhpWord/</directory>
<directory>./tests/PhpWord/</directory>
</testsuite>
</testsuites>
<filter>

View File

@ -0,0 +1,78 @@
<?php
namespace PhpOffice\PhpWord\Tests\Section;
use PhpOffice\PhpWord\Section\MemoryImage;
class MemoryImageTest extends \PHPUnit_Framework_TestCase
{
public function testPNG()
{
$src = __DIR__ . "/../_files/images/firefox.png";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng');
$this->assertEquals($oMemoryImage->getImageExtension(), 'png');
$this->assertEquals($oMemoryImage->getImageType(), 'image/png');
}
public function testGIF()
{
$src = __DIR__ . "/../_files/images/mario.gif";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif');
$this->assertEquals($oMemoryImage->getImageExtension(), 'gif');
$this->assertEquals($oMemoryImage->getImageType(), 'image/gif');
}
public function testJPG()
{
$src = __DIR__ . "/../_files/images/earth.jpg";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg');
$this->assertEquals($oMemoryImage->getImageExtension(), 'jpg');
$this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg');
}
public function testBMP()
{
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/duke_nukem.bmp");
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
$this->assertEquals($oMemoryImage->getImageFunction(), null);
$this->assertEquals($oMemoryImage->getImageExtension(), null);
$this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp');
}
public function testStyle()
{
$oMemoryImage = new MemoryImage(
__DIR__ . "/../_files/images/earth.jpg",
array('width' => 210, 'height' => 210, 'align' => 'center')
);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
}
public function testRelationID()
{
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/earth.jpg");
$iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal);
}
}

View File

@ -0,0 +1,130 @@
<?php
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\TableFull;
/**
* @runTestsInSeparateProcesses
*/
class TableFullTest extends \PHPUnit_Framework_TestCase
{
/**
* Test class construction
*
* There are 3 variables for class constructor:
* - $styleTable: Define table styles
* - $styleFirstRow: Define style for the first row
* - $styleLastRow: Define style for the last row (reserved)
*/
public function testConstruct()
{
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new TableFull($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());
$firstRow = $object->getFirstRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TableFull', $firstRow);
$this->assertEquals(3, $firstRow->getBorderBottomSize());
}
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new TableFull();
$attributes = array(
'bgColor' => 'FF0000',
'borderTopSize' => 4,
'borderTopColor' => 'FF0000',
'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000',
'borderRightSize' => 4,
'borderRightColor' => 'FF0000',
'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240,
'cellMarginLeft' => 240,
'cellMarginRight' => 240,
'cellMarginBottom' => 240,
);
foreach ($attributes as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test border color
*
* Set border color and test if each part has the same color
* While looping, push values array to be asserted with getBorderColor
*/
public function testBorderColor()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 'FF0000';
$object->setBorderColor($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderColor());
}
/**
* Test border size
*
* Set border size and test if each part has the same size
* While looping, push values array to be asserted with getBorderSize
* Value is in eights of a point, i.e. 4 / 8 = .5pt
*/
public function testBorderSize()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 4;
$object->setBorderSize($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderSize());
}
/**
* Test cell margin
*
* Set cell margin and test if each part has the same margin
* While looping, push values array to be asserted with getCellMargin
* Value is in twips
*/
public function testCellMargin()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom');
$value = 240;
$object->setCellMargin($value);
foreach ($parts as $part) {
$get = "getCellMargin{$part}";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getCellMargin());
}
}

View File

@ -5,6 +5,7 @@ use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Template;
/**
* @covers \PhpOffice\PhpWord\Template
* @coversDefaultClass \PhpOffice\PhpWord\Template
*/
final class TemplateTest extends \PHPUnit_Framework_TestCase
@ -115,8 +116,8 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers ::setValue
* @covers ::getVariables
* @covers ::setValue
* @covers ::cloneRow
* @covers ::saveAs
*/
@ -126,13 +127,13 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
$docName = 'clone-test-result.docx';
$phpWord = new PhpWord();
$document = $phpWord->loadTemplate($template);
$document = new Template($template);
$actualVar = $document->getVariables();
$document->setValue('tableHeader', utf8_decode('ééé'));
$document->cloneRow('userId', 1);
$document->setValue('userId#1', 'Test');
$document->saveAs($docName);
$docFound = \file_exists($docName);
$docFound = file_exists($docName);
unlink($docName);
$this->assertEquals($expectedVar, $actualVar);

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 952 KiB

After

Width:  |  Height:  |  Size: 952 KiB

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB