Make WordPress Core

Changeset 35988


Ignore:
Timestamp:
12/17/2015 05:11:07 PM (9 years ago)
Author:
boonebgorges
Message:

Better focus in tag cloud tests.

We should avoid testing complete markup strings, unless we are specifically
testing for the format of the markup.

Fixes #35138.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php

    r35984 r35988  
    7979            'hide_empty' => false,
    8080        ) );
    81         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
    82         $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    83             'hide_empty' => false,
    84         ) ) );
     81
     82        $found = wp_generate_tag_cloud( $tags, array(
     83            'hide_empty' => false,
     84        ) );
     85
     86        $this->assertContains( '>' . $tags[0]->name . '<', $found );
    8587    }
    8688
     
    9597        ) );
    9698
    97         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>";
    98         $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    99             'hide_empty' => false,
    100         ) ) );
     99        $found = wp_generate_tag_cloud( $tags, array(
     100            'hide_empty' => false,
     101            'format' => 'array',
     102        ) );
     103
     104        $this->assertInternalType( 'array', $found );
     105        $this->assertContains( '>' . $tags[0]->name . '<', $found[0] );
    101106    }
    102107
     
    110115        ) );
    111116
    112         $expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n";
    113         $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
     117        $found = wp_generate_tag_cloud( $tags, array(
    114118            'hide_empty' => false,
    115119            'format'     => 'list',
    116         ) ) );
     120        ) );
     121
     122        $this->assertRegExp( "|^<ul class='wp-tag-cloud'>|", $found );
     123        $this->assertRegExp( "|</ul>\n|", $found );
     124        $this->assertContains( '>' . $tags[0]->name . '<', $found );
    117125    }
    118126
     
    130138        ) );
    131139
    132         $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n".
    133             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n".
    134             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n".
    135             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>";
    136         $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
    137             'hide_empty' => false,
    138         ) ) );
     140        $found = wp_generate_tag_cloud( $tags, array(
     141            'hide_empty' => false,
     142        ) );
     143
     144        foreach ( $tags as $tag ) {
     145            $this->assertContains( '>' . $tag->name . '<', $found );
     146        }
    139147    }
    140148
     
    152160        ) );
    153161
    154         $expected = "<ul class='wp-tag-cloud'>\n\t<li>".
    155             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0 tag-link-position-1' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>".
    156             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1 tag-link-position-2' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>".
    157             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2 tag-link-position-3' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>".
    158             "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3 tag-link-position-4' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>".
    159             "</li>\n</ul>\n";
    160 
    161         $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array(
     162        $found = wp_generate_tag_cloud( $tags, array(
    162163            'hide_empty' => false,
    163164            'format'     => 'list',
    164         ) ) );
     165        ) );
     166
     167        $this->assertRegExp( "|^<ul class='wp-tag-cloud'>|", $found );
     168        $this->assertRegExp( "|</ul>\n|", $found );
     169
     170        foreach ( $tags as $tag ) {
     171            $this->assertContains( '>' . $tag->name . '<', $found );
     172        }
    165173    }
    166174
Note: See TracChangeset for help on using the changeset viewer.