Permalink
Browse files

better unit test, better cleaning after execution, better extension l…

…oading, ...
  • Loading branch information...
spipu committed Jan 19, 2018
1 parent 46c3f30 commit bf64ba3b896ec3c72d0177e77fa3d620cb5ae2b2
Showing with 281 additions and 129 deletions.
  1. +2 −0 CHANGELOG.md
  2. +2 −0 examples/about.php
  3. +2 −0 examples/bookmark.php
  4. +2 −0 examples/exemple00.php
  5. +2 −0 examples/exemple01.php
  6. +2 −0 examples/exemple02.php
  7. +2 −0 examples/exemple03.php
  8. +2 −0 examples/exemple04.php
  9. +2 −0 examples/exemple05.php
  10. +2 −0 examples/exemple06.php
  11. +2 −0 examples/exemple07.php
  12. +2 −0 examples/exemple08.php
  13. +2 −0 examples/exemple09.php
  14. +2 −0 examples/exemple10.php
  15. +2 −0 examples/exemple11.php
  16. +2 −0 examples/exemple12.php
  17. +2 −0 examples/exemple13.php
  18. +2 −0 examples/exemple14.php
  19. +2 −0 examples/forms.php
  20. +2 −0 examples/groups.php
  21. +2 −0 examples/qrcode.php
  22. +2 −0 examples/radius.php
  23. +2 −0 examples/regle.php
  24. +2 −0 examples/svg.php
  25. +2 −0 examples/svg_tiger.php
  26. +2 −0 examples/svg_tree.php
  27. +2 −0 examples/ticket.php
  28. +2 −0 examples/utf8.php
  29. +13 −5 src/Html2Pdf.php
  30. +44 −0 src/Tests/AbstractTest.php
  31. +4 −12 src/Tests/Debug/DebugTest.php
  32. +87 −4 src/Tests/Exception/ExceptionFormatterTest.php
  33. +3 −4 src/Tests/Exception/LongSentenceExceptionTest.php
  34. +7 −15 src/Tests/Html2PdfTest.php
  35. +3 −4 src/Tests/Image/BackgroundErrorTest.php
  36. +3 −4 src/Tests/Image/BackgroundOkTest.php
  37. +3 −3 src/Tests/Image/SrcErrorTest.php
  38. +3 −4 src/Tests/Image/SrcOkTest.php
  39. +3 −3 src/Tests/Output/FileNameErrorTest.php
  40. +3 −3 src/Tests/Output/FileNameOkTest.php
  41. +8 −13 src/Tests/Parsing/ParsingTest.php
  42. +6 −9 src/Tests/Tag/DivTest.php
  43. +5 −7 src/Tests/Tag/MustHaveTagsTest.php
  44. +3 −4 src/Tests/Tag/Svg/CircleErrorTest.php
  45. +3 −4 src/Tests/Tag/Svg/EllipseErrorTest.php
  46. +3 −4 src/Tests/Tag/Svg/GErrorTest.php
  47. +3 −4 src/Tests/Tag/Svg/LineErrorTest.php
  48. +3 −4 src/Tests/Tag/Svg/PathErrorTest.php
  49. +3 −4 src/Tests/Tag/Svg/PathInvalidTest.php
  50. +3 −4 src/Tests/Tag/Svg/PolygonErrorTest.php
  51. +3 −4 src/Tests/Tag/Svg/PolylineErrorTest.php
  52. +3 −4 src/Tests/Tag/Svg/RectErrorTest.php
  53. +3 −3 src/Tests/Tag/TdTooLongTest.php
