<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[59285] trunk: HTML API: Fix extensibility of `WP_HTML_Processor::next_token()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/59285">59285</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/59285","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-10-23 22:03:23 +0000 (Wed, 23 Oct 2024)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>HTML API: Fix extensibility of `WP_HTML_Processor::next_token()`.

Break out logic from the `next_token()` method into a private method which may call itself recursively. This allows for subclasses to override the `next_token()` method and be assured that each call to `next_token()` corresponds with the consumption of one single token. This also parallels how `WP_HTML_Tag_Processor::next_token()` wraps a private `base_class_next_token()` method.

Props westonruter, jonsurrell.
Fixes <a href="https://core.trac.wordpress.org/ticket/62269">#62269</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludeshtmlapiclasswphtmlprocessorphp">trunk/src/wp-includes/html-api/class-wp-html-processor.php</a></li>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/tests/phpunit/data/html-api/</li>
<li><a href="#trunktestsphpunitdatahtmlapihtmlxpathgeneratingprocessorphp">trunk/tests/phpunit/data/html-api/html-xpath-generating-processor.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludeshtmlapiclasswphtmlprocessorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/html-api/class-wp-html-processor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/html-api/class-wp-html-processor.php        2024-10-23 18:29:32 UTC (rev 59284)
+++ trunk/src/wp-includes/html-api/class-wp-html-processor.php  2024-10-23 22:03:23 UTC (rev 59285)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -604,6 +604,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Finds the next token in the HTML document.
+        *
+        * This doesn't currently have a way to represent non-tags and doesn't process
+        * semantic rules for text nodes. For access to the raw tokens consider using
+        * WP_HTML_Tag_Processor instead.
+        *
+        * @since 6.5.0 Added for internal support; do not use.
+        * @since 6.7.1 Refactored so subclasses may extend.
+        *
+        * @return bool Whether a token was parsed.
+        */
+       public function next_token(): bool {
+               return $this->_next_token();
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Ensures internal accounting is maintained for HTML semantic rules while
</span><span class="cx" style="display: block; padding: 0 10px">         * the underlying Tag Processor class is seeking to a bookmark.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -611,13 +627,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * semantic rules for text nodes. For access to the raw tokens consider using
</span><span class="cx" style="display: block; padding: 0 10px">         * WP_HTML_Tag_Processor instead.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.5.0 Added for internal support; do not use.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.7.1 Added for internal support; do not use.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @access private
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function next_token(): bool {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function _next_token(): bool {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->current_element = null;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $this->last_error ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -635,7 +651,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 *       tokens works in the meantime and isn't obviously wrong.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty( $this->element_queue ) && $this->step() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return $this->next_token();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $this->_next_token();
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Process the next event on the queue.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -646,7 +662,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return empty( $this->element_queue ) ? false : $this->next_token();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return empty( $this->element_queue ) ? false : $this->_next_token();
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $is_pop = WP_HTML_Stack_Event::POP === $this->current_element->operation;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -657,7 +673,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * the breadcrumbs.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'root-node' === $this->current_element->token->bookmark_name ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return $this->next_token();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $this->_next_token();
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Adjust the breadcrumbs for this event.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -669,7 +685,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Avoid sending close events for elements which don't expect a closing.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return $this->next_token();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return $this->_next_token();
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return true;
</span></span></pre></div>
<a id="trunktestsphpunitdatahtmlapihtmlxpathgeneratingprocessorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/html-api/html-xpath-generating-processor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/html-api/html-xpath-generating-processor.php                             (rev 0)
+++ trunk/tests/phpunit/data/html-api/html-xpath-generating-processor.php       2024-10-23 22:03:23 UTC (rev 59285)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,88 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+class HTML_XPath_Generating_Processor extends WP_HTML_Processor {
+
+       /**
+        * List of tokens that have already been seen.
+        *
+        * @var array<string, int>
+        */
+       public $token_seen_count = array();
+
+       /**
+        * Previous depth.
+        *
+        * @var int
+        */
+       private $previous_depth = 0;
+
+       /**
+        * Open stack indices.
+        *
+        * @since n.e.x.t
+        * @var array<int, array{tag_name: string, index: int}>
+        */
+       private $open_stack_indices = array();
+
+       /**
+        * Gets XPath for the current open tag.
+        *
+        * @return string XPath.
+        */
+       public function get_xpath(): string {
+               $xpath = '';
+               foreach ( $this->open_stack_indices as $level ) {
+                       $xpath .= sprintf( '/*[%d][self::%s]', $level['index'] + 1, $level['tag_name'] );
+               }
+               return $xpath;
+       }
+
+       /**
+        * Gets next token.
+        *
+        * @return bool Whether next token was matched.
+        */
+       public function next_token(): bool {
+               $result        = parent::next_token();
+               $current_depth = $this->get_current_depth();
+               $current_tag   = $this->get_tag();
+
+               $current_depth--; // Because HTML starts at depth 1.
+
+               if ( $this->get_token_type() === '#tag' ) {
+                       $token_name = ( $this->is_tag_closer() ? '-' : '+' ) . $current_tag;
+               } else {
+                       $token_name = $this->get_token_name();
+               }
+
+               if ( ! isset( $this->token_seen_count[ $token_name ] ) ) {
+                       $this->token_seen_count[ $token_name ] = 1;
+               } else {
+                       ++$this->token_seen_count[ $token_name ];
+               }
+
+               if ( $this->get_token_type() === '#tag' && ! $this->is_tag_closer() ) {
+                       if ( $current_depth < $this->previous_depth ) {
+                               array_splice(
+                                       $this->open_stack_indices,
+                                       $current_depth + 1
+                               );
+                       }
+
+                       if ( ! isset( $this->open_stack_indices[ $current_depth ] ) ) {
+                               $this->open_stack_indices[ $current_depth ] = array(
+                                       'tag_name' => $current_tag,
+                                       'index'    => 0,
+                               );
+                       } else {
+                               $this->open_stack_indices[ $current_depth ]['tag_name'] = $current_tag;
+                               ++$this->open_stack_indices[ $current_depth ]['index'];
+                       }
+
+                       $this->previous_depth = $current_depth;
+               }
+
+               return $result;
+       }
+
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/html-api/html-xpath-generating-processor.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestshtmlapiwpHtmlProcessorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php    2024-10-23 18:29:32 UTC (rev 59284)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php      2024-10-23 22:03:23 UTC (rev 59285)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -882,4 +882,180 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 'FORM', $processor->get_tag() );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertTrue( $processor->is_tag_closer() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_html_processor_with_extended_next_token() {
+               return array(
+                       'single_instance_per_tag'   => array(
+                               'html'                  => '
+                                       <html>
+                                               <head>
+                                                       <meta charset="utf-8">
+                                                       <title>Hello World</title>
+                                               </head>
+                                               <body>
+                                                       <h1>Hello World!</h1>
+                                                       <img src="example.png">
+                                                       <p>Each tag should occur only once in this document.<!--Closing P tag omitted intentionally.-->
+                                                       <footer>The end.</footer>
+                                               </body>
+                                       </html>
+                               ',
+                               'expected_token_counts' => array(
+                                       '+HTML'    => 1,
+                                       '+HEAD'    => 1,
+                                       '#text'    => 14,
+                                       '+META'    => 1,
+                                       '+TITLE'   => 1,
+                                       '-HEAD'    => 1,
+                                       '+BODY'    => 1,
+                                       '+H1'      => 1,
+                                       '-H1'      => 1,
+                                       '+IMG'     => 1,
+                                       '+P'       => 1,
+                                       '#comment' => 1,
+                                       '-P'       => 1,
+                                       '+FOOTER'  => 1,
+                                       '-FOOTER'  => 1,
+                                       '-BODY'    => 1,
+                                       '-HTML'    => 1,
+                                       ''         => 1,
+                               ),
+                               'expected_xpaths'       => array(
+                                       0 => '/*[1][self::HTML]',
+                                       1 => '/*[1][self::HTML]/*[1][self::HEAD]',
+                                       2 => '/*[1][self::HTML]/*[1][self::HEAD]/*[1][self::META]',
+                                       3 => '/*[1][self::HTML]/*[1][self::HEAD]/*[2][self::TITLE]',
+                                       4 => '/*[1][self::HTML]/*[2][self::BODY]',
+                                       5 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::H1]',
+                                       6 => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
+                                       7 => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::P]',
+                                       8 => '/*[1][self::HTML]/*[2][self::BODY]/*[4][self::FOOTER]',
+                               ),
+                       ),
+
+                       'multiple_tag_instances'    => array(
+                               'html'                  => '
+                                       <html>
+                                               <body>
+                                                       <h1>Hello World!</h1>
+                                                       <p>First
+                                                       <p>Second
+                                                       <p>Third
+                                                       <ul>
+                                                               <li>1
+                                                               <li>2
+                                                               <li>3
+                                                       </ul>
+                                               </body>
+                                       </html>
+                               ',
+                               'expected_token_counts' => array(
+                                       '+HTML' => 1,
+                                       '+HEAD' => 1,
+                                       '-HEAD' => 1,
+                                       '+BODY' => 1,
+                                       '#text' => 13,
+                                       '+H1'   => 1,
+                                       '-H1'   => 1,
+                                       '+P'    => 3,
+                                       '-P'    => 3,
+                                       '+UL'   => 1,
+                                       '+LI'   => 3,
+                                       '-LI'   => 3,
+                                       '-UL'   => 1,
+                                       '-BODY' => 1,
+                                       '-HTML' => 1,
+                                       ''      => 1,
+                               ),
+                               'expected_xpaths'       => array(
+                                       0  => '/*[1][self::HTML]',
+                                       1  => '/*[1][self::HTML]/*[1][self::HEAD]',
+                                       2  => '/*[1][self::HTML]/*[2][self::BODY]',
+                                       3  => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::H1]',
+                                       4  => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::P]',
+                                       5  => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::P]',
+                                       6  => '/*[1][self::HTML]/*[2][self::BODY]/*[4][self::P]',
+                                       7  => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]',
+                                       8  => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[1][self::LI]',
+                                       9  => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[2][self::LI]',
+                                       10 => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::UL]/*[3][self::LI]',
+                               ),
+                       ),
+
+                       'extreme_nested_formatting' => array(
+                               'html'                  => '
+                                       <html>
+                                               <body>
+                                                       <p>
+                                                               <strong><em><strike><i><b><u>FORMAT</u></b></i></strike></em></strong>
+                                                       </p>
+                                               </body>
+                                       </html>
+                               ',
+                               'expected_token_counts' => array(
+                                       '+HTML'   => 1,
+                                       '+HEAD'   => 1,
+                                       '-HEAD'   => 1,
+                                       '+BODY'   => 1,
+                                       '#text'   => 7,
+                                       '+P'      => 1,
+                                       '+STRONG' => 1,
+                                       '+EM'     => 1,
+                                       '+STRIKE' => 1,
+                                       '+I'      => 1,
+                                       '+B'      => 1,
+                                       '+U'      => 1,
+                                       '-U'      => 1,
+                                       '-B'      => 1,
+                                       '-I'      => 1,
+                                       '-STRIKE' => 1,
+                                       '-EM'     => 1,
+                                       '-STRONG' => 1,
+                                       '-P'      => 1,
+                                       '-BODY'   => 1,
+                                       '-HTML'   => 1,
+                                       ''        => 1,
+                               ),
+                               'expected_xpaths'       => array(
+                                       0 => '/*[1][self::HTML]',
+                                       1 => '/*[1][self::HTML]/*[1][self::HEAD]',
+                                       2 => '/*[1][self::HTML]/*[2][self::BODY]',
+                                       3 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]',
+                                       4 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]',
+                                       5 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]',
+                                       6 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]',
+                                       7 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]',
+                                       8 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]/*[1][self::B]',
+                                       9 => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::P]/*[1][self::STRONG]/*[1][self::EM]/*[1][self::STRIKE]/*[1][self::I]/*[1][self::B]/*[1][self::U]',
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * Ensures that subclasses to WP_HTML_Processor can do bookkeeping by extending the next_token() method.
+        *
+        * @ticket ?
+        * @dataProvider data_html_processor_with_extended_next_token
+        */
+       public function test_ensure_next_token_method_extensibility( $html, $expected_token_counts, $expected_xpaths ) {
+               require_once DIR_TESTDATA . '/html-api/html-xpath-generating-processor.php';
+
+               $processor     = HTML_XPath_Generating_Processor::create_full_parser( $html );
+               $actual_xpaths = array();
+               while ( $processor->next_tag() ) {
+                       if ( ! $processor->is_tag_closer() ) {
+                               $processor->set_attribute( 'xpath', $processor->get_xpath() );
+                               $actual_xpaths[] = $processor->get_xpath();
+                       }
+               }
+
+               $this->assertEquals( $expected_token_counts, $processor->token_seen_count, 'Snapshot: ' . var_export( $processor->token_seen_count, true ) );
+               $this->assertEquals( $expected_xpaths, $actual_xpaths, 'Snapshot: ' . var_export( $actual_xpaths, true ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>