namespace === HTMLData::NS_HTML && $node->name === 'a' && isset( $node->attrs['href'] ); }; $modifyCallbackInPlace = static function ( SerializerNode $node ) { $node->attrs['href'] = 'https://tracker.org/' . $node->attrs['href']; return $node; }; $input = '
Foo bar baz
'; $expectedOutput = 'Foo bar baz
'; $output = HtmlHelper::modifyElements( $input, $shouldModifyCallback, $modifyCallbackInPlace ); $this->assertSame( $expectedOutput, $output ); $modifyCallbackNew = static function ( SerializerNode $node ) { $href = 'https://tracker.org/' . $node->attrs['href']; $newNode = new SerializerNode( $node->id, $node->parentId, $node->namespace, $node->name, new PlainAttributes( [ 'href' => $href ] ), $node->void ); $node->attrs['href'] = 'https://tracker.org/' . $node->attrs['href']; return $newNode; }; $output = HtmlHelper::modifyElements( $input, $shouldModifyCallback, $modifyCallbackNew ); $this->assertSame( $expectedOutput, $output ); } }