PDF converter * distributed under the OSL-3.0 License * * @package Html2pdf * @author Laurent MINGUET * @copyright 2017 Laurent MINGUET */ namespace Spipu\Html2Pdf\Tests\Parsing; 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( '

test

', array( array('code', '

', 1), array('txt', 'test', -1), array('code', '

', 1), ) ), array( "\ntest", array( array('code', '', 1), array('txt', "\n", -1), array('code', '', 2), array('code', '', 2), array('txt', "test", -1), ) ) ); } }