[wp-trac] [WordPress Trac] #39992: Bug in get_the_content

WordPress Trac noreply at wordpress.org
Wed Oct 11 20:22:45 UTC 2017


#39992: Bug in get_the_content
----------------------------------------+------------------------------
 Reporter:  olik9                       |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Posts, Post Types           |     Version:  4.7.2
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------------

Comment (by birgire):

 The empty post object check

 {{{
 $post = get_post( $post );
 if ( empty( $post ) ) {
     return '';
 }

 }}}

 is for example used in {{{get_the_excerpt()}}}.

 Surprisingly there's no explicit test for {{{get_the_content()}}}.

 It's attempting to write a test that's just a single line:

 {{{
 $this->assertEquals( '', get_the_content() );

 }}}

 as there's no global {{{$post}}} object available within that test method.

 But I wanted to so the intention explicitly with:

 {{{
 unset( $GLOBALS['post'] );
 $this->assertEquals( '', get_the_content() );

 }}}

 and this is the test in [attachment:39992.3.diff].

 I did consider writing a much more verbose test, with a check if the
 global post is set, then store it in a temp, do the unset and then restore
 it afterwards (cleanup). But since there are currently no global post
 objects flying around in the test class, I skipped that path.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39992#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list