WordPress.org

Make WordPress Core

Changeset 38679


Ignore:
Timestamp:
09/30/2016 03:23:05 AM (4 years ago)
Author:
boonebgorges
Message:

Tests: Move get_the_excerpt() tests to their own file.

See #36934. Fixes #38196.

Location:
trunk/tests/phpunit/tests/post
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getTheExcerpt.php

    r38678 r38679  
    11<?php
    2 
    3 // test the output of post template tags etc
    42
    53/**
     
    75 * @group formatting
    86 */
    9 class Tests_Post_Output extends WP_UnitTestCase {
    10 
    11     function setUp() {
    12         parent::setUp();
    13         add_shortcode( 'dumptag', array( $this, '_shortcode_dumptag' ) );
    14         add_shortcode( 'paragraph', array( $this, '_shortcode_paragraph' ) );
    15     }
    16 
    17     function tearDown() {
    18         global $shortcode_tags;
    19         unset( $shortcode_tags['dumptag'], $shortcode_tags['paragraph'] );
    20         parent::tearDown();
    21     }
    22 
    23     function _shortcode_dumptag( $atts ) {
    24         $out = '';
    25         foreach ($atts as $k=>$v)
    26             $out .= "$k = $v\n";
    27         return $out;
    28     }
    29 
    30     function _shortcode_paragraph( $atts, $content ) {
    31         extract(shortcode_atts(array(
    32             'class' => 'graf',
    33         ), $atts));
    34         return "<p class='$class'>$content</p>\n";
    35     }
    36 
    37     function test_the_content() {
    38         $post_content = <<<EOF
    39 <i>This is the excerpt.</i>
    40 <!--more-->
    41 This is the <b>body</b>.
    42 EOF;
    43 
    44         $post_id = self::factory()->post->create( compact( 'post_content' ) );
    45 
    46         $expected = <<<EOF
    47 <p><i>This is the excerpt.</i><br />
    48 <span id="more-{$post_id}"></span><br />
    49 This is the <b>body</b>.</p>
    50 EOF;
    51 
    52         $this->go_to( get_permalink( $post_id ) );
    53         $this->assertTrue( is_single() );
    54         $this->assertTrue( have_posts() );
    55         $this->assertNull( the_post() );
    56 
    57         $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
    58     }
    59 
    60     function test_the_content_shortcode() {
    61         $post_content = <<<EOF
    62 [dumptag foo="bar" baz="123"]
    63 
    64 [dumptag foo=123 baz=bar]
    65 
    66 [dumptag http://example.com]
    67 
    68 EOF;
    69 
    70         $expected =<<<EOF
    71 foo = bar
    72 baz = 123
    73 foo = 123
    74 baz = bar
    75 0 = http://example.com
    76 
    77 EOF;
    78 
    79         $post_id = self::factory()->post->create( compact( 'post_content' ) );
    80         $this->go_to( get_permalink( $post_id ) );
    81         $this->assertTrue( is_single() );
    82         $this->assertTrue( have_posts() );
    83         $this->assertNull( the_post() );
    84 
    85         $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
    86     }
    87 
    88     function test_the_content_shortcode_paragraph() {
    89         $post_content = <<<EOF
    90 Graf by itself:
    91 
    92 [paragraph]my graf[/paragraph]
    93 
    94   [paragraph foo="bar"]another graf with whitespace[/paragraph]
    95 
    96 An [paragraph]inline graf[/paragraph], this doesn't make much sense.
    97 
    98 A graf with a single EOL first:
    99 [paragraph]blah[/paragraph]
    100 
    101 EOF;
    102 
    103         $expected = <<<EOF
    104 <p>Graf by itself:</p>
    105 <p class='graf'>my graf</p>
    106 
    107   <p class='graf'>another graf with whitespace</p>
    108 
    109 <p>An <p class='graf'>inline graf</p>
    110 , this doesn&#8217;t make much sense.</p>
    111 <p>A graf with a single EOL first:<br />
    112 <p class='graf'>blah</p>
    113 </p>
    114 
    115 EOF;
    116 
    117         $post_id = self::factory()->post->create( compact( 'post_content' ) );
    118         $this->go_to( get_permalink( $post_id ) );
    119         $this->assertTrue( is_single() );
    120         $this->assertTrue( have_posts() );
    121         $this->assertNull( the_post() );
    122 
    123         $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
    124     }
    125 
    126     function test_the_content_attribute_filtering() {
    127         kses_init_filters();
    128 
    129         // http://bpr3.org/?p=87
    130         // the title attribute should make it through unfiltered
    131         $post_content = <<<EOF
    132 <span class="Z3988" title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.aulast=Mariat&rft.aufirst=Denis&rft. au=Denis+Mariat&rft.au=Sead+Taourit&rft.au=G%C3%A9rard+Gu%C3%A9rin& rft.title=Genetics+Selection+Evolution&rft.atitle=&rft.date=2003&rft. volume=35&rft.issue=1&rft.spage=119&rft.epage=133&rft.genre=article& rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic;">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href= "http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a>
    133 EOF;
    134 
    135         $expected = <<<EOF
    136 <p><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.aulast=Mariat&amp;rft.aufirst=Denis&amp;rft. au=Denis+Mariat&amp;rft.au=Sead+Taourit&amp;rft.au=G%C3%A9rard+Gu%C3%A9rin&amp; rft.title=Genetics+Selection+Evolution&amp;rft.atitle=&amp;rft.date=2003&amp;rft. volume=35&amp;rft.issue=1&amp;rft.spage=119&amp;rft.epage=133&amp;rft.genre=article&amp; rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href="http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a></p>
    137 EOF;
    138 
    139         $post_id = self::factory()->post->create( compact( 'post_content' ) );
    140         $this->go_to( get_permalink( $post_id ) );
    141         $this->assertTrue( is_single() );
    142         $this->assertTrue( have_posts() );
    143         $this->assertNull( the_post() );
    144 
    145         $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
    146 
    147         kses_remove_filters();
    148     }
    149 
    150     function test_the_content_attribute_value_with_colon() {
    151         kses_init_filters();
    152 
    153         // http://bpr3.org/?p=87
    154         // the title attribute should make it through unfiltered
    155         $post_content = <<<EOF
    156 <span title="My friends: Alice, Bob and Carol">foo</span>
    157 EOF;
    158 
    159         $expected = <<<EOF
    160 <p><span title="My friends: Alice, Bob and Carol">foo</span></p>
    161 EOF;
    162 
    163         $post_id = self::factory()->post->create( compact( 'post_content' ) );
    164         $this->go_to( get_permalink( $post_id ) );
    165         $this->assertTrue( is_single() );
    166         $this->assertTrue( have_posts() );
    167         $this->assertNull( the_post() );
    168 
    169         $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
    170 
    171         kses_remove_filters();
    172     }
     7class Tests_Post_GetTheExcerpt extends WP_UnitTestCase {
    1738
    1749    /**
  • trunk/tests/phpunit/tests/post/output.php

    r36329 r38679  
    171171        kses_remove_filters();
    172172    }
    173 
    174     /**
    175      * @ticket 27246
    176      */
    177     public function test_the_excerpt_invalid_post() {
    178         $this->assertSame( '', get_echo( 'the_excerpt' ) );
    179         $this->assertSame( '', get_the_excerpt() );
    180     }
    181 
    182     /**
    183      * @ticket 27246
    184      * @expectedDeprecated get_the_excerpt
    185      */
    186     public function test_the_excerpt_deprecated() {
    187         $this->assertSame( '', get_the_excerpt( true ) );
    188         $this->assertSame( '', get_the_excerpt( false ) );
    189     }
    190 
    191     /**
    192      * @ticket 27246
    193      */
    194     public function test_the_excerpt() {
    195         $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt' ) );
    196         $this->assertSame( "<p>Post excerpt</p>\n", get_echo( 'the_excerpt' ) );
    197         $this->assertSame( 'Post excerpt', get_the_excerpt() );
    198     }
    199 
    200     /**
    201      * @ticket 27246
    202      * @ticket 35486
    203      */
    204     public function test_the_excerpt_password_protected_post() {
    205         $post = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt', 'post_password' => '1234' ) );
    206         $this->assertSame( 'There is no excerpt because this is a protected post.', get_the_excerpt( $post ) );
    207 
    208         $GLOBALS['post'] = $post;
    209         $this->assertSame( "<p>There is no excerpt because this is a protected post.</p>\n", get_echo( 'the_excerpt' ) );
    210     }
    211 
    212     /**
    213      * @ticket 27246
    214      */
    215     public function test_the_excerpt_specific_post() {
    216         $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Foo' ) );
    217         $post_id = self::factory()->post->create( array( 'post_excerpt' => 'Bar' ) );
    218         $this->assertSame( 'Bar', get_the_excerpt( $post_id ) );
    219     }
    220173}
Note: See TracChangeset for help on using the changeset viewer.