Skip to content

Commit 0360f8e

Browse files
committed
Unit tests for TCPDF and mPDF
1 parent f7bee23 commit 0360f8e

File tree

8 files changed

+218
-14
lines changed

8 files changed

+218
-14
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ before_script:
2222
- sudo apt-get -qq install graphviz > /dev/null
2323
## Composer
2424
- composer self-update
25-
- composer require dompdf/dompdf:0.6.*
26-
- composer update --prefer-source --dev
2725
- composer install --prefer-source --dev
2826
## PHP Copy/Paste Detector
2927
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"require-dev": {
4040
"phpunit/phpunit": "3.7.*",
4141
"phpdocumentor/phpdocumentor":"2.*",
42-
"squizlabs/php_codesniffer": "1.*"
42+
"squizlabs/php_codesniffer": "1.*",
43+
"dompdf/dompdf":"0.6.*",
44+
"tecnick.com/tcpdf": "6.*",
45+
"mpdf/mpdf": "5.*"
4346
},
4447
"suggest": {
4548
"ext-gd2": "Required to add images",

composer.lock

Lines changed: 109 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/Sample_Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PhpOffice\PhpWord\Settings;
77
use PhpOffice\PhpWord\IOFactory;
88

9-
error_reporting(E_ALL);
9+
error_reporting(E_ALL & ~E_DEPRECATED);
1010
define('CLI', (PHP_SAPI == 'cli') ? true : false);
1111
define('EOL', CLI ? PHP_EOL : '<br />');
1212
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));

src/PhpWord/Writer/PDF/MPDF.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MPDF extends AbstractRenderer implements WriterInterface
3232
*
3333
* @var string
3434
*/
35-
protected $includeFile = 'mdf.php';
35+
protected $includeFile = 'mpdf.php';
3636

3737
/**
3838
* Save PhpWord to file

tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase
3333
public function testConstruct()
3434
{
3535
define('DOMPDF_ENABLE_AUTOLOAD', false);
36-
$file = __DIR__ . "/../../_files/temp.pdf";
36+
$file = __DIR__ . "/../../_files/dompdf.pdf";
3737

3838
$phpWord = new PhpWord();
3939
$section = $phpWord->addSection();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
namespace PhpOffice\PhpWord\Tests\Writer\PDF;
18+
19+
use PhpOffice\PhpWord\PhpWord;
20+
use PhpOffice\PhpWord\Settings;
21+
use PhpOffice\PhpWord\Writer\PDF;
22+
23+
/**
24+
* Test class for PhpOffice\PhpWord\Writer\PDF\MPDF
25+
*
26+
* @runTestsInSeparateProcesses
27+
*/
28+
class MPDFTest extends \PHPUnit_Framework_TestCase
29+
{
30+
/**
31+
* Test construct
32+
*/
33+
public function testConstruct()
34+
{
35+
$file = __DIR__ . "/../../_files/mpdf.pdf";
36+
37+
$phpWord = new PhpWord();
38+
$section = $phpWord->addSection();
39+
$section->addText('Test 1');
40+
41+
$rendererName = Settings::PDF_RENDERER_MPDF;
42+
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');
43+
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
44+
$writer = new PDF($phpWord);
45+
$writer->save($file);
46+
47+
$this->assertTrue(file_exists($file));
48+
49+
unlink($file);
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
namespace PhpOffice\PhpWord\Tests\Writer\PDF;
18+
19+
use PhpOffice\PhpWord\PhpWord;
20+
use PhpOffice\PhpWord\Settings;
21+
use PhpOffice\PhpWord\Writer\PDF;
22+
23+
/**
24+
* Test class for PhpOffice\PhpWord\Writer\PDF\TCPDF
25+
*
26+
* @runTestsInSeparateProcesses
27+
*/
28+
class TCPDFTest extends \PHPUnit_Framework_TestCase
29+
{
30+
/**
31+
* Test construct
32+
*/
33+
public function testConstruct()
34+
{
35+
$file = __DIR__ . "/../../_files/tcpdf.pdf";
36+
37+
$phpWord = new PhpWord();
38+
$section = $phpWord->addSection();
39+
$section->addText('Test 1');
40+
41+
$rendererName = Settings::PDF_RENDERER_TCPDF;
42+
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf');
43+
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
44+
$writer = new PDF($phpWord);
45+
$writer->save($file);
46+
47+
$this->assertTrue(file_exists($file));
48+
49+
unlink($file);
50+
}
51+
}

0 commit comments

Comments
 (0)