mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-02-22 00:32:47 +00:00
HTML API: Rename WP_HTML_Processor::createFragment() to follow WPCS.
`WP_HTML_Processor::create_fragment()` is the correct method name as per the WordPress PHP coding standards. Follow-up to [56274]. Props dmsnell, jrf, hellofromTonya, SergeyBiryukov. Fixes #59547. git-svn-id: https://develop.svn.wordpress.org/trunk@56790 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b77b8fd822
commit
7c12150a80
@ -39,7 +39,7 @@
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $processor = WP_HTML_Processor::createFragment( $html );
|
||||
* $processor = WP_HTML_Processor::create_fragment( $html );
|
||||
* if ( $processor->next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) {
|
||||
* $processor->add_class( 'responsive-image' );
|
||||
* }
|
||||
@ -58,7 +58,7 @@
|
||||
* Since all elements find themselves inside a full HTML document
|
||||
* when parsed, the return value from `get_breadcrumbs()` will always
|
||||
* contain any implicit outermost elements. For example, when parsing
|
||||
* with `createFragment()` in the `BODY` context (the default), any
|
||||
* with `create_fragment()` in the `BODY` context (the default), any
|
||||
* tag in the given HTML document will contain `array( 'HTML', 'BODY', … )`
|
||||
* in its breadcrumbs.
|
||||
*
|
||||
@ -239,7 +239,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
* @param string $encoding Text encoding of the document; must be default of 'UTF-8'.
|
||||
* @return WP_HTML_Processor|null The created processor if successful, otherwise null.
|
||||
*/
|
||||
public static function createFragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {
|
||||
public static function create_fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {
|
||||
if ( '<body>' !== $context || 'UTF-8' !== $encoding ) {
|
||||
return null;
|
||||
}
|
||||
@ -280,7 +280,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @see WP_HTML_Processor::createFragment()
|
||||
* @see WP_HTML_Processor::create_fragment()
|
||||
*
|
||||
* @param string $html HTML to process.
|
||||
* @param string|null $use_the_static_create_methods_instead This constructor should not be called manually.
|
||||
@ -292,9 +292,9 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
sprintf(
|
||||
/* translators: %s: WP_HTML_Processor::createFragment. */
|
||||
/* translators: %s: WP_HTML_Processor::create_fragment(). */
|
||||
__( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ),
|
||||
'<code>WP_HTML_Processor::createFragment</code>'
|
||||
'<code>WP_HTML_Processor::create_fragment()</code>'
|
||||
),
|
||||
'6.4.0'
|
||||
);
|
||||
@ -324,7 +324,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
*
|
||||
* Example
|
||||
*
|
||||
* $processor = WP_HTML_Processor::createFragment( '<template><strong><button><em><p><em>' );
|
||||
* $processor = WP_HTML_Processor::create_fragment( '<template><strong><button><em><p><em>' );
|
||||
* false === $processor->next_tag();
|
||||
* WP_HTML_Processor::ERROR_UNSUPPORTED === $processor->get_last_error();
|
||||
*
|
||||
@ -428,7 +428,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* $processor = WP_HTML_Processor::createFragment( '<div><span><figure><img></figure></span></div>' );
|
||||
* $processor = WP_HTML_Processor::create_fragment( '<div><span><figure><img></figure></span></div>' );
|
||||
* $processor->next_tag( 'img' );
|
||||
* true === $processor->matches_breadcrumbs( array( 'figure', 'img' ) );
|
||||
* true === $processor->matches_breadcrumbs( array( 'span', 'figure', 'img' ) );
|
||||
@ -557,7 +557,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
*
|
||||
* Example
|
||||
*
|
||||
* $processor = WP_HTML_Processor::createFragment( '<p><strong><em><img></em></strong></p>' );
|
||||
* $processor = WP_HTML_Processor::create_fragment( '<p><strong><em><img></em></strong></p>' );
|
||||
* $processor->next_tag( 'IMG' );
|
||||
* $processor->get_breadcrumbs() === array( 'HTML', 'BODY', 'P', 'STRONG', 'EM', 'IMG' );
|
||||
*
|
||||
@ -1439,5 +1439,5 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::createFragment instead of calling the class constructor directly.';
|
||||
const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::get_tag
|
||||
*/
|
||||
public function test_get_tag_is_null_once_document_is_finished() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div class="test">Test</div>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div class="test">Test</div>' );
|
||||
$p->next_tag();
|
||||
$this->assertSame( 'DIV', $p->get_tag() );
|
||||
|
||||
@ -69,7 +69,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::next_tag
|
||||
*/
|
||||
public function test_stops_processing_after_unsupported_elements() {
|
||||
$p = WP_HTML_Processor::createFragment( '<p><x-not-supported></p><p></p>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<p><x-not-supported></p><p></p>' );
|
||||
$p->next_tag( 'P' );
|
||||
$this->assertFalse( $p->next_tag(), 'Stepped into a tag after encountering X-NOT-SUPPORTED element when it should have aborted.' );
|
||||
$this->assertNull( $p->get_tag(), "Should have aborted processing, but still reported tag {$p->get_tag()} after properly failing to step into tag." );
|
||||
@ -95,7 +95,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
|
||||
* @throws WP_HTML_Unsupported_Exception
|
||||
*/
|
||||
public function test_clear_to_navigate_after_seeking() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
|
||||
|
||||
while ( $p->next_tag() ) {
|
||||
// Create a bookmark before entering a stack of elements and formatting elements.
|
||||
@ -144,7 +144,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::reconstruct_active_formatting_elements
|
||||
*/
|
||||
public function test_fails_to_reconstruct_formatting_elements() {
|
||||
$p = WP_HTML_Processor::createFragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
|
||||
|
||||
$this->assertTrue( $p->next_tag( 'EM' ), 'Could not find first EM.' );
|
||||
$this->assertFalse( $p->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' );
|
||||
|
||||
@ -23,7 +23,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @param string $tag_name Name of first tag in HTML (because HTML treats IMAGE as IMG this may not match the HTML).
|
||||
*/
|
||||
public function test_navigates_into_normative_html_for_supported_elements( $html, $tag_name ) {
|
||||
$p = WP_HTML_Processor::createFragment( $html );
|
||||
$p = WP_HTML_Processor::create_fragment( $html );
|
||||
|
||||
$this->assertTrue( $p->step(), "Failed to step into supported {$tag_name} element." );
|
||||
$this->assertSame( $tag_name, $p->get_tag(), "Misread {$tag_name} as a {$p->get_tag()} element." );
|
||||
@ -85,7 +85,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @param string $html HTML string containing unsupported elements.
|
||||
*/
|
||||
public function test_fails_when_encountering_unsupported_tag( $html ) {
|
||||
$p = WP_HTML_Processor::createFragment( $html );
|
||||
$p = WP_HTML_Processor::create_fragment( $html );
|
||||
|
||||
$this->assertFalse( $p->step(), "Should not have stepped into unsupported {$p->get_tag()} element." );
|
||||
}
|
||||
@ -236,7 +236,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @param string $html HTML containing unsupported markup.
|
||||
*/
|
||||
public function test_fails_when_encountering_unsupported_markup( $html, $description ) {
|
||||
$p = WP_HTML_Processor::createFragment( $html );
|
||||
$p = WP_HTML_Processor::create_fragment( $html );
|
||||
|
||||
while ( $p->step() && null === $p->get_attribute( 'supported' ) ) {
|
||||
continue;
|
||||
@ -277,7 +277,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @param int $n How many breadcrumb matches to scan through in order to find "target" element.
|
||||
*/
|
||||
public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $n ) {
|
||||
$p = WP_HTML_Processor::createFragment( $html );
|
||||
$p = WP_HTML_Processor::create_fragment( $html );
|
||||
|
||||
$p->next_tag(
|
||||
array(
|
||||
@ -303,7 +303,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @return void
|
||||
*/
|
||||
public function test_reports_correct_breadcrumbs_for_html( $html, $breadcrumbs, $ignored_n ) {
|
||||
$p = WP_HTML_Processor::createFragment( $html );
|
||||
$p = WP_HTML_Processor::create_fragment( $html );
|
||||
|
||||
while ( $p->next_tag() && null === $p->get_attribute( 'target' ) ) {
|
||||
continue;
|
||||
@ -362,7 +362,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @param bool $should_match Whether the target node should match the breadcrumbs.
|
||||
*/
|
||||
public function test_reports_if_tag_matches_breadcrumbs_of_various_specificity( $html_with_target_node, $breadcrumbs, $should_match ) {
|
||||
$processor = WP_HTML_Processor::createFragment( $html_with_target_node );
|
||||
$processor = WP_HTML_Processor::create_fragment( $html_with_target_node );
|
||||
while ( $processor->next_tag() && null === $processor->get_attribute( 'target' ) ) {
|
||||
continue;
|
||||
}
|
||||
@ -420,7 +420,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::set_attribute
|
||||
*/
|
||||
public function test_can_modify_attributes_after_finding_tag() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
|
||||
|
||||
$this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' );
|
||||
|
||||
@ -438,7 +438,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::next_tag
|
||||
*/
|
||||
public function test_can_query_an_element_by_tag_name() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><DIV><strong><img></strong></DIV>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' );
|
||||
$p->next_tag( 'IMG' );
|
||||
$p->set_attribute( 'loading', 'lazy' );
|
||||
|
||||
@ -455,7 +455,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::seek
|
||||
*/
|
||||
public function test_can_seek_back_and_forth() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><p one><div><p><div two><p><div><p><div><p three>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><p one><div><p><div two><p><div><p><div><p three>' );
|
||||
|
||||
// Find first tag of interest.
|
||||
while ( $p->next_tag() && null === $p->get_attribute( 'one' ) ) {
|
||||
|
||||
@ -27,7 +27,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function test_in_body_skips_unexpected_button_closer() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div>Test</button></div>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
|
||||
|
||||
$p->step();
|
||||
$this->assertEquals( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' );
|
||||
@ -52,7 +52,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @throws WP_HTML_Unsupported_Exception
|
||||
*/
|
||||
public function test_in_body_button_with_no_button_in_scope() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
|
||||
|
||||
$this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
|
||||
$this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
|
||||
@ -79,7 +79,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @throws WP_HTML_Unsupported_Exception
|
||||
*/
|
||||
public function test_in_body_button_with_button_in_scope_as_parent() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );
|
||||
|
||||
$this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
|
||||
$this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );
|
||||
@ -114,7 +114,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @throws WP_HTML_Unsupported_Exception
|
||||
*/
|
||||
public function test_in_body_button_with_button_in_scope_as_ancestor() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );
|
||||
|
||||
// This button finds itself normally nesting inside the DIV.
|
||||
$this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' );
|
||||
@ -149,7 +149,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::step_in_body
|
||||
*/
|
||||
public function test_in_body_any_other_end_tag_with_unclosed_special_element() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><span><p></span><div>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' );
|
||||
|
||||
$p->next_tag( 'P' );
|
||||
$this->assertSame( 'P', $p->get_tag(), "Expected to start test on P element but found {$p->get_tag()} instead." );
|
||||
@ -172,7 +172,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::step_in_body
|
||||
*/
|
||||
public function test_in_body_any_other_end_tag_with_unclosed_non_special_element() {
|
||||
$p = WP_HTML_Processor::createFragment( '<div><span><code></span><div>' );
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' );
|
||||
|
||||
$p->next_tag( 'CODE' );
|
||||
$this->assertSame( 'CODE', $p->get_tag(), "Expected to start test on CODE element but found {$p->get_tag()} instead." );
|
||||
|
||||
@ -42,7 +42,7 @@ class Tests_HtmlApi_WpHtmlSupportRequiredHtmlProcessor extends WP_UnitTestCase {
|
||||
* @param string $tag_name the HTML Processor should abort when encountering this tag, e.g. "BUTTON".
|
||||
*/
|
||||
private function ensure_support_is_added_everywhere( $tag_name ) {
|
||||
$p = WP_HTML_Processor::createFragment( "<$tag_name>" );
|
||||
$p = WP_HTML_Processor::create_fragment( "<$tag_name>" );
|
||||
|
||||
$this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class Tests_HtmlApi_WpHtmlSupportRequiredOpenElements extends WP_UnitTestCase {
|
||||
* @param string $tag_name the HTML Processor should abort when encountering this tag, e.g. "BUTTON".
|
||||
*/
|
||||
private function ensure_support_is_added_everywhere( $tag_name ) {
|
||||
$p = WP_HTML_Processor::createFragment( "<$tag_name>" );
|
||||
$p = WP_HTML_Processor::create_fragment( "<$tag_name>" );
|
||||
|
||||
$this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user