Fixed unit tests

This commit is contained in:
Gabriel Bull 2014-03-23 12:37:31 -04:00
parent 66c73c07c5
commit d75c00caf4
26 changed files with 92 additions and 257 deletions

View File

@ -42,12 +42,12 @@ class MediaTest extends \PHPUnit_Framework_TestCase
public function testAddSectionMediaElement() public function testAddSectionMediaElement()
{ {
$section = new Section(0); $section = new Section(0);
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg"); $section->addImage(__DIR__ . "/_files/images/mars_noext_jpg");
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg"); $section->addImage(__DIR__ . "/_files/images/mars.jpg");
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif"); $section->addImage(__DIR__ . "/_files/images/mario.gif");
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png"); $section->addImage(__DIR__ . "/_files/images/firefox.png");
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp"); $section->addImage(__DIR__ . "/_files/images/duke_nukem.bmp");
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif"); $section->addImage(__DIR__ . "/_files/images/angela_merkel.tif");
$elements = $section->getElements(); $elements = $section->getElements();
$this->assertEquals(6, count($elements)); $this->assertEquals(6, count($elements));

View File

@ -130,10 +130,8 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
*/ */
public function testLoadTemplate() public function testLoadTemplate()
{ {
$templateFqfn = \join( $templateFqfn = __DIR__ . "/_files/templates/blank.docx";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blank.docx')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$this->assertInstanceOf( $this->assertInstanceOf(
'PhpOffice\\PhpWord\\Template', 'PhpOffice\\PhpWord\\Template',

View File

@ -18,10 +18,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
*/ */
public function testCanRead() public function testCanRead()
{ {
$dir = join( $dir = __DIR__ . "/../_files/documents";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
);
$object = new Word2007; $object = new Word2007;
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx'; $file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
$this->assertTrue($object->canRead($file)); $this->assertTrue($object->canRead($file));
@ -32,10 +29,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
*/ */
public function testCanReadFailed() public function testCanReadFailed()
{ {
$dir = join( $dir = __DIR__ . "/../_files/documents";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
);
$object = new Word2007; $object = new Word2007;
$file = $dir . \DIRECTORY_SEPARATOR . 'foo.docx'; $file = $dir . \DIRECTORY_SEPARATOR . 'foo.docx';
$this->assertFalse($object->canRead($file)); $this->assertFalse($object->canRead($file));
@ -47,10 +41,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
*/ */
public function testLoad() public function testLoad()
{ {
$dir = join( $dir = __DIR__ . "/../_files/documents";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents')
);
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx'; $file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
$object = IOFactory::load($file); $object = IOFactory::load($file);
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object); $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object);

View File

@ -30,7 +30,6 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
} }
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
@ -72,10 +71,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddImage() public function testAddImage()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oFooter = new Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addImage($src); $element = $oFooter->addImage($src);

View File

@ -68,10 +68,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddImage() public function testAddImage()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oHeader = new Header(1); $oHeader = new Header(1);
$element = $oHeader->addImage($src); $element = $oHeader->addImage($src);
@ -111,10 +108,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddWatermark() public function testAddWatermark()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oHeader = new Header(1); $oHeader = new Header(1);
$element = $oHeader->addWatermark($src); $element = $oHeader->addWatermark($src);

View File

@ -10,10 +10,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/firefox.png";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
);
$oImage = new Image($src); $oImage = new Image($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
@ -25,10 +22,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testConstructWithStyle() public function testConstructWithStyle()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/firefox.png";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
);
$oImage = new Image( $oImage = new Image(
$src, $src,
array('width' => 210, 'height' => 210, 'align' => 'center', array('width' => 210, 'height' => 210, 'align' => 'center',
@ -43,12 +37,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testValidImageTypes() public function testValidImageTypes()
{ {
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg"); new Image(__DIR__ . "/../_files/images/mars_noext_jpg");
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg"); new Image(__DIR__ . "/../_files/images/mars.jpg");
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif"); new Image(__DIR__ . "/../_files/images/mario.gif");
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png"); new Image(__DIR__ . "/../_files/images/firefox.png");
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp"); new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif"); new Image(__DIR__ . "/../_files/images/angela_merkel.tif");
} }
/** /**
@ -57,7 +51,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testImageNotFound() public function testImageNotFound()
{ {
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/thisisnotarealimage"); new Image(__DIR__ . "/../_files/images/thisisnotarealimage");
} }
/** /**
@ -66,26 +60,22 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInvalidImageTypes() public function testInvalidImageTypes()
{ {
new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/alexz-johnson.pcx"); new Image(__DIR__ . "/../_files/images/alexz-johnson.pcx");
} }
public function testStyle() public function testStyle()
{ {
$oImage = new Image(\join( $oImage = new Image(
\DIRECTORY_SEPARATOR, __DIR__ . "/../_files/images/earth.jpg",
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') array('width' => 210, 'height' => 210, 'align' => 'center')
), array('width' => 210, 'height' => 210, 'align' => 'center')); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
public function testRelationID() public function testRelationID()
{ {
$oImage = new Image(\join( $oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oImage->setRelationId($iVal); $oImage->setRelationId($iVal);
$this->assertEquals($oImage->getRelationId(), $iVal); $this->assertEquals($oImage->getRelationId(), $iVal);
@ -93,11 +83,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testWatermark() public function testWatermark()
{ {
$oImage = new Image(\join( $oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
));
$oImage->setIsWatermark(true); $oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true); $this->assertEquals($oImage->getIsWatermark(), true);
} }

View File

@ -7,10 +7,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
{ {
public function testPNG() public function testPNG()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/firefox.png";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png')
);
$oMemoryImage = new MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@ -24,10 +21,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testGIF() public function testGIF()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/mario.gif";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'mario.gif')
);
$oMemoryImage = new MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@ -41,10 +35,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testJPG() public function testJPG()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oMemoryImage = new MemoryImage($src); $oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
@ -58,10 +49,7 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testBMP() public function testBMP()
{ {
$oMemoryImage = new MemoryImage(\join( $oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/duke_nukem.bmp");
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'duke_nukem.bmp')
));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null); $this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
@ -72,20 +60,16 @@ class MemoryImageTest extends \PHPUnit_Framework_TestCase
public function testStyle() public function testStyle()
{ {
$oMemoryImage = new MemoryImage(\join( $oMemoryImage = new MemoryImage(
\DIRECTORY_SEPARATOR, __DIR__ . "/../_files/images/earth.jpg",
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') array('width' => 210, 'height' => 210, 'align' => 'center')
), array('width' => 210, 'height' => 210, 'align' => 'center')); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
} }
public function testRelationID() public function testRelationID()
{ {
$oMemoryImage = new MemoryImage(\join( $oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/earth.jpg");
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal); $oMemoryImage->setRelationId($iVal);

View File

@ -7,10 +7,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstructWithSupportedFiles() public function testConstructWithSupportedFiles()
{ {
$src = \join( $src = __DIR__ . "/../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oObject = new Object($src); $oObject = new Object($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@ -20,10 +17,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
public function testConstructWithNotSupportedFiles() public function testConstructWithNotSupportedFiles()
{ {
$src = \join( $src = __DIR__ . "/../_files/xsl/passthrough.xsl";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl')
);
$oObject = new Object($src); $oObject = new Object($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@ -33,10 +27,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
public function testConstructWithSupportedFilesAndStyle() public function testConstructWithSupportedFilesAndStyle()
{ {
$src = \join( $src = __DIR__ . "/../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oObject = new Object($src, array('width' => '230px')); $oObject = new Object($src, array('width' => '230px'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
@ -46,10 +37,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
public function testRelationId() public function testRelationId()
{ {
$src = \join( $src = __DIR__ . "/../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oObject = new Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
@ -59,10 +47,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
public function testImageRelationId() public function testImageRelationId()
{ {
$src = \join( $src = __DIR__ . "/../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oObject = new Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
@ -72,10 +57,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
public function testObjectId() public function testObjectId()
{ {
$src = \join( $src = __DIR__ . "/../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oObject = new Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);

View File

@ -89,10 +89,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddImageSection() public function testAddImageSection()
{ {
$src = \join( $src = __DIR__ . "/../../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oCell = new Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -102,10 +99,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddImageHeader() public function testAddImageHeader()
{ {
$src = \join( $src = __DIR__ . "/../../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oCell = new Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -115,10 +109,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddImageFooter() public function testAddImageFooter()
{ {
$src = \join( $src = __DIR__ . "/../../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oCell = new Cell('footer', 1); $oCell = new Cell('footer', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -161,10 +152,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddObjectXLS() public function testAddObjectXLS()
{ {
$src = \join( $src = __DIR__ . "/../../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$oCell = new Cell('section', 1); $oCell = new Cell('section', 1);
$element = $oCell->addObject($src); $element = $oCell->addObject($src);

View File

@ -75,10 +75,8 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
public function testAddImage() public function testAddImage()
{ {
$src = \join( $src = __DIR__ . "/../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$oTextRun = new TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addImage($src); $element = $oTextRun->addImage($src);

View File

@ -73,14 +73,8 @@ class SectionTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddElements() public function testAddElements()
{ {
$objectSource = join( $objectSource = __DIR__ . "/_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR, $imageSource = __DIR__ . "/_files/images/PhpWord.png";
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$imageSource = join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png')
);
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new Section(0); $section = new Section(0);

View File

@ -14,7 +14,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFileExists() public function testFileExists()
{ {
$dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); $dir = __DIR__ . "/../_files/templates";
chdir($dir); chdir($dir);
$this->assertTrue(File::file_exists('blank.docx')); $this->assertTrue(File::file_exists('blank.docx'));
} }
@ -23,7 +23,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
*/ */
public function testNoFileExists() public function testNoFileExists()
{ {
$dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); $dir = __DIR__ . "/../_files/templates";
chdir($dir); chdir($dir);
$this->assertFalse(File::file_exists('404.docx')); $this->assertFalse(File::file_exists('404.docx'));
} }
@ -33,7 +33,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
*/ */
public function testRealpath() public function testRealpath()
{ {
$dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); $dir = realpath(__DIR__ . "/../_files/templates");
chdir($dir); chdir($dir);
$file = 'blank.docx'; $file = 'blank.docx';
$expected = $dir . \DIRECTORY_SEPARATOR . $file; $expected = $dir . \DIRECTORY_SEPARATOR . $file;

View File

@ -3,7 +3,7 @@ namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses

View File

@ -4,7 +4,7 @@ namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\Tab; use PhpOffice\PhpWord\Style\Tab;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses

View File

@ -3,7 +3,7 @@ namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Tab; use PhpOffice\PhpWord\Style\Tab;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses

View File

@ -15,19 +15,11 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
final public function testTemplateCanBeSavedInTemporaryLocation() final public function testTemplateCanBeSavedInTemporaryLocation()
{ {
$templateFqfn = \join( $templateFqfn = __DIR__ . "/_files/templates/with_table_macros.docx";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'with_table_macros.docx')
);
$document = new Template($templateFqfn); $document = new Template($templateFqfn);
$xslDOMDocument = new \DOMDocument(); $xslDOMDocument = new \DOMDocument();
$xslDOMDocument->load( $xslDOMDocument->load(__DIR__ . "/_files/xsl/remove_tables_by_needle.xsl");
\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'remove_tables_by_needle.xsl')
)
);
foreach (array('${employee.', '${scoreboard.') as $needle) { foreach (array('${employee.', '${scoreboard.') as $needle) {
$document->applyXslStyleSheet($xslDOMDocument, array('needle' => $needle)); $document->applyXslStyleSheet($xslDOMDocument, array('needle' => $needle));
} }
@ -63,10 +55,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn)
{ {
$expectedDocumentFqfn = \join( $expectedDocumentFqfn = __DIR__ . "/_files/documents/without_table_macros.docx";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'without_table_macros.docx')
);
$actualDocumentZip = new \ZipArchive(); $actualDocumentZip = new \ZipArchive();
$actualDocumentZip->open($actualDocumentFqfn); $actualDocumentZip->open($actualDocumentFqfn);
@ -93,20 +82,10 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue() final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue()
{ {
$template = new Template( $template = new Template(__DIR__ . "/_files/templates/blank.docx");
\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blank.docx')
)
);
$xslDOMDocument = new \DOMDocument(); $xslDOMDocument = new \DOMDocument();
$xslDOMDocument->load( $xslDOMDocument->load(__DIR__ . "/_files/xsl/passthrough.xsl");
\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl')
)
);
/* /*
* We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure. * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure.
@ -123,20 +102,10 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate() final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate()
{ {
$template = new Template( $template = new Template(__DIR__ . "/_files/templates/corrupted_main_document_part.docx");
\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'corrupted_main_document_part.docx')
)
);
$xslDOMDocument = new \DOMDocument(); $xslDOMDocument = new \DOMDocument();
$xslDOMDocument->load( $xslDOMDocument->load(__DIR__ . "/_files/xsl/passthrough.xsl");
\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl')
)
);
/* /*
* We have to use error control below, because \DOMDocument::loadXML omits warning on failure. * We have to use error control below, because \DOMDocument::loadXML omits warning on failure.
@ -153,10 +122,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCloneRow() public function testCloneRow()
{ {
$template = \join( $template = __DIR__ . "/_files/templates/clone-merge.docx";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'clone-merge.docx')
);
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation'); $expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
$docName = 'clone-test-result.docx'; $docName = 'clone-test-result.docx';

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\ODText; namespace PhpOffice\PhpWord\Tests\Writer\ODText;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Content * @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Content
@ -24,14 +24,8 @@ class ContentTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteContent() public function testWriteContent()
{ {
$imageSrc = \join( $imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
\DIRECTORY_SEPARATOR, $objectSrc = __DIR__ . "/../../_files/documents/sheet.xls";
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png')
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$expected = 'Expected'; $expected = 'Expected';
$phpWord = new PhpWord(); $phpWord = new PhpWord();

View File

@ -49,18 +49,9 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSave() public function testSave()
{ {
$imageSrc = \join( $imageSrc = __DIR__ . "/../_files/images/PhpWord.png";
\DIRECTORY_SEPARATOR, $objectSrc = __DIR__ . "/../_files/documents/sheet.xls";
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') $file = __DIR__ . "/../_files/temp.odt";
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$file = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.odt')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addFontStyle('Font', array('size' => 11));

View File

@ -62,18 +62,9 @@ class RTFTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSave() public function testSave()
{ {
$imageSrc = \join( $imageSrc = __DIR__ . "/../_files/images/PhpWord.png";
\DIRECTORY_SEPARATOR, $objectSrc = __DIR__ . "/../_files/documents/sheet.xls";
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') $file = __DIR__ . "/../_files/temp.rtf";
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$file = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.rtf')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addFontStyle('Font', array('size' => 11));

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\Word2007; namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Base * @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Base
@ -46,10 +46,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
{ {
$pStyle = 'pStyle'; $pStyle = 'pStyle';
$aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120);
$imageSrc = join( $imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addParagraphStyle($pStyle, $aStyle); $phpWord->addParagraphStyle($pStyle, $aStyle);
@ -297,7 +294,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->createSection(); $section = $phpWord->createSection();
$section->addImage( $section->addImage(
\PHPWORD_TESTS_BASE_DIR . '/data/images/earth.jpg', __DIR__ . "/../../_files/images/earth.jpg",
array( array(
'marginTop' => -1, 'marginTop' => -1,
'marginLeft' => -1, 'marginLeft' => -1,
@ -319,10 +316,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteWatermark() public function testWriteWatermark()
{ {
$imageSrc = join( $imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->createSection(); $section = $phpWord->createSection();

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\Word2007; namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
@ -38,10 +38,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
*/ */
public function testElements() public function testElements()
{ {
$objectSrc = join( $objectSrc = __DIR__ . "/../../_files/documents/sheet.xls";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls')
);
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); $phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true));

View File

@ -3,7 +3,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\Writer\Word2007\Footer; use PhpOffice\PhpWord\Writer\Word2007\Footer;
use PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\Writer\Word2007;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* Class FooterTest * Class FooterTest
@ -19,10 +19,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteFooter() public function testWriteFooter()
{ {
$imageSrc = \join( $imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png')
);
$container = new \PhpOffice\PhpWord\Section\Footer(1); $container = new \PhpOffice\PhpWord\Section\Footer(1);
$container->addText(''); $container->addText('');
$container->addPreserveText(''); $container->addPreserveText('');

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\Word2007; namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses

View File

@ -3,7 +3,7 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\Writer\Word2007\Header; use PhpOffice\PhpWord\Writer\Word2007\Header;
use PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\Writer\Word2007;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* Class HeaderTest * Class HeaderTest
@ -19,10 +19,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteHeader() public function testWriteHeader()
{ {
$imageSrc = \join( $imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png')
);
$container = new \PhpOffice\PhpWord\Section\Header(1); $container = new \PhpOffice\PhpWord\Section\Header(1);
$container->addText('Test'); $container->addText('Test');

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpWord\Tests\Writer\Word2007; namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses

View File

@ -3,7 +3,7 @@ namespace PhpOffice\PhpWord\Tests\Writer;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\Writer\Word2007;
use PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
/** /**
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007 * @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007
@ -64,10 +64,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
$textrun->addText('Test 3'); $textrun->addText('Test 3');
$writer = new Word2007($phpWord); $writer = new Word2007($phpWord);
$file = \join( $file = __DIR__ . "/../_files/temp.docx";
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.docx')
);
$writer->save($file); $writer->save($file);
$this->assertTrue(file_exists($file)); $this->assertTrue(file_exists($file));
unlink($file); unlink($file);
@ -89,7 +86,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->createSection(); $section = $phpWord->createSection();
foreach ($images as $source => $target) { foreach ($images as $source => $target) {
$section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/{$source}"); $section->addImage(__DIR__ . "/../_files/images/{$source}");
} }
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
@ -97,7 +94,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
foreach ($images as $source => $target) { foreach ($images as $source => $target) {
$this->assertFileEquals( $this->assertFileEquals(
\PHPWORD_TESTS_BASE_DIR . "/data/images/{$source}", __DIR__ . "/../_files/images/{$source}",
$mediaPath . "/section_image{$target}" $mediaPath . "/section_image{$target}"
); );
} }