Skip to content

Commit

Permalink
Issue #842: Rename function to capture_current_source().
Browse files Browse the repository at this point in the history
Props @westonruter.
This also needs to account for themes and mu-plugins.
  • Loading branch information
Ryan Kienstra committed Feb 23, 2018
1 parent f1bf9f3 commit 3d1e6e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function remove_invalid_attribute( $element, $attribute ) {
* @param DOMNode $node The node to check for the presence of a plugin in a comment.
* @return void
*/
public function set_plugin_output( $node ) {
public function capture_current_source( $node ) {
preg_match( ':(before|after)\:(.*):s', $node->nodeValue, $matches );
if ( ! isset( $matches[1], $matches[2] ) ) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private function process_node( $node ) {

// Don't process text or comment nodes.
if ( XML_COMMENT_NODE === $node->nodeType ) {
$this->set_plugin_output( $node );
$this->capture_current_source( $node );
return;
} elseif ( XML_TEXT_NODE === $node->nodeType || XML_CDATA_SECTION_NODE === $node->nodeType ) {
return;
Expand Down
10 changes: 5 additions & 5 deletions tests/test-class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,20 @@ public function test_remove_attribute() {
}

/**
* Test set_plugin_output.
* Test capture_current_source.
*
* @covers AMP_Base_Sanitizer::set_plugin_output()
* @covers AMP_Base_Sanitizer::capture_current_source()
*/
public function test_set_plugin_output() {
public function test_capture_current_source() {
$dom = new DomDocument();
$closing_comment = 'after:amp';
$node = $dom->createComment( $closing_comment );
$sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom );
$this->assertEquals( null, $sanitizer->current_plugin_output );
$sanitizer->set_plugin_output( $node );
$sanitizer->capture_current_source( $node );
$this->assertEquals( 'amp', $sanitizer->current_plugin_output );
$opening_comment = $dom->createComment( 'before:amp' );
$sanitizer->set_plugin_output( $opening_comment );
$sanitizer->capture_current_source( $opening_comment );
$this->assertEquals( null, $sanitizer->current_plugin_output );
}

Expand Down
10 changes: 5 additions & 5 deletions tests/test-tag-and-attribute-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,20 +853,20 @@ public function test_html_sanitizer( $source, $expected = null, $scripts = array
}

/**
* Test set_plugin_output.
* Test capture_current_source.
*
* @covers AMP_Tag_And_Attribute_Sanitizer::set_plugin_output()
* @covers AMP_Tag_And_Attribute_Sanitizer::capture_current_source()
*/
public function test_set_plugin_output() {
public function test_capture_current_source() {
$dom = new DomDocument();
$comment_before = 'before:amp';
$comment_after = 'after:amp';
$node = $dom->createComment( $comment_after );
$sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom );
$sanitizer->set_plugin_output( $node );
$sanitizer->capture_current_source( $node );
$this->assertEquals( 'amp', $sanitizer->current_plugin_output );
$closing_comment = $dom->createComment( $comment_before );
$sanitizer->set_plugin_output( $closing_comment );
$sanitizer->capture_current_source( $closing_comment );
$this->assertEquals( null, $sanitizer->current_plugin_output );
}

Expand Down

0 comments on commit 3d1e6e3

Please sign in to comment.