@@ -7,7 +7,9 @@ All notable changes to this project will be documented in this file.
* add support of css `page-break-before:always` and `page-break-after:always` on `DIV` tag, based on PR #190 and PR #204
* add no-html mode for debug output
* add php 7.2 compatibility
* add some unit tests, better coverage
* fix lots of bad method names and minor improvements, from PR #147
* fix bad cleaning after output or exception
* fix changelog file
## [5.0.1](https://github.com/spipu/html2pdf/compare/v5.0.0...v5.0.1) - 2017-06-15
@@ -27,6 +27,8 @@
$html2pdf->createIndex('Sommaire', 30, 12, false, true, 2);
$html2pdf->output('about.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->createIndex('Sommaire', 25, 12, false, true, 1);
$html2pdf->output('bookmark.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple00.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple01.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple02.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple03.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple04.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple05.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple06.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -27,6 +27,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple07.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple08.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -71,6 +71,8 @@
$html2pdf->output('exemple09.pdf');
exit;
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
exit;
@@ -23,6 +23,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple10.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple11.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple12.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple13.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -26,6 +26,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('exemple14.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -33,6 +33,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('forms.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('groups.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('qrcode.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -24,6 +24,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('radius.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('regle.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('svg.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('svg_tiger.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('svg_tree.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -25,6 +25,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('ticket.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -26,6 +26,8 @@
$html2pdf->writeHTML($content);
$html2pdf->output('utf8.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
}
@@ -481,14 +481,18 @@ public function createIndex($titre = 'Index', $sizeTitle = 20, $sizeBookmark = 1
}
/**
* clean up the objects
* clean up the objects, if the method output can not be called because of an exception
*
* @access protected
* @return Html2Pdf
*/
protected function _cleanUp()
public function clean()
{
self::$_subobj = null;
self::$_tables = array();
Locale::clean();
return $this;
}
/**
@@ -512,7 +516,7 @@ protected function _cleanUp()
public function output($name = 'document.pdf', $dest = 'I')
{
// close the pdf and clean up
$this->_cleanUp();
$this->clean();
// if on debug mode
if (!is_null($this->debug)) {
@@ -1066,7 +1070,11 @@ protected function _prepareSubObj()
self::$_subobj->setFallbackImage($this->_fallbackImage);
self::$_subobj->parsingCss->css = &$this->parsingCss->css;
self::$_subobj->parsingCss->cssKeys = &$this->parsingCss->cssKeys;
self::$_subobj->extensions = $this->extensions;
// add all the extensions
foreach ($this->extensions as $extension) {
self::$_subobj->addExtension($extension);
}
// clone font from the original PDF
self::$_subobj->pdf->cloneFontFrom($this->pdf);
@@ -0,0 +1,44 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Html2Pdf;
/**
* Class Html2PdfTest
*/
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Html2Pdf
*/
private $html2pdf;
/**
* Executed before each test
*/
protected function setUp()
{
$this->html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]);
$this->html2pdf->pdf->SetTitle('PhpUnit Test');
}
/**
* Executed after each test
*/
protected function tearDown()
{
$this->html2pdf->clean();
$this->html2pdf = null;
}
/**
* Get the object to test
*
* @return Html2Pdf
*/
protected function getObject()
{
return $this->html2pdf;
}
}
@@ -12,13 +12,13 @@
namespace Spipu\Html2Pdf\Tests\Debug;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Debug\Debug;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class DebugTest
*/
class DebugTest extends \PHPUnit_Framework_TestCase
class DebugTest extends AbstractTest
{
/**
* test Debug Mode, Automatic
@@ -31,12 +31,8 @@ public function testAutomatic()
$html.= '<div>Second Tag</div>';
$html.= '<b>Third Tag</b>';
// prepare the Html2Pdf object
$object = new Html2Pdf();
$object->pdf->SetTitle('PhpUnit Test');
// make the test
ob_start();
$object = $this->getObject();
$object->setModeDebug();
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
@@ -60,12 +56,8 @@ public function testManual()
// Prepare debug object, without html output
$debug = new Debug(false);
// prepare the Html2Pdf object
$object = new Html2Pdf();
$object->pdf->SetTitle('PhpUnit Test');
// make the test
ob_start();
$object = $this->getObject();
$object->setModeDebug($debug);
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
Oops, something went wrong.

0 comments on commit bf64ba3

Please sign in to comment.