Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
TestTokenHandler | |
100.00% |
12 / 12 |
|
100.00% |
9 / 9 |
10 | |
100.00% |
1 / 1 |
getTokens | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
startDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
endDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
error | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
characters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
startTag | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
endTag | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doctype | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
comment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikimedia\RemexHtml\Tokenizer; |
4 | |
5 | /** |
6 | * A TokenHandler which collects events from the Tokenizer and generates an |
7 | * array compatible with the html5lib tokenizer tests. |
8 | */ |
9 | class TestTokenHandler implements TokenHandler { |
10 | private $tokens = []; |
11 | |
12 | public function getTokens() { |
13 | return $this->tokens; |
14 | } |
15 | |
16 | public function startDocument( Tokenizer $tokenizer, $fns, $fn ) { |
17 | } |
18 | |
19 | public function endDocument( $pos ) { |
20 | } |
21 | |
22 | public function error( $text, $pos ) { |
23 | $this->tokens[] = 'ParseError'; |
24 | } |
25 | |
26 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
27 | $this->tokens[] = [ 'Character', substr( $text, $start, $length ) ]; |
28 | } |
29 | |
30 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
31 | $attrArray = $attrs->getValues(); |
32 | if ( $selfClose ) { |
33 | $this->tokens[] = [ 'StartTag', $name, $attrArray, $selfClose ]; |
34 | } else { |
35 | $this->tokens[] = [ 'StartTag', $name, $attrArray ]; |
36 | } |
37 | } |
38 | |
39 | public function endTag( $name, $sourceStart, $sourceLength ) { |
40 | $this->tokens[] = [ 'EndTag', $name ]; |
41 | } |
42 | |
43 | public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
44 | $this->tokens[] = [ 'DOCTYPE', $name, $public, $system, !$quirks ]; |
45 | } |
46 | |
47 | public function comment( $text, $sourceStart, $sourceLength ) { |
48 | $this->tokens[] = [ 'Comment', $text ]; |
49 | } |
50 | } |