WordPress.org

Make WordPress Core

Changeset 42382


Ignore:
Timestamp:
12/10/2017 12:30:32 AM (3 years ago)
Author:
johnbillion
Message:

Build/Test tools: Switch to PHPUnit's expectOutputString() method instead of manually using output buffers for output assertions.

Props birgire
Fixes #42098

Location:
trunk/tests/phpunit/tests
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/getArchives.php

    r42343 r42382  
    128128
    129129    function test_wp_get_archives_echo() {
    130         $expected['echo'] = "<li><a href='" . $this->month_url . "'>" . date( 'F Y' ) . '</a></li>';
    131         ob_start();
     130        $expected['echo'] = "\t<li><a href='" . $this->month_url . "'>" . date( 'F Y' ) . '</a></li>' . "\n";
     131        $this->expectOutputString( $expected['echo'] );
    132132        wp_get_archives( array( 'echo' => true ) );
    133         $actual = ob_get_clean();
    134         $this->assertEquals( $expected['echo'], trim( $actual ) );
    135133    }
    136134
  • trunk/tests/phpunit/tests/post/listPages.php

    r42343 r42382  
    239239<li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li>
    240240</ul></li>';
    241         ob_start();
     241        $this->expectOutputString( $expected['echo'] );
    242242        wp_list_pages( $args );
    243         $actual = ob_get_clean();
    244         $this->AssertEquals( $expected['echo'], $actual );
    245243    }
    246244
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r42343 r42382  
    142142        set_post_thumbnail( $post_id, $attachment_id );
    143143
    144         ob_start();
     144        $this->expectOutputString( $caption );
    145145        the_post_thumbnail_caption( $post_id );
    146 
    147         $this->assertEquals( $caption, ob_get_clean() );
    148146    }
    149147
     
    167165
    168166    function test_the_post_thumbnail() {
    169         ob_start();
     167
     168        $this->expectOutputString( '' );
    170169        the_post_thumbnail();
    171         $actual = ob_get_clean();
    172 
    173         $this->assertEquals( '', $actual );
    174 
    175         $GLOBALS['post'] = self::$post;
    176 
    177         ob_start();
     170
     171        $GLOBALS['post'] = self::$post;
     172
     173        $this->expectOutputString( '' );
    178174        the_post_thumbnail();
    179         $actual = ob_get_clean();
    180 
    181         $this->assertEquals( '', $actual );
    182175
    183176        set_post_thumbnail( self::$post, self::$attachment_id );
     
    189182        );
    190183
    191         ob_start();
     184        $this->expectOutputString( $expected );
    192185        the_post_thumbnail();
    193         $actual = ob_get_clean();
    194 
    195         $this->assertEquals( $expected, $actual );
    196186    }
    197187
     
    234224        $GLOBALS['post'] = self::$post;
    235225
    236         ob_start();
     226        $this->expectOutputString( '' );
    237227        the_post_thumbnail_url();
    238         $actual = ob_get_clean();
    239 
    240         $this->assertEmpty( $actual );
    241 
    242         ob_start();
     228
     229        set_post_thumbnail( self::$post, self::$attachment_id );
     230
     231        $this->expectOutputString( wp_get_attachment_url( self::$attachment_id ) );
    243232        the_post_thumbnail_url();
    244         $actual = ob_get_clean();
    245 
    246         $this->assertEmpty( $actual );
    247 
    248         set_post_thumbnail( self::$post, self::$attachment_id );
    249 
    250         ob_start();
    251         the_post_thumbnail_url();
    252         $actual = ob_get_clean();
    253 
    254         $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
    255233    }
    256234
  • trunk/tests/phpunit/tests/taxonomy.php

    r42343 r42382  
    6767        $post_id = self::factory()->post->create();
    6868
    69         ob_start();
     69        $this->expectOutputString( sprintf(
     70            'Categories: <a href="%s">Uncategorized</a>.',
     71            get_category_link( 1 )
     72        ) );
    7073        the_taxonomies( array( 'post' => $post_id ) );
    71         $output = ob_get_clean();
    72 
    73         $link     = get_category_link( 1 );
    74         $expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.';
    75         $this->assertEquals( $expected, $output );
    7674    }
    7775
  • trunk/tests/phpunit/tests/user/listAuthors.php

    r42343 r42382  
    162162    function test_wp_list_authors_echo() {
    163163        $expected['echo'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
    164         ob_start();
     164        $this->expectOutputString( $expected['echo'] );
    165165        wp_list_authors( array( 'echo' => true ) );
    166         $actual = ob_get_clean();
    167         $this->AssertEquals( $expected['echo'], $actual );
    168166    }
    169167
Note: See TracChangeset for help on using the changeset viewer.