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