source: trunk/client/inc/hpdf5/spipu/html2pdf/src/Tests/Parsing/HtmlLexerTest.php@ 353

Last change on this file since 353 was 347, checked in by roby, 4 years ago

Aggiornamento per compatibilità con php7.4

File size: 1.8 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\HtmlLexer;
16
17/**
18 * Class HtmlLexerTest
19 */
20class HtmlLexerTest extends \PHPUnit_Framework_TestCase
21{
22 /**
23 * Test: tokenize
24 *
25 * @param string $html html to test
26 * @param array $expectedTokens expected token
27 *
28 * @dataProvider tokenizeProvider
29 */
30 public function testTokenize($html, $expectedTokens)
31 {
32 $lexer = new HtmlLexer();
33 $tokens = $lexer->tokenize($html);
34
35 $this->assertEquals(count($expectedTokens), count($tokens));
36
37 for ($i = 0; $i < count($tokens); $i++) {
38 $this->assertEquals($expectedTokens[$i][0], $tokens[$i]->getType());
39 $this->assertEquals($expectedTokens[$i][1], $tokens[$i]->getData());
40 $this->assertEquals($expectedTokens[$i][2], $tokens[$i]->getLine());
41 }
42 }
43
44 /**
45 * provider: tokenize
46 *
47 * @return array
48 */
49 public function tokenizeProvider()
50 {
51 return array(
52 array(
53 '<p>test</p>',
54 array(
55 array('code', '<p>', 1),
56 array('txt', 'test', -1),
57 array('code', '</p>', 1),
58 )
59 ),
60 array(
61 "<a><!-- comment -->\n<b><c>test",
62 array(
63 array('code', '<a>', 1),
64 array('txt', "\n", -1),
65 array('code', '<b>', 2),
66 array('code', '<c>', 2),
67 array('txt', "test", -1),
68 )
69 )
70 );
71 }
72}
Note: See TracBrowser for help on using the repository browser.