Skip to content

Commit 49d9527

Browse files
committed
Adjust get_updated_xml_applies_the_updates_so_far_and_keeps_the_processor_on_the_current_tag test to use a root node
1 parent 9ffdf1a commit 49d9527

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

components/XML/Tests/XMLProcessorTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,23 +480,25 @@ public function test_to_string_returns_updated_xml() {
480480
* @covers XMLProcessor::get_updated_xml
481481
*/
482482
public function test_get_updated_xml_applies_the_updates_so_far_and_keeps_the_processor_on_the_current_tag() {
483-
$processor = XMLProcessor::create_from_string( '<line id="remove" /><content enabled="yes" post-type="test">Test</content><text id="span-id"></text>' );
483+
$processor = XMLProcessor::create_from_string( '<doc><line id="remove" /><content enabled="yes" post-type="test">Test</content><text id="span-id"></text></doc>' );
484+
$processor->next_tag();
485+
484486
$processor->next_tag();
485487
$processor->remove_attribute( '', 'id' );
486488

487489
$processor->next_tag();
488490
$processor->set_attribute( '', 'id', 'content-id-1' );
489491

490492
$this->assertSame(
491-
'<line /><content id="content-id-1" enabled="yes" post-type="test">Test</content><text id="span-id"></text>',
493+
'<doc><line /><content id="content-id-1" enabled="yes" post-type="test">Test</content><text id="span-id"></text></doc>',
492494
$processor->get_updated_xml(),
493495
'Calling get_updated_xml after updating the attributes of the second tag returned different XML than expected'
494496
);
495497

496498
$processor->set_attribute( '', 'id', 'content-id-2' );
497499

498500
$this->assertSame(
499-
'<line /><content id="content-id-2" enabled="yes" post-type="test">Test</content><text id="span-id"></text>',
501+
'<doc><line /><content id="content-id-2" enabled="yes" post-type="test">Test</content><text id="span-id"></text></doc>',
500502
$processor->get_updated_xml(),
501503
'Calling get_updated_xml after updating the attributes of the second tag for the second time returned different XML than expected'
502504
);
@@ -505,7 +507,7 @@ public function test_get_updated_xml_applies_the_updates_so_far_and_keeps_the_pr
505507
$processor->remove_attribute( '', 'id' );
506508

507509
$this->assertSame(
508-
'<line /><content id="content-id-2" enabled="yes" post-type="test">Test</content><text ></text>',
510+
'<doc><line /><content id="content-id-2" enabled="yes" post-type="test">Test</content><text ></text></doc>',
509511
$processor->get_updated_xml(),
510512
'Calling get_updated_xml after removing the id attribute of the third tag returned different XML than expected'
511513
);
@@ -1717,6 +1719,27 @@ public function test_detects_invalid_document_no_root_tag() {
17171719
$this->assertFalse( $processor->next_tag(), 'Found an element when there was none.' );
17181720
$this->assertTrue( $processor->is_paused_at_incomplete_input(), 'Did not indicate that the XML input was incomplete.' );
17191721
}
1722+
1723+
/**
1724+
*
1725+
* @covers XMLProcessor::next_tag
1726+
*/
1727+
public function test_tolerates_illegal_extender_in_pi_target() {
1728+
$processor = XMLProcessor::create_from_string(
1729+
'<!DOCTYPE animal [
1730+
<!ELEMENT animal ANY>
1731+
<?_˒ an illegal extender #x2d2 in PITarget ?>
1732+
]>
1733+
<animal/>
1734+
'
1735+
);
1736+
$this->assertTrue( $processor->next_tag(), 'Found an element when there was none.' );
1737+
$this->assertEquals( 'animal', $processor->get_tag_local_name(), 'Did not find the expected tag.' );
1738+
$this->assertTrue( $processor->next_token(), 'Found an element when there was none.' );
1739+
$this->assertFalse( $processor->next_token(), 'Found an element when there was none.' );
1740+
$this->assertNull( $processor->get_last_error(), 'Did not find the expected error.' );
1741+
$this->assertNull( $processor->get_exception(), 'Did not find the expected error.' );
1742+
}
17201743

17211744
/**
17221745
*

components/XML/class-xmlprocessor.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,15 +4086,16 @@ private function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
40864086
return false;
40874087
}
40884088

4089-
if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
4090-
if ( $this->is_empty_element() ) {
4091-
array_pop( $this->stack_of_open_elements );
4092-
$this->element = $this->top_element();
4093-
if ( 0 === count( $this->stack_of_open_elements ) ) {
4094-
$this->parser_context = self::IN_MISC_CONTEXT;
4089+
if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
4090+
if ( $this->is_empty_element() ) {
4091+
array_pop( $this->stack_of_open_elements );
4092+
if ( empty( $this->stack_of_open_elements ) ) {
4093+
// We've just popped the root element – the context
4094+
// becomes "misc" by definition.
4095+
$this->parser_context = self::IN_MISC_CONTEXT;
4096+
}
40954097
}
40964098
}
4097-
}
40984099

40994100
try {
41004101
switch ( $this->parser_context ) {

0 commit comments

Comments
 (0)