From 0360f8e290c02aefc32b99b868def6b57e1e9794 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Mon, 19 May 2014 23:21:17 +0700 Subject: [PATCH] Unit tests for TCPDF and mPDF --- .travis.yml | 2 - composer.json | 5 +- composer.lock | 117 ++++++++++++++++-- samples/Sample_Header.php | 2 +- src/PhpWord/Writer/PDF/MPDF.php | 2 +- tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php | 2 +- tests/PhpWord/Tests/Writer/PDF/MPDFTest.php | 51 ++++++++ tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php | 51 ++++++++ 8 files changed, 218 insertions(+), 14 deletions(-) create mode 100644 tests/PhpWord/Tests/Writer/PDF/MPDFTest.php create mode 100644 tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php diff --git a/.travis.yml b/.travis.yml index d4f511da..63165dbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,8 +22,6 @@ before_script: - sudo apt-get -qq install graphviz > /dev/null ## Composer - composer self-update - - composer require dompdf/dompdf:0.6.* - - composer update --prefer-source --dev - composer install --prefer-source --dev ## PHP Copy/Paste Detector - curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar diff --git a/composer.json b/composer.json index a201a033..b9eef98d 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,10 @@ "require-dev": { "phpunit/phpunit": "3.7.*", "phpdocumentor/phpdocumentor":"2.*", - "squizlabs/php_codesniffer": "1.*" + "squizlabs/php_codesniffer": "1.*", + "dompdf/dompdf":"0.6.*", + "tecnick.com/tcpdf": "6.*", + "mpdf/mpdf": "5.*" }, "suggest": { "ext-gd2": "Required to add images", diff --git a/composer.lock b/composer.lock index aab180be..172e564e 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "d46ea4154e935e4be01ffbad0a67bab2", + "hash": "91993ff980d11a416fcf3a7309a4044f", "packages": [ ], @@ -619,6 +619,49 @@ ], "time": "2014-04-24 13:29:03" }, + { + "name": "mpdf/mpdf", + "version": "v5.7.2", + "source": { + "type": "git", + "url": "https://github.com/finwe/mpdf.git", + "reference": "1627f9e7d2ef0f635a886f611079216ed2929717" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/finwe/mpdf/zipball/1627f9e7d2ef0f635a886f611079216ed2929717", + "reference": "1627f9e7d2ef0f635a886f611079216ed2929717", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=4.3.10" + }, + "type": "library", + "autoload": { + "classmap": [ + "mpdf.php", + "classes" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-1.0+" + ], + "authors": [ + { + "name": "Ian Back" + } + ], + "description": "A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support", + "homepage": "http://www.mpdf1.com/mpdf/index.php", + "keywords": [ + "pdf", + "php", + "utf-8" + ], + "time": "2014-05-16 07:18:10" + }, { "name": "nikic/php-parser", "version": "v0.9.4", @@ -833,16 +876,16 @@ }, { "name": "phpdocumentor/phpdocumentor", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/phpDocumentor2.git", - "reference": "d7503ada7386aa6b2956224d50a8d0226a22a99f" + "reference": "bf9fa40f6d00412410025b2e16eb16c315eb0216" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/phpDocumentor2/zipball/d7503ada7386aa6b2956224d50a8d0226a22a99f", - "reference": "d7503ada7386aa6b2956224d50a8d0226a22a99f", + "url": "https://api.github.com/repos/phpDocumentor/phpDocumentor2/zipball/bf9fa40f6d00412410025b2e16eb16c315eb0216", + "reference": "bf9fa40f6d00412410025b2e16eb16c315eb0216", "shasum": "" }, "require": { @@ -895,12 +938,13 @@ "ext-xslcache": "Enabling the XSLCache extension improves the generation of xml based templates." }, "bin": [ - "bin/phpdoc.php" + "bin/phpdoc.php", + "bin/phpdoc" ], "type": "library", "extra": { "branch-alias": { - "dev-develop": "2.4-dev" + "dev-develop": "2.5-dev" } }, "autoload": { @@ -924,7 +968,7 @@ "documentation", "phpdoc" ], - "time": "2014-04-01 18:14:51" + "time": "2014-05-17 12:25:35" }, { "name": "phpdocumentor/reflection", @@ -2528,6 +2572,63 @@ "homepage": "http://symfony.com", "time": "2014-04-18 20:37:09" }, + { + "name": "tecnick.com/tcpdf", + "version": "6.0.078", + "source": { + "type": "git", + "url": "git://git.code.sf.net/p/tcpdf/code", + "reference": "e1cbda79b99f3cdc8fdf26b39eb4870d2cd9fbac" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "fonts", + "config", + "include", + "tcpdf.php", + "tcpdf_parser.php", + "tcpdf_import.php", + "tcpdf_barcodes_1d.php", + "tcpdf_barcodes_2d.php", + "include/tcpdf_colors.php", + "include/tcpdf_filters.php", + "include/tcpdf_font_data.php", + "include/tcpdf_fonts.php", + "include/tcpdf_images.php", + "include/tcpdf_static.php", + "include/barcodes/datamatrix.php", + "include/barcodes/pdf417.php", + "include/barcodes/qrcode.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPLv3" + ], + "authors": [ + { + "name": "Nicola Asuni", + "email": "info@tecnick.com", + "homepage": "http://nicolaasuni.tecnick.com" + } + ], + "description": "TCPDF is a PHP class for generating PDF documents.", + "homepage": "http://www.tcpdf.org/", + "keywords": [ + "PDFD32000-2008", + "TCPDF", + "barcodes", + "datamatrix", + "pdf", + "pdf417", + "qrcode" + ], + "time": "2014-05-12 19:50:13" + }, { "name": "twig/twig", "version": "v1.15.1", diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index fdada151..b752848d 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -6,7 +6,7 @@ use PhpOffice\PhpWord\Autoloader; use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\IOFactory; -error_reporting(E_ALL); +error_reporting(E_ALL & ~E_DEPRECATED); define('CLI', (PHP_SAPI == 'cli') ? true : false); define('EOL', CLI ? PHP_EOL : '
'); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index 77bbafd6..e12e53ae 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -32,7 +32,7 @@ class MPDF extends AbstractRenderer implements WriterInterface * * @var string */ - protected $includeFile = 'mdf.php'; + protected $includeFile = 'mpdf.php'; /** * Save PhpWord to file diff --git a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php index a2c8fb31..a22cb530 100644 --- a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php +++ b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php @@ -33,7 +33,7 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase public function testConstruct() { define('DOMPDF_ENABLE_AUTOLOAD', false); - $file = __DIR__ . "/../../_files/temp.pdf"; + $file = __DIR__ . "/../../_files/dompdf.pdf"; $phpWord = new PhpWord(); $section = $phpWord->addSection(); diff --git a/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php new file mode 100644 index 00000000..4728b7f1 --- /dev/null +++ b/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php @@ -0,0 +1,51 @@ +addSection(); + $section->addText('Test 1'); + + $rendererName = Settings::PDF_RENDERER_MPDF; + $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf'); + Settings::setPdfRenderer($rendererName, $rendererLibraryPath); + $writer = new PDF($phpWord); + $writer->save($file); + + $this->assertTrue(file_exists($file)); + + unlink($file); + } +} diff --git a/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php new file mode 100644 index 00000000..c73f0043 --- /dev/null +++ b/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php @@ -0,0 +1,51 @@ +addSection(); + $section->addText('Test 1'); + + $rendererName = Settings::PDF_RENDERER_TCPDF; + $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf'); + Settings::setPdfRenderer($rendererName, $rendererLibraryPath); + $writer = new PDF($phpWord); + $writer->save($file); + + $this->assertTrue(file_exists($file)); + + unlink($file); + } +}