', 7 ),
+ 'Adjacent elements' => array( '
', 4 ),
+ );
+ }
+
+ /**
+ * Ensures that the HTML Processor properly reports the depth of a given non-element.
+ *
+ * @ticket 61255
+ *
+ * @dataProvider data_html_with_target_element_and_depth_of_next_node_in_body
+ *
+ * @param string $html_with_target_element HTML containing element with `target` class.
+ * @param int $depth_after_element Depth into document immediately after target node.
+ */
+ public function test_reports_proper_non_element_depth_in_body( $html_with_target_element, $depth_after_element ) {
+ $processor = WP_HTML_Processor::create_fragment( $html_with_target_element );
+
+ $this->assertTrue(
+ $processor->next_tag( array( 'class_name' => 'target' ) ),
+ 'Failed to find target element: check test data provider.'
+ );
+
+ $this->assertTrue(
+ $processor->next_token(),
+ 'Failed to find next node after target element: check tests data provider.'
+ );
+
+ $this->assertSame(
+ $depth_after_element,
+ $processor->get_current_depth(),
+ 'HTML Processor reported the wrong depth after the matched element.'
+ );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[].
+ */
+ public static function data_html_with_target_element_and_depth_of_next_node_in_body() {
+ return array(
+ 'Element then text' => array( 'One Deeper', 4 ),
+ 'Basic layout and formatting stack' => array( '
Formatted', 8 ),
+ 'Basic layout with text' => array( 'a
bcee', 8 ),
+ 'Adjacent elements' => array( 'Here
', 5 ),
+ 'Adjacent text' => array( 'BeforeAfter
', 4 ),
+ 'HTML comment' => array( '', 3 ),
+ 'HTML comment in DIV' => array( '', 4 ),
+ 'Funky comment' => array( '
', 5 ),
+ );
+ }
}