html2pdf mit composer hinzugefügt

This commit is contained in:
aschwarz
2023-02-16 09:19:46 +01:00
parent 3dcc93a65d
commit d1ab7f3763
613 changed files with 134681 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\AbstractTestCase;
/**
* Class AbstractTest
*/
abstract class AbstractTest extends AbstractTestCase
{
/**
* Get the object to test
*
* @return Html2Pdf
*/
protected function getObject()
{
return $this->html2pdf;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class AbstractTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\AbstractTestCase
{
}
} else {
abstract class AbstractTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\AbstractTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class CssConverterTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\CssConverterTestCase
{
}
} else {
abstract class CssConverterTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\CssConverterTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class ExceptionFormatterTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\ExceptionFormatterTestCase
{
}
} else {
abstract class ExceptionFormatterTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\ExceptionFormatterTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class HtmlTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\HtmlTestCase
{
}
} else {
abstract class HtmlTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\HtmlTestCase
{
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use Spipu\Html2Pdf\Html2Pdf;
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var Html2Pdf
*/
protected $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;
}
public function expectException($exception)
{
if (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) {
$this->setExpectedException($exception);
}
}
public function expectExceptionMessage($message, $exception = null)
{
if (method_exists(\PHPUnit_Framework_TestCase::class, 'expectExceptionMessage')) {
parent::expectExceptionMessage($message);
} elseif (method_exists(\PHPUnit_Framework_TestCase::class, 'setExpectedException')) {
$this->setExpectedException($exception, $message);
}
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\CssConverter;
abstract class CssConverterTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var CssConverter
*/
protected $cssConverter;
protected function setUp()
{
$this->cssConverter = new CssConverter();
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
abstract class ExceptionFormatterTestCase extends PHPUnit_Framework_TestCase
{
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Parsing\Html;
abstract class HtmlTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var Html
*/
protected $object;
protected function setUp()
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->will($this->returnCallback([$this, 'mockPrepareTxt']));
$this->object = new Html($textParser);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\SvgDrawer;
abstract class SvgDrawerTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var SvgDrawer
*/
protected $svgDrawer;
protected function setUp()
{
$myPdf = $this->createMock('Spipu\Html2Pdf\MyPdf');
$cssConverter = new CssConverter();
$this->svgDrawer = new SvgDrawer($myPdf, $cssConverter);
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Parsing\TagParser;
abstract class TagParserTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var TagParser
*/
protected $parser;
protected function setUp()
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->will($this->returnCallback([$this, 'mockPrepareTxt']));
$this->parser = new TagParser($textParser);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Parsing\TextParser;
abstract class TextParserTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var TextParser
*/
protected $parser;
protected function setUp()
{
$this->parser = new TextParser();
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\Html2Pdf;
abstract class AbstractTestCase extends TestCase
{
use AssertContains;
/**
* @var Html2Pdf
*/
protected $html2pdf;
/**
* Executed before each test
*/
protected function setUp(): void
{
$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(): void
{
$this->html2pdf->clean();
$this->html2pdf = null;
}
public function expectExceptionMessage($message, $exception = null): void
{
// Yes, we ignore $exception
parent::expectExceptionMessage($message);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
trait AssertContains
{
public static function assertContains($needle, $haystack, string $message = ''): void
{
if (is_string($haystack)) {
parent::assertStringContainsString($needle, $haystack, $message);
} else {
parent::assertContains($needle, $haystack, $message);
}
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\CssConverter;
abstract class CssConverterTestCase extends TestCase
{
/**
* @var CssConverter
*/
protected $cssConverter;
public function setUp(): void
{
$this->cssConverter = new CssConverter();
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
abstract class ExceptionFormatterTestCase extends TestCase
{
use AssertContains;
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\Parsing\Html;
abstract class HtmlTestCase extends TestCase
{
/**
* @var Html
*/
protected $object;
protected function setUp(): void
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->willReturnCallback([$this, 'mockPrepareTxt']);
$this->object = new Html($textParser);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\SvgDrawer;
abstract class SvgDrawerTestCase extends TestCase
{
/**
* @var SvgDrawer
*/
protected $svgDrawer;
public function setUp(): void
{
$myPdf = $this->createMock('Spipu\Html2Pdf\MyPdf');
$cssConverter = new CssConverter();
$this->svgDrawer = new SvgDrawer($myPdf, $cssConverter);
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\Parsing\TagParser;
abstract class TagParserTestCase extends TestCase
{
/**
* @var TagParser
*/
protected $parser;
protected function setUp(): void
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->willReturnCallback([$this, 'mockPrepareTxt']);
$this->parser = new TagParser($textParser);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9;
use PHPUnit\Framework\TestCase;
use Spipu\Html2Pdf\Parsing\TextParser;
abstract class TextParserTestCase extends TestCase
{
/**
* @var TextParser
*/
protected $parser;
protected function setUp(): void
{
$this->parser = new TextParser();
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class SvgDrawerTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\SvgDrawerTestCase
{
}
} else {
abstract class SvgDrawerTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\SvgDrawerTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class TagParserTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\TagParserTestCase
{
}
} else {
abstract class TagParserTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\TagParserTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Spipu\Html2Pdf\Tests\CrossVersionCompatibility;
if (HTML2PDF_PHPUNIT_VERSION === 9) {
abstract class TextParserTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit9\TextParserTestCase
{
}
} else {
abstract class TextParserTestCase extends \Spipu\Html2Pdf\Tests\CrossVersionCompatibility\PhpUnit5\TextParserTestCase
{
}
}

View File

@ -0,0 +1,13 @@
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
if (!class_exists('PHPUnit_Framework_TestCase') && version_compare(phpversion(), '7.1') >= 0) {
class PHPUnit_Framework_TestCase extends PHPUnit\Framework\TestCase
{
}
define('HTML2PDF_PHPUNIT_VERSION', 9);
} else {
define('HTML2PDF_PHPUNIT_VERSION', 5);
}

View File

@ -0,0 +1,107 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\CssConverterTestCase;
/**
* Class CssConverterTest
*/
class CssConverterTest extends CssConverterTestCase
{
/**
* @param string $css
* @param string $old
* @param array $expected
*
* @dataProvider convertToMMProvider
*/
public function testConvertToMM($css, $old, $expected)
{
$result = $this->cssConverter->convertToMM($css, $old);
$this->assertEquals($expected, $result);
}
public function convertToMMProvider()
{
return array(
array('100mm', null, 100),
array('100px', null, 25.4 / 96. * 100),
array('100', null, 25.4 / 96. * 100),
array('100pt', null, 25.4 / 72. * 100),
array('100in', null, 25.4 * 100),
array('10%', 100, 10),
array('100cm', null, null),
);
}
/**
* @param string $css
* @param array $expected
*
* @dataProvider convertToRadiusProvider
*/
public function testConvertToRadius($css, $expected)
{
$result = $this->cssConverter->convertToRadius($css);
$this->assertEquals(count($expected), count($result));
for ($i = 0; $i < count($result); $i++) {
$this->assertEquals($expected[$i], $result[$i]);
}
}
public function convertToRadiusProvider()
{
return array(
array('100mm', array(100)),
array('100mm 10mm', array(100, 10)),
array('100mm 10mm ', array(100, 10)),
array('100mm 10cm 10mm', array(100, 10)),
array('1mm 2mm 3mm 4mm', array(1, 2, 3, 4)),
);
}
/**
* @param string $css
* @param boolean $expectedRes
* @param array $expectedColor
*
* @dataProvider convertToColorProvider
*/
public function testConvertToColor($css, $expectedRes, $expectedColor)
{
$res = true;
$resultColor = $this->cssConverter->convertToColor($css, $res);
$this->assertEquals($expectedRes, $res);
$this->assertEquals(count($expectedColor), count($resultColor));
for ($i = 0; $i < count($resultColor); $i++) {
if (is_null($expectedColor[$i])) {
$this->assertNull($resultColor[$i]);
} else {
$this->assertEquals($expectedColor[$i], $resultColor[$i]);
}
}
}
public function convertToColorProvider()
{
return array(
array('transparent', true, array(null, null, null)),
array('aliceblue', true, array( 240, 248, 255)),
array('#F0A050', true, array( 240, 160, 80)),
array('#FA5', true, array( 255, 170, 85)),
array('rgb( 50, 100, 150)', true, array( 50, 100, 150)),
array('rgb( 10%, 20%, 30%)', true, array(25.5, 51, 76.5)),
array('rgb( 0.2, 0.4, 0.6)', true, array( 51, 102, 153)),
array('cmyk(255, 255, 255, 255)', true, array( 100, 100, 100, 100)),
array('cmyk(10%, 20%, 30%, 40%)', true, array( 10, 20, 30, 40)),
array('cmyk(0.2, 0.4, 0.6, 0.8)', true, array( 20, 40, 60, 80)),
array('blakc', false, array( 0, 0, 0)),
);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Debug;
use Spipu\Html2Pdf\Debug\Debug;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class DebugTest
*/
class DebugTest extends AbstractTest
{
/**
* test Debug Mode, Automatic
*
* @return void
*/
public function testAutomatic()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<b>Third Tag</b>';
ob_start();
$object = $this->getObject();
$object->setModeDebug();
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
$debugResult = ob_get_clean();
$this->assertSame('', $pdfResult);
$this->assertNotEmpty($debugResult);
}
/**
* test Debug Mode, manual
*
* @return void
*/
public function testManual()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<b>Third Tag</b>';
// Prepare debug object, without html output
$debug = new Debug(false);
ob_start();
$object = $this->getObject();
$object->setModeDebug($debug);
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
$debugResult = ob_get_clean();
$this->assertSame('', $pdfResult);
$this->assertNotEmpty($debugResult);
}
}

View File

@ -0,0 +1,336 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests;
use PHPUnit_Framework_TestCase;
/**
* Class ExamplesTest
*/
class ExamplesTest extends PHPUnit_Framework_TestCase
{
/**
* Launch a example
*
* @param string $example code of the example
*
* @return void
* @throws \Exception
*/
protected function launchExample($example)
{
$filename = dirname(dirname(__FILE__)).'/examples/'.$example.'.php';
if (!is_file($filename)) {
throw new \Exception('The filename of the example ['.$example.'] does not exist!');
}
$folder = dirname($filename);
// get the content of the file
$content = file_get_contents($filename);
// keep only the example
$parts = explode('try {', $content);
$parts = explode('} catch', $parts[1]);
$content = $parts[0];
// replace the good path
$content = str_replace('dirname(__FILE__)', "'$folder'", $content);
// add the class to use
$content = 'use Spipu\Html2Pdf\Html2Pdf; '.$content;
// get the output
$regexp = '/\$html2pdf->output\(([^\)]*)\);/';
$replace = 'return $html2pdf->output(\'test.pdf\', \'S\');';
$content = preg_replace($regexp, $replace, $content);
// execute
$currentDir = getcwd();
chdir($folder);
$result = eval($content);
chdir($currentDir);
// test
$this->assertNotEmpty($result);
}
/**
* test: about
*
* @return void
*/
public function testAbout()
{
$this->launchExample('about');
}
/**
* test: bookmark
*
* @return void
*/
public function testBookmark()
{
$this->launchExample('bookmark');
}
/**
* test: bookmark
*
* @return void
*/
public function testBalloon()
{
$this->launchExample('balloon');
}
/**
* test: example01
*
* @return void
*/
public function testExample01()
{
$this->launchExample('example01');
}
/**
* test: example02
*
* @return void
*/
public function testExample02()
{
$this->launchExample('example02');
}
/**
* test: example03
*
* @return void
*/
public function testExample03()
{
$this->launchExample('example03');
}
/**
* test: example04
*
* @return void
*/
public function testExample04()
{
$this->launchExample('example04');
}
/**
* test: example05
*
* @return void
*/
public function testExample05()
{
$this->launchExample('example05');
}
/**
* test: example06
*
* @return void
*/
public function testExample06()
{
$this->launchExample('example06');
}
/**
* test: example07
*
* @return void
*/
public function testExample07()
{
$this->launchExample('example07');
}
/**
* test: example08
*
* @return void
*/
public function testExample08()
{
$this->launchExample('example08');
}
/**
* test: example10
*
* @return void
*/
public function testExample10()
{
$this->launchExample('example10');
}
/**
* test: example11
*
* @return void
*/
public function testExample11()
{
$this->launchExample('example11');
}
/**
* test: example12
*
* @return void
*/
public function testExample12()
{
$this->launchExample('example12');
}
/**
* test: example13
*
* @return void
*/
public function testExample13()
{
$this->launchExample('example13');
}
/**
* test: example14
*
* @return void
*/
public function testExample14()
{
$this->launchExample('example14');
}
/**
* test: example15
*
* @return void
*/
public function testExample15()
{
$this->launchExample('example15');
}
/**
* test: forms
*
* @return void
*/
public function testForms()
{
$this->launchExample('forms');
}
/**
* test: groups
*
* @return void
*/
public function testGroups()
{
$this->launchExample('groups');
}
/**
* test: qrcode
*
* @return void
*/
public function testQrcode()
{
$this->launchExample('qrcode');
}
/**
* test: radius
*
* @return void
*/
public function testRadius()
{
$this->launchExample('radius');
}
/**
* test: regle
*
* @return void
*/
public function testMeasure()
{
$this->launchExample('measure');
}
/**
* test: svg
*
* @return void
*/
public function testSvg()
{
$this->launchExample('svg');
}
/**
* test: svg_tiger
*
* @return void
*/
public function testSvgTiger()
{
$this->launchExample('svg_tiger');
}
/**
* test: svg_tree
*
* @return void
*/
public function testSvgTree()
{
$this->launchExample('svg_tree');
}
/**
* test: ticket
*
* @return void
*/
public function testTicket()
{
$this->launchExample('ticket');
}
/**
* test: utf8
*
* @return void
*/
public function testUtf8()
{
$this->launchExample('utf8');
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Exception;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Exception\LongSentenceException;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\ExceptionFormatterTestCase;
/**
* Class ExceptionFormaterTest
*/
class ExceptionFormatterTest extends ExceptionFormatterTestCase
{
/**
* Test the formatter / generic exception
*/
public function testGeneric()
{
$exception = new Html2PdfException('My Message');
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.Html2PdfException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
}
}
/**
* Test the formatter / parsing exception
*/
public function testParsing()
{
$exception = new HtmlParsingException('My Message');
$exception->setInvalidTag('my_tag');
$exception->setHtmlLine(42);
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.HtmlParsingException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my_tag', $message);
$this->assertContains('42', $message);
}
}
/**
* Test the formatter / image exception
*/
public function testImage()
{
$exception = new ImageException('My Message');
$exception->setImage('my_image.png');
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.ImageException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my_image.png', $message);
}
}
/**
* Test the formatter / long sentence exception
*/
public function testLongSentence()
{
$exception = new LongSentenceException('My Message');
$exception->setSentence('my sentence');
$exception->setLength(142);
$exception->setWidthBox(242);
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.LongSentenceException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my sentence', $message);
$this->assertContains('142', $message);
$this->assertContains('242', $message);
}
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Exception;
use Spipu\Html2Pdf\Exception\LongSentenceException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class DebugTest
*/
class LongSentenceExceptionTest extends AbstractTest
{
/**
* test LongSentence Exception
*
* @return void
*/
public function testBug()
{
$this->expectException(LongSentenceException::class);
$sentence = 'This is a sentence.';
$bigSentence = $sentence;
for ($k=0; $k<110; $k++) {
$bigSentence.= ' '.$sentence;
}
$html = '<page backleft="0" backright="200mm"style="font-size: 1mm">'.$bigSentence.'</page>';
$object = $this->getObject();
$object->setSentenceMaxLines(100);
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tag\AbstractTag;
/**
* Class Html2PdfTest
*/
class Html2PdfTest extends AbstractTest
{
public function testExtensionTag()
{
$tag = new testTag();
$extension = $this->createMock('Spipu\Html2Pdf\Extension\ExtensionInterface');
$extension->expects($this->any())->method('getName')->willReturn('test');
$extension->expects($this->any())->method('getTags')->willReturn(array($tag));
$object = $this->getObject();
$object->addExtension($extension);
$object->writeHTML('<div><test_tag>Hello</test_tag></div>');
$this->assertTrue(true);
}
public function testSecurityGood()
{
$object = $this->getObject();
$object->setTestIsImage(false);
$object->writeHTML('<div><img src="https://www.spipu.net/res/logo_spipu.gif" alt="" /></div>');
$object->writeHTML('<div><img src="/temp/test.jpg" alt="" /></div>');
$object->writeHTML('<div><img src="c:/temp/test.jpg" alt="" /></div>');
// Ensures we assert something
$this->assertTrue(true);
}
public function testSecurityKo()
{
$this->expectException(HtmlParsingException::class);
$this->expectExceptionMessage('Unauthorized path scheme', HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<div><img src="phar://test.com/php.phar" alt="" /></div>');
}
}
class testTag extends AbstractTag
{
public function getName()
{
return 'test_tag';
}
public function open($properties)
{
}
public function close($properties)
{
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class BackgroundErrorTest
*/
class BackgroundErrorTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$this->expectException(ImageException::class);
$image = '/res/wrong.png';
try {
$object = $this->getObject();
$object->writeHTML('<div style="background-image: url('.$image.')">Hello World</div>');
$object->output('test.pdf', 'S');
} catch (ImageException $e) {
$this->assertSame($image, $e->getImage());
throw $e;
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class BackgroundOkTest
*/
class BackgroundOkTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<div style="background-image: url('.dirname(__FILE__).'/res/logo.png)">Hello World</div>');
$result = $object->output('test.pdf', 'S');
$this->assertContains('PhpUnit Test', $result);
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class SrcErrorTest
*/
class SrcErrorTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$this->expectException(ImageException::class);
$image = '/res/wrong.png';
try {
$object = $this->getObject();
$object->writeHTML('Hello World <img src="'.$image.'" />');
$object->output('test.pdf', 'S');
} catch (ImageException $e) {
$this->assertSame($image, $e->getImage());
throw $e;
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class SrcOkTest
*/
class SrcOkTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('Hello World <img src="'.dirname(__FILE__).'/res/logo.png" />');
$result = $object->output('test.pdf', 'S');
$this->assertContains('PhpUnit Test', $result);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,74 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Locale;
use Spipu\Html2Pdf\Exception\LocaleException;
/**
* Class LocaleTest
*/
class LocaleTest extends PHPUnit_Framework_TestCase
{
/**
* test bad code
*
* @return void
*/
public function testBadCode()
{
$this->expectException(LocaleException::class);
Locale::clean();
try {
Locale::load('$aa');
} catch (LocaleException $e) {
$this->assertSame('$aa', $e->getLocalCode());
throw $e;
}
}
/**
* test unknown code
*
* @return void
*/
public function testUnknownCode()
{
$this->expectException(LocaleException::class);
Locale::clean();
try {
Locale::load('aa');
} catch (LocaleException $e) {
$this->assertSame('aa', $e->getLocalCode());
throw $e;
}
}
/**
* test good code
*
* @return void
*/
public function testGoodCode()
{
Locale::clean();
Locale::load('en');
$this->assertSame('Page [[page_cu]]/[[page_nb]]', Locale::get('pdf04'));
$this->assertSame('bad_return', Locale::get('bad_code', 'bad_return'));
Locale::clean();
$this->assertSame('bad_return', Locale::get('pdf04', 'bad_return'));
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Output;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class FileNameOkTest
*/
class FileNameOkTest extends AbstractTest
{
/**
* test: the file extension must be PDF - OK
*
* @return void
*/
public function testOk()
{
$object = $this->getObject();
$object->writeHTML('Hello World');
ob_start();
$object->output('test.pdf');
$result = ob_get_clean();
$this->assertContains('PhpUnit Test', $result);
}
/**
* test: the file extension is ignored if output string
*
* @return void
*/
public function testIgnore()
{
$object = $this->getObject();
$object->writeHTML('Hello World');
$result = $object->output('test.bad', 'S');
$this->assertContains('PhpUnit Test', $result);
}
/**
* test: the file extension must be PDF - Error
*
* @return void
*/
public function testError()
{
$this->expectException(Html2PdfException::class);
$object = $this->getObject();
$object->writeHTML('<p>Hello World</p>');
$object->output('test.bad');
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Parsing\HtmlLexer;
/**
* Class HtmlLexerTest
*/
class HtmlLexerTest extends PHPUnit_Framework_TestCase
{
/**
* Test: tokenize
*
* @param string $html html to test
* @param array $expectedTokens expected token
*
* @dataProvider tokenizeProvider
*/
public function testTokenize($html, $expectedTokens)
{
$lexer = new HtmlLexer();
$tokens = $lexer->tokenize($html);
$this->assertEquals(count($expectedTokens), count($tokens));
for ($i = 0; $i < count($tokens); $i++) {
$this->assertEquals($expectedTokens[$i][0], $tokens[$i]->getType());
$this->assertEquals($expectedTokens[$i][1], $tokens[$i]->getData());
$this->assertEquals($expectedTokens[$i][2], $tokens[$i]->getLine());
}
}
/**
* provider: tokenize
*
* @return array
*/
public function tokenizeProvider()
{
return array(
array(
'<p>test</p>',
array(
array('code', '<p>', 1),
array('txt', 'test', -1),
array('code', '</p>', 1),
)
),
array(
"<a><!-- comment -->\n<b><c>test",
array(
array('code', '<a>', 1),
array('txt', "\n", -1),
array('code', '<b>', 2),
array('code', '<c>', 2),
array('txt', "test", -1),
)
)
);
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\HtmlTestCase;
/**
* Class HtmlTest
*/
class HtmlTest extends HtmlTestCase
{
/**
* mock of prepareTxt method
*
* @param $txt
* @param bool $spaces
* @return mixed
*/
public function mockPrepareTxt($txt, $spaces = true)
{
return $txt;
}
/**
* Test the prepareHtml method
*/
public function testPrepareHtml()
{
$result = $this->object->prepareHtml('Hello [[date_y]]-[[date_m]]-[[date_d]] World');
$this->assertSame('Hello '.date('Y-m-d').' World', $result);
$result = $this->object->prepareHtml('Hello [[date_h]]:[[date_i]]:[[date_s]] World');
$this->assertSame('Hello '.date('H:i:s').' World', $result);
$html = '
<html>
<head>
<style type="text">.my-class { color: red; }</style>
<link type="text/css" href="my-style.css"/>
</head>
<body class="my-class"><p>Hello World</p></body>
</html>';
$expected='<style type="text">.my-class { color: red; }</style>'.
'<link type="text/css" href="my-style.css"/>'.
'<page class="my-class"><p>Hello World</p></page>';
$result = $this->object->prepareHtml($html);
$this->assertSame($expected, $result);
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class ParsingTest
*/
class ParsingTest extends AbstractTest
{
/**
* test: The tag is unknown
*
* @return void
*/
public function testUnknownTag()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<bad_tag>Hello World</bad_tag>');
$object->output('test.pdf', 'S');
}
/**
* test: Too many tag closures found
*
* @return void
*/
public function testTooManyClosuresFound()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<i><u>Hello</u></i></b>');
$object->output('test.pdf', 'S');
}
/**
* test: Tags are closed in a wrong order
*
* @return void
*/
public function testWrongClosedOrder()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<b><u><i>Hello</u></i></b>');
$object->output('test.pdf', 'S');
}
/**
* test: The following tag has not been closed
*
* @return void
*/
public function testNotClosed()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<b><i>Hello</i>');
$object->output('test.pdf', 'S');
}
/**
* test: The following tags have not been closed
*
* @return void
*/
public function testNotClosedMore()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<b><u><i>Hello</i>');
$object->output('test.pdf', 'S');
}
/**
* test: The HTML tag code provided is invalid
*
* @return void
*/
public function testInvalidCode()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<az1-r_h>Hello</az1-r_h>');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,203 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Parsing\Node;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\TagParserTestCase;
/**
* Class TagParserTest
*/
class TagParserTest extends TagParserTestCase
{
/**
* mock of prepareTxt method
*
* @param $txt
* @param bool $spaces
* @return mixed
*/
public function mockPrepareTxt($txt, $spaces = true)
{
return $txt;
}
/**
* @param string $code
* @param array $expected
*
* @dataProvider tagAttributesProvider
*/
public function testExtractTagAttributes($code, $expected)
{
$result = $this->parser->extractTagAttributes($code);
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function tagAttributesProvider()
{
return array(
array('attr=value', array('attr' => 'value')),
array('attr="value"', array('attr' => 'value')),
array('attr=\'value\'', array('attr' => 'value')),
array('attr="value with spaces"', array('attr' => 'value with spaces')),
array('attr="value with \'quotes"', array('attr' => 'value with \'quotes')),
array('my attr="value"', array('attr' => 'value')),
array('attr1=val1 attr2="value2"', array('attr1' => 'val1', 'attr2' => 'value2')),
);
}
/**
* Test if a bad tag is detected
*/
public function testAnalyzeTagBadTag()
{
$this->expectException(HtmlParsingException::class);
$this->parser->analyzeTag('test');
}
/**
* Test basic open, close, autoclose tags
*/
public function testBasicTags()
{
$result = $this->parser->analyzeTag('<my_tag/>');
$this->assertTrue($result instanceof Node);
$this->assertSame('my_tag', $result->getName());
$this->assertSame(true, $result->isAutoClose());
$this->assertSame(false, $result->isClose());
$result->setLine(10);
$this->assertSame(10, $result->getLine());
$result->setParam('attr', 'value');
$this->assertSame('value', $result->getParam('attr'));
$result = $this->parser->analyzeTag('<my_tag>');
$this->assertSame('my_tag', $result->getName());
$this->assertSame(false, $result->isAutoClose());
$this->assertSame(false, $result->isClose());
$this->assertSame(['style' => [], 'num' => 0], $result->getParams());
$this->assertSame('default', $result->getParam('attr', 'default'));
$result = $this->parser->analyzeTag('</my_tag>');
$this->assertSame('my_tag', $result->getName());
$this->assertSame(false, $result->isAutoClose());
$this->assertSame(true, $result->isClose());
}
/**
* Test styles
*/
public function testAnalyzeAttributes()
{
$result = $this->parser->analyzeTag('<img src="my_src" alt="my alt"/>');
$this->assertSame('my_src', $result->getParam('src'));
$this->assertSame('my alt', $result->getParam('alt'));
$result = $this->parser->analyzeTag('<a href="my_src" title="my title"/>');
$this->assertSame('my_src', $result->getParam('href'));
$this->assertSame('my title', $result->getParam('title'));
$result = $this->parser->analyzeTag('<input type="text" value="my value" class="my_class" />');
$this->assertSame('text', $result->getParam('type'));
$this->assertSame('my value', $result->getParam('value'));
$this->assertSame('my_class', $result->getParam('class'));
$result = $this->parser->analyzeTag('<my_tag width="10" height="20" align="center" valign="bottom" bgcolor="red">');
$this->assertSame('10px', $result->getStyle('width'));
$this->assertSame('20px', $result->getStyle('height'));
$this->assertSame('center', $result->getStyle('text-align'));
$this->assertSame('bottom', $result->getStyle('vertical-align'));
$this->assertSame('red', $result->getStyle('background'));
$result = $this->parser->analyzeTag('<img align="right">');
$this->assertSame('right', $result->getStyle('float'));
$result = $this->parser->analyzeTag('<table cellpadding="1" cellspacing="2">');
$this->assertSame('1px', $result->getParam('cellpadding'));
$this->assertSame('2px', $result->getParam('cellspacing'));
$result = $this->parser->analyzeTag('<td rowspan="0" colspan="2px">');
$this->assertSame(1, $result->getParam('rowspan'));
$this->assertSame(2, $result->getParam('colspan'));
$result = $this->parser->analyzeTag('<my_tag color="red">');
$this->assertSame('red', $result->getParam('color'));
$this->assertSame(null, $result->getStyle('color'));
$result = $this->parser->analyzeTag('<font color="red">');
$this->assertSame(null, $result->getParam('color'));
$this->assertSame('red', $result->getStyle('color'));
}
/**
* Test borders
*/
public function testBorders()
{
$result = $this->parser->analyzeTag('<div border="1" bordercolor="red" />');
$this->assertSame('div', $result->getName());
$this->assertSame('solid 1px red', $result->getParam('border'));
$this->assertSame('solid 1px red', $result->getStyle('border'));
$result = $this->parser->analyzeTag('<div border="0" bordercolor="red" />');
$this->assertSame('div', $result->getName());
$this->assertSame('none', $result->getParam('border'));
$this->assertSame('none', $result->getStyle('border'));
}
/**
* Test levels
*/
public function testLevels()
{
$result = $this->parser->analyzeTag('<basic_tag>');
$this->assertSame(0, $result->getParam('num'));
$result = $this->parser->analyzeTag('<table>');
$this->assertSame(1, $result->getParam('num'));
$result = $this->parser->analyzeTag('<ol>');
$this->assertSame(2, $result->getParam('num'));
$result = $this->parser->analyzeTag('<ul>');
$this->assertSame(3, $result->getParam('num'));
$result = $this->parser->analyzeTag('</ul>');
$this->assertSame('ul', $result->getName());
$this->assertSame(3, $result->getParam('num'));
$result = $this->parser->analyzeTag('</ol>');
$this->assertSame(2, $result->getParam('num'));
$result = $this->parser->analyzeTag('</table>');
$this->assertSame(1, $result->getParam('num'));
$result = $this->parser->analyzeTag('<basic_tag>');
$this->assertSame(0, $result->getParam('num'));
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\TextParserTestCase;
/**
* Class TextParserTest
*/
class TextParserTest extends TextParserTestCase
{
/**
* Test if it works
*/
public function testOk()
{
$result = $this->parser->prepareTxt('hello world', false);
$this->assertSame('hello world', $result);
$result = $this->parser->prepareTxt('hello world', true);
$this->assertSame('hello world', $result);
$result = $this->parser->prepareTxt('hello 10&euro; world');
$this->assertSame('hello 10€ world', $result);
$result = $this->parser->prepareTxt('hello &lt; world');
$this->assertSame('hello < world', $result);
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use PHPUnit_Framework_TestCase;
use Spipu\Html2Pdf\Parsing\Token;
/**
* Class TokenTest
*/
class TokenTest extends PHPUnit_Framework_TestCase
{
/**
* Test if it works
*/
public function testOk()
{
$token = new Token('hello', 'world', 45);
$this->assertSame('hello', $token->getType());
$this->assertSame('world', $token->getData());
$this->assertSame(45, $token->getLine());
}
}

View File

@ -0,0 +1,280 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\CrossVersionCompatibility\SvgDrawerTestCase;
/**
* Class SvgDrawerTest
*/
class SvgDrawerTest extends SvgDrawerTestCase
{
/**
* Test IsDrawing Exception
*/
public function testIsDrawingException()
{
$this->expectException(HtmlParsingException::class);
$properties = [
'x' => 0,
'y' => 0,
'w' => '100mm',
'h' => '100mm',
];
$this->svgDrawer->startDrawing($properties);
$this->svgDrawer->startDrawing($properties);
}
/**
* Test IsDrawing
*/
public function testIsDrawingOk()
{
$properties = [
'x' => 0,
'y' => 0,
'w' => 100,
'h' => 100,
];
$this->assertFalse($this->svgDrawer->isDrawing());
$this->svgDrawer->startDrawing($properties);
$this->assertTrue($this->svgDrawer->isDrawing());
$this->svgDrawer->stopDrawing();
$this->assertFalse($this->svgDrawer->isDrawing());
}
/**
* Test properties
*/
public function testProperties()
{
$properties = [
'x' => 1,
'y' => 2,
'w' => 3,
'h' => 4,
];
$this->svgDrawer->startDrawing($properties);
$this->assertSame(1, $this->svgDrawer->getProperty('x'));
$this->assertSame(2, $this->svgDrawer->getProperty('y'));
$this->assertSame(3, $this->svgDrawer->getProperty('w'));
$this->assertSame(4, $this->svgDrawer->getProperty('h'));
}
/**
* Test: tokenize
*
* @param mixed $transform
* @param mixed $expected
*
* @dataProvider transformProvider
*/
public function testTransform($transform, $expected)
{
$properties = [
'x' => 0,
'y' => 0,
'w' => 100,
'h' => 100,
];
$this->svgDrawer->startDrawing($properties);
$result = $this->svgDrawer->prepareTransform($transform);
$this->assertArraySame($expected, $result);
}
/**
* @param array $expected
* @param array $result
*/
protected function assertArraySame($expected, $result)
{
if (is_array($expected)) {
foreach ($expected as $key => $value) {
$expected[$key] = round($value, 5);
}
}
if (is_array($result)) {
foreach ($result as $key => $value) {
$result[$key] = round($value, 5);
}
}
$this->assertSame($expected, $result);
}
/**
* provider: tokenize
*
* @return array
*/
public function transformProvider()
{
return array(
array(
false,
null
),
array(
'no instruction',
null
),
array(
'foo(1,2)',
null
),
array(
'before scale( 0.1 , 0.2 ) after',
[
0.1, 0.,
0., 0.2,
0., 0.
]
),
array(
'scale(0.1,0.2)',
[
0.1, 0.,
0., 0.2,
0., 0.
]
),
array(
'scale(0.1)',
[
0.1, 0.,
0., 0.1,
0., 0.
]
),
array(
'scale(,)',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'scale()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'translate()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'translate(10mm)',
[
1., 0.,
0., 1.,
10., 0.
]
),
array(
'translate(10mm, 20mm)',
[
1., 0.,
0., 1.,
10., 20.
]
),
array(
'rotate()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'rotate(90)',
[
0., 1.,
-1., 0.,
0., 0.
]
),
array(
'rotate(180)',
[
-1., 0.,
0., -1.,
0., 0.
]
),
array(
'rotate(180, 10mm, 10mm)',
[
-1., 0.,
0., -1.,
-20., -20.
]
),
array(
'skewx()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'skewx(45)',
[
1., 0.,
1., 1.,
0., 0.
]
),
array(
'skewy()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'skewy(45)',
[
1., 1.,
0., 1.,
0., 0.
]
),
array(
'matrix()',
[
0., 0.,
0., 0.,
0., 0.
]
),
array(
'matrix(1,2,3,4,5%,6%)',
[
1., 2.,
3., 4.,
5., 6.
]
),
);
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Div Tag test
*/
class DivTest extends AbstractTest
{
/**
* test No Break
*
* @return void
*/
public function testNoBreak()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(1, $object->getNbPages());
}
/**
* test Break Before
*
* @return void
*/
public function testBreakBefore()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-before:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(2, $object->getNbPages());
}
/**
* test Break After
*
* @return void
*/
public function testBreakAfter()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-after:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(2, $object->getNbPages());
}
/**
* test Break before and After
*
* @return void
*/
public function testBreakBeforeAndAfter()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-before:always; page-break-after:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(3, $object->getNbPages());
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class Thead must not be empty
*/
class MustHaveTagsTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testOk()
{
$html = '<table>';
$html.= '<thead><tr><td>Hello</td></tr></thead>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
}
/**
* test
*
* @return void
*/
public function testNotEmptyThead()
{
$this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class);
$html = '<table>';
$html.= '<thead></thead>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
/**
* test
*
* @return void
*/
public function testNotEmptyTfoot()
{
$this->expectException(\Spipu\Html2Pdf\Exception\HtmlParsingException::class);
$html = '<table>';
$html.= '<tfoot></tfoot>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class CircleErrorTest
*/
class CircleErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<circle />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class EllipseErrorTest
*/
class EllipseErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<ellipse />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class GErrorTest
*/
class GErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<g />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class LineErrorTest
*/
class LineErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<line />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PathErrorTest
*/
class PathErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<path />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PathInvalidTest
*/
class PathInvalidTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$html = '
<page>
<draw style="width:150mm; height:100mm;">
<path style="fill:#770000; stroke:#AA0033;" d="n 20mm,40mm a16mm,8mm 0,0,0 16mm,8mm" />
</draw>
</page>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PolygonErrorTest
*/
class PolygonErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<polygon />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PolylineErrorTest
*/
class PolylineErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<polyline />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class RectErrorTest
*/
class RectErrorTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(HtmlParsingException::class);
$object = $this->getObject();
$object->writeHTML('<rect />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class TdTooLongTest
*/
class TdTooLongTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testCase()
{
$this->expectException(\Spipu\Html2Pdf\Exception\TableException::class);
$sentence = 'Hello World ! ';
$sentences = '';
for ($k=0; $k<100; $k++) {
$sentences.= $sentence;
}
$object = $this->getObject();
$object->writeHTML('<table><tr><td style="width: 28mm">'.$sentences.'</td></tr></table>');
$object->output('test.pdf', 'S');
}
}