]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TestTokenHandler.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / Tokenizer / TestTokenHandler.php
diff --git a/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TestTokenHandler.php b/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TestTokenHandler.php
new file mode 100644 (file)
index 0000000..06f3d0f
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+namespace RemexHtml\Tokenizer;
+
+/**
+ * A TokenHandler which collects events from the Tokenizer and generates an
+ * array compatible with the html5lib tokenizer tests.
+ */
+class TestTokenHandler implements TokenHandler {
+       private $tokens = [];
+
+       public function getTokens() {
+               return $this->tokens;
+       }
+
+       public function startDocument( Tokenizer $tokenizer, $fns, $fn ) {
+       }
+
+       public function endDocument( $pos ) {
+       }
+
+       public function error( $text, $pos ) {
+               $this->tokens[] = 'ParseError';
+       }
+
+       public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [ 'Character', substr( $text, $start, $length ) ];
+       }
+
+       public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
+               $attrArray = $attrs->getValues();
+               if ( $selfClose ) {
+                       $this->tokens[] = [ 'StartTag', $name, $attrArray, $selfClose ];
+               } else {
+                       $this->tokens[] = [ 'StartTag', $name, $attrArray ];
+               }
+       }
+
+       public function endTag( $name, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [ 'EndTag', $name ];
+       }
+
+       public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [ 'DOCTYPE', $name, $public, $system, !$quirks ];
+       }
+
+       public function comment( $text, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [ 'Comment', $text ];
+       }
+}