source: trunk/client/inc/hpdf5/spipu/html2pdf/src/Tests/Parsing/HtmlTest.php@ 394

Last change on this file since 394 was 347, checked in by roby, 3 years ago

Aggiornamento per compatibilità con php7.4

File size: 2.0 KB
Line 
1<?php
2/**
3 * Html2Pdf Library - Tests
4 *
5 * HTML => PDF converter
6 * distributed under the OSL-3.0 License
7 *
8 * @package Html2pdf
9 * @author Laurent MINGUET <webmaster@html2pdf.fr>
10 * @copyright 2017 Laurent MINGUET
11 */
12
13namespace Spipu\Html2Pdf\Tests\Parsing;
14
15use Spipu\Html2Pdf\Parsing\Html;
16
17/**
18 * Class HtmlTest
19 */
20class HtmlTest extends \PHPUnit_Framework_TestCase
21{
22 /**
23 * @var Html
24 */
25 private $object;
26
27 protected function setUp()
28 {
29 $textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
30 ->disableOriginalConstructor()
31 ->setMethods(['prepareTxt'])
32 ->getMock();
33
34 $textParser
35 ->expects($this->any())
36 ->method('prepareTxt')
37 ->will($this->returnCallback([$this, 'mockPrepareTxt']));
38
39 $this->object = new Html($textParser);
40 }
41
42 /**
43 * mock of prepareTxt method
44 *
45 * @param $txt
46 * @param bool $spaces
47 * @return mixed
48 */
49 public function mockPrepareTxt($txt, $spaces = true)
50 {
51 return $txt;
52 }
53
54 /**
55 * Test the prepareHtml method
56 */
57 public function testPrepareHtml()
58 {
59 $result = $this->object->prepareHtml('Hello [[date_y]]-[[date_m]]-[[date_d]] World');
60 $this->assertSame('Hello '.date('Y-m-d').' World', $result);
61
62 $result = $this->object->prepareHtml('Hello [[date_h]]:[[date_i]]:[[date_s]] World');
63 $this->assertSame('Hello '.date('H:i:s').' World', $result);
64
65 $html = '
66<html>
67 <head>
68 <style type="text">.my-class { color: red; }</style>
69 <link type="text/css" href="my-style.css"/>
70 </head>
71 <body class="my-class"><p>Hello World</p></body>
72</html>';
73
74 $expected='<style type="text">.my-class { color: red; }</style>'.
75 '<link type="text/css" href="my-style.css"/>'.
76 '<page class="my-class"><p>Hello World</p></page>';
77
78 $result = $this->object->prepareHtml($html);
79 $this->assertSame($expected, $result);
80 }
81}
Note: See TracBrowser for help on using the repository browser.